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.Wed, 03 Dec 2014 02:38:35 +0100Solving linear matrix equationshttps://ask.sagemath.org/question/25059/solving-linear-matrix-equations/Hi everybody, I'm new to Sage and I'm pretty confused with the solving of matrix equations, I didn't fully understand the guide.
I've got these vectors:
V_fa = vector([V_f*cos(phi), V_f*sin(phi), 0])
V_ra = vector([V, 0, 0])
omega = vector([0, 0, L*psi_d])
P = vector([0, L*psi_d, 0])
And i want to implement the equation:
V_fa=V_ra+omega.cross_product(P)
to isolate and obtain the value of `psi_d`.
How can I do that?
Thank you very much
Sun, 30 Nov 2014 19:35:22 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/Answer by calc314 for <p>Hi everybody, I'm new to Sage and I'm pretty confused with the solving of matrix equations, I didn't fully understand the guide.</p>
<p>I've got these vectors:</p>
<pre><code>V_fa = vector([V_f*cos(phi), V_f*sin(phi), 0])
V_ra = vector([V, 0, 0])
omega = vector([0, 0, L*psi_d])
P = vector([0, L*psi_d, 0])
</code></pre>
<p>And i want to implement the equation:</p>
<pre><code>V_fa=V_ra+omega.cross_product(P)
</code></pre>
<p>to isolate and obtain the value of <code>psi_d</code>.</p>
<p>How can I do that?</p>
<p>Thank you very much</p>
https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?answer=25060#post-id-25060I think you are asking for a system from this vector equation that you can then get Sage to solve. To create such a system, try:
ans1=V_ra+omega.cross_product(P)
sys=[ans1[i]==V_fa[i] for i in range(0,3)]
Then, you get the result:
[-L^2*psi_d^2 + V == V_f*cos(phi), 0 == V_f*sin(phi), 0 == 0]
Solving the first equation for `psi_d` can be done by:
solve(sys[0],psi_d)
and gives:
[psi_d == -sqrt(-V_f*cos(phi) + V)/L, psi_d == sqrt(-V_f*cos(phi) + V)/L]
Sage does not seem to like the idea of solving all three equations at once. You might be able to avoid this by specifying more information about `phi`.
Sun, 30 Nov 2014 20:12:04 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?answer=25060#post-id-25060Comment by Silvia for <p>I think you are asking for a system from this vector equation that you can then get Sage to solve. To create such a system, try:</p>
<pre><code>ans1=V_ra+omega.cross_product(P)
sys=[ans1[i]==V_fa[i] for i in range(0,3)]
</code></pre>
<p>Then, you get the result:</p>
<pre><code>[-L^2*psi_d^2 + V == V_f*cos(phi), 0 == V_f*sin(phi), 0 == 0]
</code></pre>
<p>Solving the first equation for <code>psi_d</code> can be done by:</p>
<pre><code>solve(sys[0],psi_d)
</code></pre>
<p>and gives: </p>
<pre><code>[psi_d == -sqrt(-V_f*cos(phi) + V)/L, psi_d == sqrt(-V_f*cos(phi) + V)/L]
</code></pre>
<p>Sage does not seem to like the idea of solving all three equations at once. You might be able to avoid this by specifying more information about <code>phi</code>.</p>
https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25062#post-id-25062Thank you for your reply!
What kind of information do i need to specify? It's an angle, so do i have to declare it as a real?
Also, when i do
solve(sys[0],psi_d)
it gives :
TypeError: 'module' object has no attribute '__getitem__'
what does it mean?Sun, 30 Nov 2014 20:44:55 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25062#post-id-25062Comment by calc314 for <p>I think you are asking for a system from this vector equation that you can then get Sage to solve. To create such a system, try:</p>
<pre><code>ans1=V_ra+omega.cross_product(P)
sys=[ans1[i]==V_fa[i] for i in range(0,3)]
</code></pre>
<p>Then, you get the result:</p>
<pre><code>[-L^2*psi_d^2 + V == V_f*cos(phi), 0 == V_f*sin(phi), 0 == 0]
</code></pre>
<p>Solving the first equation for <code>psi_d</code> can be done by:</p>
<pre><code>solve(sys[0],psi_d)
</code></pre>
<p>and gives: </p>
<pre><code>[psi_d == -sqrt(-V_f*cos(phi) + V)/L, psi_d == sqrt(-V_f*cos(phi) + V)/L]
</code></pre>
<p>Sage does not seem to like the idea of solving all three equations at once. You might be able to avoid this by specifying more information about <code>phi</code>.</p>
https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25064#post-id-25064I'm not sure about that error. I'm assuming you did something like `var('V_f, phi, V, L, psi_d')` at the beginning of your work.Mon, 01 Dec 2014 04:24:28 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25064#post-id-25064Comment by calc314 for <p>I think you are asking for a system from this vector equation that you can then get Sage to solve. To create such a system, try:</p>
<pre><code>ans1=V_ra+omega.cross_product(P)
sys=[ans1[i]==V_fa[i] for i in range(0,3)]
</code></pre>
<p>Then, you get the result:</p>
<pre><code>[-L^2*psi_d^2 + V == V_f*cos(phi), 0 == V_f*sin(phi), 0 == 0]
</code></pre>
<p>Solving the first equation for <code>psi_d</code> can be done by:</p>
<pre><code>solve(sys[0],psi_d)
</code></pre>
<p>and gives: </p>
<pre><code>[psi_d == -sqrt(-V_f*cos(phi) + V)/L, psi_d == sqrt(-V_f*cos(phi) + V)/L]
</code></pre>
<p>Sage does not seem to like the idea of solving all three equations at once. You might be able to avoid this by specifying more information about <code>phi</code>.</p>
https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25065#post-id-25065I've not been successful with getting the solving to work when the two nontrivial equations are both involved. Sage (actually Maxima) seems to be having some sort of issue with this case. It's got me baffled.Mon, 01 Dec 2014 04:25:28 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25065#post-id-25065Comment by Silvia for <p>I think you are asking for a system from this vector equation that you can then get Sage to solve. To create such a system, try:</p>
<pre><code>ans1=V_ra+omega.cross_product(P)
sys=[ans1[i]==V_fa[i] for i in range(0,3)]
</code></pre>
<p>Then, you get the result:</p>
<pre><code>[-L^2*psi_d^2 + V == V_f*cos(phi), 0 == V_f*sin(phi), 0 == 0]
</code></pre>
<p>Solving the first equation for <code>psi_d</code> can be done by:</p>
<pre><code>solve(sys[0],psi_d)
</code></pre>
<p>and gives: </p>
<pre><code>[psi_d == -sqrt(-V_f*cos(phi) + V)/L, psi_d == sqrt(-V_f*cos(phi) + V)/L]
</code></pre>
<p>Sage does not seem to like the idea of solving all three equations at once. You might be able to avoid this by specifying more information about <code>phi</code>.</p>
https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25084#post-id-25084I think the problem is in sys[0], actually if i do show(sys[0]) it gives the same errore message.
i tried writing
for i in range (0,3):
sys[i]=[ans1[i]==rV_fa[i]]
but it says TypeError: 'module' object does not support item assignment. What does it means?
How can I fix it? It seems a very simple operation to me but i can't understand what it is that I'm doing wrong.Tue, 02 Dec 2014 17:10:41 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25084#post-id-25084Comment by calc314 for <p>I think you are asking for a system from this vector equation that you can then get Sage to solve. To create such a system, try:</p>
<pre><code>ans1=V_ra+omega.cross_product(P)
sys=[ans1[i]==V_fa[i] for i in range(0,3)]
</code></pre>
<p>Then, you get the result:</p>
<pre><code>[-L^2*psi_d^2 + V == V_f*cos(phi), 0 == V_f*sin(phi), 0 == 0]
</code></pre>
<p>Solving the first equation for <code>psi_d</code> can be done by:</p>
<pre><code>solve(sys[0],psi_d)
</code></pre>
<p>and gives: </p>
<pre><code>[psi_d == -sqrt(-V_f*cos(phi) + V)/L, psi_d == sqrt(-V_f*cos(phi) + V)/L]
</code></pre>
<p>Sage does not seem to like the idea of solving all three equations at once. You might be able to avoid this by specifying more information about <code>phi</code>.</p>
https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25088#post-id-25088I think you might have imported the python module `sys` at some point in your worksheet. In that case, you cannot use sys as a variable name. Try changing that variable name to something else and see if that resolves the error.
In addition, the code you suggested above will not assign things to sys[i] unless you initialize the sys variable as a list with 3 objects. This is the reason you are getting the error in this case.Wed, 03 Dec 2014 02:38:35 +0100https://ask.sagemath.org/question/25059/solving-linear-matrix-equations/?comment=25088#post-id-25088