Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

No.

No, no, no, no, no.

And no.

You didn't "change a variable to a function". You redefined (twice) the Python variable x.

Initially, you didn't define x, which means that by default, the Python variable x is bound to a Python object representing the symbolic variable $x$. This definition is active for lines 1-5 of your code.

Line 6, you redefine the Python variable x, binding it to a Python object representing an (undefined) symbolic function $x$.

Line 7, you redefine the Python variable x again, which binds it to the symbolic expression sol[0][0].rhs(), which turns out to be 1/2*R/p_x.

This symbolic expression has a .diff method :

Let e such a sumbolic expression ; e.diff(u) will return e.fiunction(u).diff(u), meaning *" take e as the body of a function of u and differentiate it wis respect to u".

Therefore, x.diff(R).simplify()) is 1/2*R/p_x.function(R).diff(R).simplify() which evaluates to $\frac{p_x}{2}$.

See a Python tutorial (or the Python documentation) to understand the meaning of = in Python : a variable is just a label attached to a Python object ; this is quite different of a Sage symbolic variable, which is a Python object representing such a (mathematical) variable in the sage.symbolic.expression.Expression class.

HTH,

No.

No, no, no, no, no.

And no.

You didn't "change a variable to a function". You redefined (twice) the Python variable x.

Initially, you didn't define x, which means that by default, the Python variable x is bound to a Python object representing the symbolic variable $x$. This definition is active for lines 1-5 of your code.

Line 6, you redefine the Python variable x, binding it to a Python object representing an (undefined) symbolic function $x$.

Line 7, you redefine the Python variable x again, which binds it to the symbolic expression sol[0][0].rhs(), which turns out to be 1/2*R/p_x.

This symbolic expression has a .diff method :

Let e such a sumbolic expression ; e.diff(u) will return e.fiunction(u).diff(u), meaning *" take e as the body of a function of u and differentiate it wis respect to u".

Therefore, x.diff(R).simplify()) is 1/2*R/p_x.function(R).diff(R).simplify() which evaluates to $\frac{p_x}{2}$.

See a Python tutorial (or the Python documentation) to understand the meaning of = in Python : a variable is just a label attached to a Python object ; this is quite different of a Sage symbolic variable, which is a Python object representing such a (mathematical) variable in the sage.symbolic.expression.Expression class.

The problem is compounded by the (hopefully convenient) shortcut of defining var("a") as a shortcut meaning a = SR.var("a"), meaning :

  • Create a sage.symbolic.expression.Expression representing the mathematical variable $a$, then

  • bind this object to the Python variable a.

This convenient shortcut is confusing to beginners...

HTH,

No.

No, no, no, no, no.

And no.

You didn't "change a variable to a function". You redefined (twice) the Python variable x.

Initially, you didn't define x, which means that by default, the Python variable x is bound to a Python object representing the symbolic variable $x$. This definition is active for lines 1-5 of your code.

Line 6, you redefine the Python variable x, binding it to a Python object representing an (undefined) symbolic function $x$.

Line 7, you redefine the Python variable x again, which binds it to the symbolic expression sol[0][0].rhs(), which turns out to be 1/2*R/p_x.

This symbolic expression has a .diff method :

Let e such a sumbolic expression ; e.diff(u) will return e.fiunction(u).diff(u), meaning *" take e as the body of a function of u and differentiate it wis with respect to u".

Therefore, x.diff(R).simplify()) is 1/2*R/p_x.function(R).diff(R).simplify() which evaluates to $\frac{p_x}{2}$.

See a Python tutorial (or the Python documentation) to understand the meaning of = in Python : a variable is just a label attached to a Python object ; this is quite different of a Sage symbolic variable, which is a Python object representing such a (mathematical) variable in the sage.symbolic.expression.Expression class.

The problem is compounded by the (hopefully convenient) shortcut of defining var("a") as a shortcut meaning a = SR.var("a"), meaning :

  • Create a sage.symbolic.expression.Expression representing the mathematical variable $a$, then

  • bind this object to the Python variable a.

This convenient shortcut is confusing to beginners...

HTH,

No.

No, no, no, no, no.

And no.

You didn't "change a variable to a function". You redefined (twicetwice !) the Python variable x.

Initially, you didn't define x, which means that by default, the Python variable x is bound to a Python object representing the symbolic variable $x$. This definition is active for lines 1-5 of your code.

Line 6, you redefine the Python variable x, binding it to a Python object representing an (undefined) symbolic function $x$.

Line 7, you redefine the Python variable x again, which binds it to the symbolic expression sol[0][0].rhs(), which turns out to be 1/2*R/p_x.

This symbolic expression has a .diff method :

Let e such a sumbolic expression ; e.diff(u) will return e.fiunction(u).diff(u), meaning *" take e as the body of a function of u and differentiate it with respect to u".

Therefore, x.diff(R).simplify()) is 1/2*R/p_x.function(R).diff(R).simplify() which evaluates to $\frac{p_x}{2}$.

See a Python tutorial (or the Python documentation) to understand the meaning of = in Python : a variable is just a label attached to a Python object ; this is quite different of a Sage symbolic variable, which is a Python object representing such a (mathematical) variable in the sage.symbolic.expression.Expression class.

The problem is compounded by the (hopefully convenient) shortcut of defining var("a") as a shortcut meaning a = SR.var("a"), meaning :

  • Create a sage.symbolic.expression.Expression representing the mathematical variable $a$, then

  • bind this object to the Python variable a.

This convenient shortcut is confusing to beginners...

HTH,