diff(diff)

0 views
Skip to first unread message

czbebe

unread,
Jan 5, 2010, 9:32:58 PM1/5/10
to sympy
Dear members,

import sympy
import math
u = Function('u')
x = Symbol('x')
diff(diff(u(x),x),x) = D(u(x), x, x) ii is all right.
diff(x*diff(u(x),x),x) = x*D(u(x), x, x)+D(u(x), x) it is all right.

diff(sin(x)*diff(u(x),x),x) gives an error.

Can anyone show me the correct way to get a correct result ?

czbebe

Aaron S. Meurer

unread,
Jan 5, 2010, 10:11:43 PM1/5/10
to sy...@googlegroups.com

On Jan 5, 2010, at 7:32 PM, czbebe wrote:

> Dear members,
>
> import sympy
> import math

I believe the problem lies here. You are importing math, which imports the math sin, which doesn't work with SymPy symbolic operations. You have some options:

- Don't import math. If you need to evaluate a floating point expression, use N() or .evalf(), as in sin(1.2).evalf(). If you need other things from math, do explicit imports instead of import *. Actually, it's best to use explicit imports anyway, especially if you are writing a script.
- If you really want math behavior, use lambdify(sin(x), x, "math").
- Do from math import sin as msin or some similar. That is, use the as keyword.
- Don't import from. That is, just do import sympy and import math and then use sympy.sin and so on. Doing import sympy as S can make this easier.

One of these should fit your needs. If not, I am sure someone else on this list can come up with yet another solution.

Aaron Meurer


> u = Function('u')
> x = Symbol('x')
> diff(diff(u(x),x),x) = D(u(x), x, x) ii is all right.
> diff(x*diff(u(x),x),x) = x*D(u(x), x, x)+D(u(x), x) it is all right.
>
> diff(sin(x)*diff(u(x),x),x) gives an error.
>
> Can anyone show me the correct way to get a correct result ?
>
> czbebe

> --
> You received this message because you are subscribed to the Google Groups "sympy" group.
> To post to this group, send email to sy...@googlegroups.com.
> To unsubscribe from this group, send email to sympy+un...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/sympy?hl=en.
>
>

czbebe

unread,
Jan 5, 2010, 11:03:41 PM1/5/10
to sympy
Thanks Aaron,

To my needs,

import sympy
import math
diff(sympy.sin(x)*diff(u(x),x),x)

is a good choice because math functions are used in other places.
I will try this.

czbebe

> > For more options, visit this group athttp://groups.google.com/group/sympy?hl=en.- 引用テキストを表示しない -
>
> - 引用テキストを表示 -

Reply all
Reply to author
Forward
0 new messages