ASKSAGE: Sage Q&A Forum - Individual question feedhttp://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Fri, 03 Feb 2012 13:25:12 -0600How to calculate sine of a matrixhttp://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/Hi
I want to calcilate sin(M*t) which M is a 3 by 3 matrix. I have no problem with calculating exp(M*t) but it seems the sine is different!
I will be pleased if anyone could help...Thu, 02 Feb 2012 19:00:41 -0600http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/Answer by Jason Grout for <p>Hi
I want to calcilate sin(M<em>t) which M is a 3 by 3 matrix. I have no problem with calculating exp(M</em>t) but it seems the sine is different!
I will be pleased if anyone could help...</p>
http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?answer=13242#post-id-13242I'm trying to understand what you are doing with sin(Mt). Is one of these what you want?
sage: m=random_matrix(QQ,3); m
[-1 0 -1]
[-1 1 2]
[-2 0 1]
sage: m.apply_map(sin)
[-sin(1) 0 -sin(1)]
[-sin(1) sin(1) sin(2)]
[-sin(2) 0 sin(1)]
sage: t=var('t')
sage: (m*t).apply_map(sin)
[ sin(-t) 0 sin(-t)]
[ sin(-t) sin(t) sin(2*t)]
[sin(-2*t) 0 sin(t)]
Or do you mean you want to calculate the series $\sum_{k=0}^{\infty} (-1)^{k}\frac{M^{2k+1}}{(2k+1)!}$?
Fri, 03 Feb 2012 06:43:11 -0600http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?answer=13242#post-id-13242Comment by kcrisman for <p>I'm trying to understand what you are doing with sin(Mt). Is one of these what you want?</p>
<pre><code>sage: m=random_matrix(QQ,3); m
[-1 0 -1]
[-1 1 2]
[-2 0 1]
sage: m.apply_map(sin)
[-sin(1) 0 -sin(1)]
[-sin(1) sin(1) sin(2)]
[-sin(2) 0 sin(1)]
sage: t=var('t')
sage: (m*t).apply_map(sin)
[ sin(-t) 0 sin(-t)]
[ sin(-t) sin(t) sin(2*t)]
[sin(-2*t) 0 sin(t)]
</code></pre>
<p>Or do you mean you want to calculate the series $\sum_{k=0}^{\infty} (-1)^{k}\frac{M^{2k+1}}{(2k+1)!}$?</p>
http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?comment=20349#post-id-20349Ah, I *knew* there was a way to do this that we had already added. But seriously, I think @saeed1922 wants the latter. Why doesn't e^M work, though? Or more precisely, where does the error come from? I can't find it in e.__pow__??Fri, 03 Feb 2012 13:25:12 -0600http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?comment=20349#post-id-20349Answer by Shashank for <p>Hi
I want to calcilate sin(M<em>t) which M is a 3 by 3 matrix. I have no problem with calculating exp(M</em>t) but it seems the sine is different!
I will be pleased if anyone could help...</p>
http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?answer=13237#post-id-13237You could just use
$$ sin(x) = \frac{exp(i*x)-exp(-i*x)}{2*i} $$Thu, 02 Feb 2012 19:11:02 -0600http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?answer=13237#post-id-13237Answer by kcrisman for <p>Hi
I want to calcilate sin(M<em>t) which M is a 3 by 3 matrix. I have no problem with calculating exp(M</em>t) but it seems the sine is different!
I will be pleased if anyone could help...</p>
http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?answer=13241#post-id-13241I'm just putting down some thoughts here that hopefully someone else will know about.
sage: M = matrix([[2,3],[3,2]])
sage: e^M
---------------------------------------------------------------------------
TypeError Traceback (most recent call last)
TypeError: mutable matrices are unhashable
sage: exp(M)
[1/2*(e^6 + 1)*e^(-1) 1/2*(e^6 - 1)*e^(-1)]
[1/2*(e^6 - 1)*e^(-1) 1/2*(e^6 + 1)*e^(-1)]
sage: M.exp()
[1/2*(e^6 + 1)*e^(-1) 1/2*(e^6 - 1)*e^(-1)]
[1/2*(e^6 - 1)*e^(-1) 1/2*(e^6 + 1)*e^(-1)]
Naturally, this is really because there isn't any `sin` method. However:
sage: M = matrix([[2,3],[3,2]])
sage: M.simp[tab] # nothing
sage: M = matrix(SR,[[2,3],[3,2]])
sage: M.simp[tab]
M.simplify M.simplify_rational M.simplify_trig
There still isn't a `sin`. But this could be doable. Of course, the question remains as to how *many* such things we would want to add. Thoughts?Fri, 03 Feb 2012 03:50:00 -0600http://ask.sagemath.org/question/8227/how-to-calculate-sine-of-a-matrix/?answer=13241#post-id-13241