ASKSAGE: Sage Q&A Forum - Individual question feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 20 Mar 2019 14:31:51 -0500Solve symbolic matrix cellhttps://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/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:
var('a','b','c','x','y','z')
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
show(Rzyxp)
eqn2 = Rzyxp[2]
show(eqn2)
result1 = solve(eqn2==0, b)
show(result1)
Any help would be appreciatedTue, 19 Mar 2019 14:44:52 -0500https://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/Answer by Emmanuel Charpentier for <p>I'm trying to take a cell from a matrix and solve for a variable symbolically. When I run this, I get the error:</p>
<p>TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.</p>
<p>This is the code I am trying to execute:</p>
<pre><code>var('a','b','c','x','y','z')
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
show(Rzyxp)
eqn2 = Rzyxp[2]
show(eqn2)
result1 = solve(eqn2==0, b)
show(result1)
</code></pre>
<p>Any help would be appreciated</p>
https://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/?answer=45847#post-id-45847`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)
HTH,Wed, 20 Mar 2019 14:31:51 -0500https://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/?answer=45847#post-id-45847Answer by nbruin for <p>I'm trying to take a cell from a matrix and solve for a variable symbolically. When I run this, I get the error:</p>
<p>TypeError: The first argument must be a symbolic expression or a list of symbolic expressions.</p>
<p>This is the code I am trying to execute:</p>
<pre><code>var('a','b','c','x','y','z')
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
show(Rzyxp)
eqn2 = Rzyxp[2]
show(eqn2)
result1 = solve(eqn2==0, b)
show(result1)
</code></pre>
<p>Any help would be appreciated</p>
https://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/?answer=45844#post-id-45844`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:
solve(Rzyxp[2,0],b)
does not give an error (but possibly not a very useful answer either).Wed, 20 Mar 2019 11:33:44 -0500https://ask.sagemath.org/question/45841/solve-symbolic-matrix-cell/?answer=45844#post-id-45844