Ask Your Question

# Taking derivative of a solution

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 close merge delete

## 2 Answers

Sort by ยป oldest newest most voted
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]]

more

## Comments

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

( 2011-11-18 09:33:38 +0200 )edit

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])

more

## Your Answer

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

Add Answer

## Stats

Asked: 2011-11-18 08:58:41 +0200

Seen: 381 times

Last updated: Nov 18 '11