'Solve' produces solutions one some computers, but not others
2 views (last 30 days)
Show older comments
Gunnar Larsson
on 9 Nov 2015
Commented: Gunnar Larsson
on 29 Nov 2015
Hi!
I have a rather confusing problem. I have an array 7x1 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?
Accepted Answer
Walter Roberson
on 9 Nov 2015
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().
0 Comments
More Answers (0)
See Also
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!