Outputting solutions to symbolic variables in a matrix.

Joe Turner (view profile)

on 17 Feb 2019
Latest activity Answered by Walter Roberson

Walter Roberson (view profile)

on 17 Feb 2019
I created a system of 22 symbolic varriables for a rather large system of euqation I was solving. I was able to solve for all the varriables and file them into a 22x1 matrix. However, now I need to extract the solve values of those matrix elements. When I try to use an element like Matrix(7,1) it simply outputs 'x7', and I cant use the 'sol.' on the matrix or its elements to get these numbers. Is there an efficent way to get the solved values from all the matrix elements?

Star Strider (view profile)

on 17 Feb 2019

Assuming the vector elements are not functions of symbolic variables (i.e. are purely numeric) see if using the double (link) function will convert them to an array that will allow you to access specific numeric elements. (It should.)

Joe Turner

Joe Turner (view profile)

on 17 Feb 2019
Trying to use that gives me an error:
Error using symengine
Unable to convert expression into double array.
Error in sym/double (line 672)
Hopefully I was clear in the original question, but the matrix I'm trying to get the values for looks something like M=[x1;x2;x3...x22]. I've already got the solutions for the xs, and can view them with sol.x. I just need to convert the matrix to store all the solved values
Star Strider

Star Strider (view profile)

on 17 Feb 2019
Your vector likely contains symbolic variables in the solutions, so double will not work in that event. (I thought I covered that in: ‘Assuming the vector elements are not functions of symbolic variables...’)
You need to evaluate them with respect to those variables, and then export them as double values.
A simple example:
syms x y
a(1) = sym(pi);
a(2) = pi*x + y;
D(1) = double(a(1))
D(2) = double(a(2))
produces:
D =
3.14159265358979
Error using symengine
Unable to convert expression into double array.
Error in sym/double (line 672)
Error in TestScript (line ###)
D(2) = double(a(2))
I suspect this is essentially the same error you are seeing.