Ask Your Question
1

Taking derivative of a solution

asked 13 years ago

Hun gravatar image

updated 13 years ago

Hi, is there a way to take a derivative of a solution of equations?

For example,

var('p, alpha, beta, q, A, B, J, K')
h=solve([p==alpha+2*beta*q, A-B*p==J*q, p*q-K-alpha*q-beta*q^2==0],p,q,J)

in the solution expressions for p,q,J, can I take a partial derivative of each with respect to A by adding some kind of an expression? Also, is there a effective way to simplify the results that I get for p,q,J?

Preview: (hide)

2 Answers

Sort by » oldest newest most voted
4

answered 13 years ago

kcrisman gravatar image
sage: h
[[p == -(2*sqrt(K)*beta - alpha*sqrt(beta))/sqrt(beta), q == -(2*B*K*sqrt(beta) - (B*alpha - A)*sqrt(K))/(2*B*sqrt(K)*beta - B*alpha*sqrt(beta) + A*sqrt(beta)), J == -(2*B*K*beta - (B*alpha - A)*sqrt(K*beta))/K], [p == (2*sqrt(K)*beta + alpha*sqrt(beta))/sqrt(beta), q == (2*B*K*sqrt(beta) + (B*alpha - A)*sqrt(K))/(2*B*sqrt(K)*beta + B*alpha*sqrt(beta) - A*sqrt(beta)), J == -(2*B*K*beta + (B*alpha - A)*sqrt(K*beta))/K]]
sage: h[0]
[p == -(2*sqrt(K)*beta - alpha*sqrt(beta))/sqrt(beta), q == -(2*B*K*sqrt(beta) - (B*alpha - A)*sqrt(K))/(2*B*sqrt(K)*beta - B*alpha*sqrt(beta) + A*sqrt(beta)), J == -(2*B*K*beta - (B*alpha - A)*sqrt(K*beta))/K]
sage: h[0][0]
p == -(2*sqrt(K)*beta - alpha*sqrt(beta))/sqrt(beta)
sage: h[0][0].rhs()
-(2*sqrt(K)*beta - alpha*sqrt(beta))/sqrt(beta)
sage: h[0][0].rhs().diff(A)
0
sage: h[0][1].rhs().diff(A)
(2*B*K*sqrt(beta) - (B*alpha - A)*sqrt(K))*sqrt(beta)/(2*B*sqrt(K)*beta - B*alpha*sqrt(beta) + A*sqrt(beta))^2 - sqrt(K)/(2*B*sqrt(K)*beta - B*alpha*sqrt(beta) + A*sqrt(beta))
sage: h[0][2].rhs().diff(A)
-sqrt(K*beta)/K

This is the slow way, though. You might try this.

sage:     h=solve([p==alpha+2*beta*q, A-B*p==J*q, p*q-K-alpha*q-beta*q^2==0],p,q,J,solution_dict=True)
sage: [[s.diff(A) for s in sol.values()] for sol in h]
[[(2*B*K*sqrt(beta) - (B*alpha - A)*sqrt(K))*sqrt(beta)/(2*B*sqrt(K)*beta - B*alpha*sqrt(beta) + A*sqrt(beta))^2 - sqrt(K)/(2*B*sqrt(K)*beta - B*alpha*sqrt(beta) + A*sqrt(beta)), -sqrt(K*beta)/K, 0], [(2*B*K*sqrt(beta) + (B*alpha - A)*sqrt(K))*sqrt(beta)/(2*B*sqrt(K)*beta + B*alpha*sqrt(beta) - A*sqrt(beta))^2 - sqrt(K)/(2*B*sqrt(K)*beta + B*alpha*sqrt(beta) - A*sqrt(beta)), sqrt(K*beta)/K, 0]]
Preview: (hide)
link

Comments

Thanks!! I'm going to have to study your answer for a while of course..

Hun gravatar imageHun ( 13 years ago )
0

answered 13 years ago

Hun gravatar image

updated 13 years ago

So this is what I would have wanted to do.. prior to learning about it from here. :)

var('p, alpha, beta, q, A, B, J, K')
h=solve([p==alpha+2*beta*q, A-B*p==J*q, p*q-K-alpha*q-beta*q^2==0],p,q,J)
show(h[1][0].simplify_full())
show(h[1][1].simplify_full())
show(h[1][2].simplify_full())
show(h[1][0].rhs().diff(A).simplify_full())
show(h[1][1].rhs().diff(A).simplify_full())
show(h[1][2].rhs().diff(A).simplify_full())

and this..

h=solve([p==alpha+2*beta*q, A-B*p==J*q, p*q-K-alpha*q-beta*q^2==0],p,q,J,solution_dict=True)
show([[s.diff(A).simplify_full() for s in sol.values()] for sol in h])
Preview: (hide)
link

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: 13 years ago

Seen: 488 times

Last updated: Nov 18 '11