MATLAB: ‘Solve’ produces solutions one some computers, but not others

evalsolvesymbolicSymbolic Math Toolbox

Hi!
I have a rather confusing problem. I have an array 7×1 sym:
F=
1 - conc2 - conc3 - conc4 - conc5 - conc6 - conc7 - conc1
(2*conc4 + 2*conc5)/(2*conc1 + conc2 + 2*conc3 + conc4 + conc6) - 137/171
(2*conc4 + 2*conc5)/(conc1 + conc2) - 685/256
(2*conc4 + 2*conc5)/(conc6 + 2*conc7) - 137/642
(conc2*conc3^(1/2))/conc1 - 3327435595198581/288230376151711744
(conc3^(1/2)*conc5)/conc4 - 298932303587285/144115188075855872
(conc3^(1/2)*conc7^(1/2))/conc6 - 3468615750991967/140737488355328
I use solve on this array, and evaluate the expressions to get numeric values:
solution = solve(F)
names = fieldnames(solution);
l=length(names);
answer=zeros(l,1);
for a=1:l
answer(a)=eval(getfield(solution, names{a}));
end
When I run it on my computer (Windows 7, Matlab 2013a) I get:
answer =
0.1015
0.0137
0.0073
0.1504
0.0036
0.0029
0.7205
However, on some other computers (in general running on Matlab 2015a) 'solve' returns rather complex expressions that use RootOf and z, which eval cannot handle. Has anyone got a clue what might be the cause and how it might be solved?

Best Answer

The cause of the problem is that you cannot eval() symbolic expressions. Symbolic expressions are written in a language which is similar to MATLAB but is not MATLAB.
If you have a symbolic value that you want to convert to numeric, then use double() . If you are providing specific values for symbolic variables by having assigned numeric values to the same names, then you might need to subs() before you do the double().