# solving matrix equation

Could anyone please tell me how to solve a matrix equation? In the following code I have an extremely complicated matrix O. But I know that the matrix O equals to P. (I'm deriving what textbook didn't and the textbook said that they are same.)

var('theta, phi, psi, omega_1, omega_2, omega_3, t, f, g, h') #Variables are defined.

theta=function('theta')(t); phi=function('phi')(t); psi=function('psi')(t);

R1=matrix([[cos(phi), sin(phi),0],[-sin(phi), cos(phi), 0],[0, 0, 1]])

R2=matrix([[1,0,0],[0, cos(theta), sin(theta)],[0, -sin(theta), cos(theta)]])

R3=matrix([[cos(psi),sin(psi),0],[-sin(psi),cos(psi),0],[0,0,1]])

P=matrix([[0,omega_3,-omega_2],[-omega_3, 0, omega_1],[omega_2, -omega_1, 0]])

R=R3*R2*R1

R_T=R.T; R_dev=R.derivative(t)

O=R_dev*R_T

view(O)


assuming that O==P, How can I obtain the omega_1, omega_2, omega_3 as function of theta, phi, psi, t?

edit retag close merge delete

Sort by » oldest newest most voted Use this to simplify the matrix:

O.parent()([x.full_simplify() for x in O.list()])


Then omega_i will just be the coefficients of this simplified matrix.

EDIT:

The command t.full_simplify() tries to simplify t as much as possible and return the result. The rest of the line is the application to the list of matrix coefficients O.list(), and then rebuilding the matrix ; O.parent() is the space of matrices of the correct size over the correct ring. This matrix space can swallow the list and give back a matrix. This could also be done more simply using

O.apply_map(lambda t:t.full_simplify())

more

I appreciate for your answer. It works perfectly. But could you please let me know what the code means? The 'parent()()' and 'x.full_simplify()'?