Ask Your Question
1

Taking derivative of a solution

asked 2011-11-18 08:58:41 +0100

Hun gravatar image

updated 2011-11-18 14:22:52 +0100

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?

edit retag flag offensive close merge delete

2 Answers

Sort by ยป oldest newest most voted
4

answered 2011-11-18 09:23:25 +0100

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]]
edit flag offensive delete link more

Comments

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

Hun gravatar imageHun ( 2011-11-18 09:33:38 +0100 )edit
0

answered 2011-11-18 14:10:45 +0100

Hun gravatar image

updated 2011-11-18 14:29:44 +0100

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])
edit flag offensive delete link more

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: 2011-11-18 08:58:41 +0100

Seen: 433 times

Last updated: Nov 18 '11