MATLAB: Solving system of equations with symbolic vector elements as variables

Symbolic Math Toolboxsystem equations vector symbolic

Hi all,
I am new to MatLab and the syntax is confusing me. I am trying to solve a system of equations symbolically where the variables are elements of a vector, but can't seem to get the syntax correct and can't find anything similar on help pages.
I have defined the vector symbolically as below.
pi=sym('pi',[1 3]);
pi=solve(0.6*pi(1)+0.3*pi(2)+0.2*pi(3)==pi(1),0.1*pi(1)+0.3*pi(2)+0.5*pi(3)==pi(3),pi(1)+pi(2)+pi(3)==1,pi(1),pi(2),pi(3))
Instead of assigning the numerical solution to the vector pi, it gives me the following output:
pi1: [1x1 sym]
pi2: [1x1 sym]
pi3: [1x1 sym]
If I don't assign the solution to pi but simply run the solve command as follows:
solve(0.6*pi(1)+0.3*pi(2)+0.2*pi(3)==pi(1),0.1*pi(1)+0.3*pi(2)+0.5*pi(3)==pi(3),pi(1)+pi(2)+pi(3)==1,pi(1),pi(2),pi(3))
Then I get the following error:
Undefined function 'mtimes' for input arguments of type 'struct'.
Your help is appreciated!

Best Answer

The symbolic toolbox does not produce numeric solutions: it produces symbolic solutions where the symbols might be in terms of rational numbers or expressions or numbers that are being stored in symbolic form. For example,
sym('0.1')
really does mean 1 x 10^-1 in the symbolic toolbox, by in MATLAB, 0.1 means "the closest number to 0.1 that is representable with a 53 bit binary matissa, which is 0.1000000000000000055511151231257827021181583404541015625
You should examine pi.pi1 to see what it gives you. If you want to approximate the solution in double precision then use double(pi.pi1)