Ask Your Question

Solve symbolic matrix cell

asked 2019-03-19 14:44:52 -0500

I'm trying to take a cell from a matrix and solve for a variable symbolically. When I run this, I get the error:

TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.

This is the code I am trying to execute:

Rz = matrix([[cos(a),-sin(a),0,0],[sin(a),cos(a),0,0],[0,0,1,0],[0,0,0,1]])
Ry = matrix([[cos(b),0,sin(b),0],[0,1,0,0],[-sin(b),0,cos(b),0],[0,0,0,1]])
Rx = matrix([[1,0,0,0],[0,cos(c),-sin(c),0],[0,sin(c),cos(c),0],[0,0,0,1]])
P = matrix([[x],[y],[z],[1]])

Rzyxp = Rz * Ry * Rx * P

eqn2 = Rzyxp[2]

result1 = solve(eqn2==0, b)

Any help would be appreciated

edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted

answered 2019-03-20 11:33:44 -0500

nbruin gravatar image

Rzyxp is a matrix, so Rzyxp[2] is its third row: a vector; albeit a one-dimensional one. In order to get the entry itself, you need to index with two indices:


does not give an error (but possibly not a very useful answer either).

edit flag offensive delete link more

answered 2019-03-20 14:31:51 -0500

Emmanuel Charpentier gravatar image

nbrion's answer's usefulness can be slightly enhanced with a few assumptions:

 sage: with assuming(b>-pi/2,b<pi/2): ((eqn2[0]).solve(b)[0]/cos(b)).trig_reduce()
....: .arctan().trig_expand()
b == arctan(z*cos(c)/x + y*sin(c)/x)


edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

1 follower


Asked: 2019-03-19 14:44:52 -0500

Seen: 31 times

Last updated: Mar 20