# Solving linear matrix equations This post is a wiki. Anyone with karma >750 is welcome to improve it.

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

edit retag close merge delete

Sort by » oldest newest most voted

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:

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,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.

more

Thank 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,psi_d)

it gives : TypeError: 'module' object has no attribute '__getitem__' what does it mean?

I'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.

I'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.

I think the problem is in sys, actually if i do show(sys) 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.

I 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.