ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Sat, 17 Nov 2012 20:31:19 +0100eigenvalues of a derivative vs derivative of eigenvalueshttps://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/Hi! I have this little problem. If anyone would be so kind to share his knowledge and shed some lite on it, I'd be very grateful. Big thanks in advance (and sorry for my english)!
I have a matrix M=M(x) depending on a variable x. I want sage to compute trace of a product of a derivative of M, M' and some function of it, f(M), at a fixed value of x=x_0; that is:
(tr[M'*f(M)])|_(x=x_0).
It just so happens that tr[M'*f(M)] = sum( ev_i' *f(ev_i) ), where {ev_i(x)} are eigenvalues of M. Lucky me. Diagonalisation of M commutes with differentiating or taking the function of it, one could say.
But my M and its derivative are somewhat complicated, yet simplify greatly after substituting x=x_0. So I would very much prefer first to compute M', substitute x_0 M0:=M|_(x=x_0) and M'0:=M'|_(x=x_0), and only after that ask sage for eigenvalues:
ev1=M0.eigenvalues()
ev2=M'0.eigenvalues()
So here's the question: do i have any reason for hoping that:
(tr[M'*f(M)])|_(x=x_0) = sum( ev2[i] *f(ev1[i]) for i in range(dim of M) )?
(That is, wether the order of eigenvalues changes if I exchange diagonalisation with differentiation?)Sat, 17 Nov 2012 19:18:33 +0100https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/Answer by Shashank for <p>Hi! I have this little problem. If anyone would be so kind to share his knowledge and shed some lite on it, I'd be very grateful. Big thanks in advance (and sorry for my english)!</p>
<p>I have a matrix M=M(x) depending on a variable x. I want sage to compute trace of a product of a derivative of M, M' and some function of it, f(M), at a fixed value of x=x_0; that is:</p>
<p>(tr[M'*f(M)])|_(x=x_0).</p>
<p>It just so happens that tr[M'*f(M)] = sum( ev_i' *f(ev_i) ), where {ev_i(x)} are eigenvalues of M. Lucky me. Diagonalisation of M commutes with differentiating or taking the function of it, one could say.</p>
<p>But my M and its derivative are somewhat complicated, yet simplify greatly after substituting x=x_0. So I would very much prefer first to compute M', substitute x_0 M0:=M|_(x=x_0) and M'0:=M'|_(x=x_0), and only after that ask sage for eigenvalues:</p>
<p>ev1=M0.eigenvalues()</p>
<p>ev2=M'0.eigenvalues()</p>
<p>So here's the question: do i have any reason for hoping that:</p>
<p>(tr[M'*f(M)])|_(x=x_0) = sum( ev2[i] *f(ev1[i]) for i in range(dim of M) )?</p>
<p>(That is, wether the order of eigenvalues changes if I exchange diagonalisation with differentiation?)</p>
https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?answer=14277#post-id-14277You can take the derivative of a matrix and substitute x=x0 using apply_map
ev1=M0.eigenvalues()
ev2=(M0.apply_map(lambda y:y.diff(x).subs(x==x0))).eigenvalues()
This takes the derivatives of all the components of M0, substitutes x=x0 and then calculates the eigenvalues of the resulting matrix.
Sat, 17 Nov 2012 19:31:14 +0100https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?answer=14277#post-id-14277Comment by ozik for <p>You can take the derivative of a matrix and substitute x=x0 using apply_map</p>
<pre><code>ev1=M0.eigenvalues()
ev2=(M0.apply_map(lambda y:y.diff(x).subs(x==x0))).eigenvalues()
</code></pre>
<p>This takes the derivatives of all the components of M0, substitutes x=x0 and then calculates the eigenvalues of the resulting matrix.</p>
https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?comment=18694#post-id-18694Is there any way of knowing in what order put the eigenvalues of derivative to get correct trace?Sat, 17 Nov 2012 20:31:19 +0100https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?comment=18694#post-id-18694Comment by ozik for <p>You can take the derivative of a matrix and substitute x=x0 using apply_map</p>
<pre><code>ev1=M0.eigenvalues()
ev2=(M0.apply_map(lambda y:y.diff(x).subs(x==x0))).eigenvalues()
</code></pre>
<p>This takes the derivatives of all the components of M0, substitutes x=x0 and then calculates the eigenvalues of the resulting matrix.</p>
https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?comment=18696#post-id-18696Well, ok; thank you for that comment. In order to differentiate, I was planning on typing something much-less-fancy, like to loops with dM[i,j]=diff(M[i,j], x). But what about my question? Again, sorry for my lack of narrative competence. I came up with an example:Sat, 17 Nov 2012 20:21:42 +0100https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?comment=18696#post-id-18696Comment by ozik for <p>You can take the derivative of a matrix and substitute x=x0 using apply_map</p>
<pre><code>ev1=M0.eigenvalues()
ev2=(M0.apply_map(lambda y:y.diff(x).subs(x==x0))).eigenvalues()
</code></pre>
<p>This takes the derivatives of all the components of M0, substitutes x=x0 and then calculates the eigenvalues of the resulting matrix.</p>
https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?comment=18695#post-id-18695var('x');
M=Matrix(SR, 2,2, [0, cos(x), cos(x), 0]);
dM=Matrix(SR, 2,2);
for i in range(2):
for j in range(2):
dM[i,j]=diff(M[i,j], x);
dM.eigenvalues() == [diff(M.eigenvalues()[1], x), diff(M.eigenvalues()[0], x)]
(dM*M).trace() == dM.eigenvalues()[0]*M.eigenvalues()[1] + dM.eigenvalues()[1]*M.eigenvalues()[0]
#and not:
(dM *M).trace() =/= dM.eigenvalues()[0]*M.eigenvalues()[0] + dM.eigenvalues()[1]*M.eigenvalues()[1]
#as I was hoping forSat, 17 Nov 2012 20:26:43 +0100https://ask.sagemath.org/question/9543/eigenvalues-of-a-derivative-vs-derivative-of-eigenvalues/?comment=18695#post-id-18695