Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Let's define

idk = v_ges_rhs.subs({
                d_e : RIF(.999,1.001),
                x : -.25,
                d_m : RIF(.05,.15),
                e_m : e_0 * RIF(80.5,81.5),
                e_s : e_0 * RIF(3,4)
               })

This is a symbolic expression containing RIF numbers and the only symbolic variable is d_k.

At any point in the interval we can evaluate it to a symbolic expression which is just a RIF number, e.g.

sage: idk.subs({d_k : 0.2})
-1.?e10

Unfortunately we cannot call .upper() on this directly, because there is still a symbolic wrapper around it:

sage: type(idk.subs({d_k : 0.2}))
<type 'sage.symbolic.expression.Expression'>

To remove the wrapper, we use a RingConverter from SR to RIF:

sage: from sage.symbolic.expression_conversions import RingConverter
sage: R = RingConverter(RIF)
sage: R(idk.subs({d_k : 0.2}))
-1.?e10
sage: type(R(idk.subs({d_k : 0.2})))
<type 'sage.rings.real_mpfi.RealIntervalFieldElement'>
sage: R(idk.subs({d_k : 0.2})).upper()
-6.57758536841850e9

We can define functions which do this at a given point

f = lambda x: idk.subs({d_k: x})
from sage.symbolic.expression_conversions import RingConverter
R = RingConverter(RIF)
f_lower = lambda x: R(SR(idk.subs({d_k : x}))).lower()
f_upper = lambda x: R(SR(idk.subs({d_k : x}))).upper()

and plot them:

plot([f, f_lower, f_upper],(x,0.2,0.99), color=['blue', 'red', 'green'])

RIF plot

Let's define

idk = v_ges_rhs.subs({
                d_e : RIF(.999,1.001),
                x : -.25,
                d_m : RIF(.05,.15),
                e_m : e_0 * RIF(80.5,81.5),
                e_s : e_0 * RIF(3,4)
               })

This is a symbolic expression containing RIF numbers and the only symbolic variable is d_k.

At any point in the interval we can evaluate it to a symbolic expression which is just a RIF number, e.g.

sage: idk.subs({d_k : 0.2})
-1.?e10

Unfortunately we cannot call .upper() on this directly, because there is still a symbolic wrapper around it:

sage: type(idk.subs({d_k : 0.2}))
<type 'sage.symbolic.expression.Expression'>

To remove the wrapper, we use a RingConverter from SR conversion to RIF:

sage: from sage.symbolic.expression_conversions import RingConverter
sage: R = RingConverter(RIF)
sage: R(idk.subs({d_k RIF(idk.subs({d_k : 0.2}))
-1.?e10
sage: type(R(idk.subs({d_k : 0.2})))
<type 'sage.rings.real_mpfi.RealIntervalFieldElement'>
sage: R(idk.subs({d_k RIF(idk.subs({d_k : 0.2})).upper()
-6.57758536841850e9
sage: RIF(idk.subs({d_k : 0.2})).lower()
-8.63461563768822e9

We can define functions which do this at a given point

f = lambda x: idk.subs({d_k: x})
from sage.symbolic.expression_conversions import RingConverter
R = RingConverter(RIF)
f_lower = lambda x: R(SR(idk.subs({d_k : x}))).lower()
RIF(idk.subs({d_k : x})).lower()
f_upper = lambda x: R(SR(idk.subs({d_k : x}))).upper()
RIF(idk.subs({d_k : x})).upper()

and plot them:

plot([f, f_lower, f_upper],(x,0.2,0.99), color=['blue', 'red', 'green'])

RIF plot