Processing math: 100%

First time here? Check out the FAQ!

Ask Your Question
0

define symbolic constant

asked 11 years ago

I need to define some symbolic constants in some expressions, so that the symbolic constant survives differentiation. How can they be defined?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
1

answered 11 years ago

tmonteil gravatar image

I may not understand your question. As long as you declare the variable whith respect to which you differentiate, there should not be any problem, for example:

sage: f(x,y) = x*y
sage: f
(x, y) |--> x*y
sage: f.differentiate(x)
(x, y) |--> y

Here, you differentiate whith respect to x, so y is considered as a constant. Also:

sage: f(x) = pi*x
sage: f
x |--> pi*x
sage: f.differentiate(x)
x |--> pi

But Sage also protect you from differentiating whith respect to a constant:

sage: f.differentiate(pi)
TypeError: argument symb must be a symbol
Preview: (hide)
link
0

answered 11 years ago

updated 11 years ago

Permit me to ask this another way. I want to compute the symbolic gradient of the following:

-mu * x / r^3, where mu is a constant and r = sqrt( x^2 + y^2 + z^2 )

In my sage worksheet I have:

variables = var( 'x, y, z, r, f' )

constants = var( 'm' )

r = sqrt( x^2 + y^2 + z^2 )

f = -m * x / r^3

show(f.gradient([x,y,z]))

Sage does not give me the correct answer. My question is how do I get Sage to treat or declare m as a constant in the calculus sense?

Preview: (hide)
link

Comments

When i do this, i get (3mx2(x2+y2+z2)52m(x2+y2+z2)32,3mxy(x2+y2+z2)52,3mxz(x2+y2+z2)52) I did the computation by hand and it seems to be the correct result. If you replace `m` by `pi`, you will get the same answer. Which expression did you expect ?

tmonteil gravatar imagetmonteil ( 11 years ago )

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 11 years ago

Seen: 3,013 times

Last updated: Nov 20 '13