problem in solving linear equations in symbolic matlab

3 views (last 30 days)
Hi All
I am using these lines : syms c21 c31
[A, b0] = equationsToMatrix([M1 == 0,M2 == 0], [c21,c31])
X = linsolve(A,b0);
I get the error
The following error occurred converting from sym to double: Error using mupadmex Error in MuPAD command: DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use the VPA function instead.

Accepted Answer

John D'Errico
John D'Errico on 14 Dec 2014
Edited: John D'Errico on 14 Dec 2014
When you see this kind of error, think about what it is telling you. Look at the entire error. Because it will tell you information. Also, tell us the entire error, as well as what you did to generate that error. For example, in order for me to reproduce that error, I had to do something you did not report to us.
M1 = x + 3*y - 2 + x*sin(z);
M2 = 12.34234562342436534656869*x +y + 5;
[A, b] = equationsToMatrix([M1 == 0,M2 == 0], [x,y])
A =
[ sin(z) + 1, 3]
[ 217128840431765/17592186044416, 1]
b =
2
-5
X = linsolve(A,b)
X =
299067162755072/(17592186044416*sin(z) - 633794335250879)
-(10*(8796093022208*sin(z) + 52221861108561))/(17592186044416*sin(z) - 633794335250879)
As you can see, linsolve in fact can handle that the matrices were actually symbolic objects, containing in this case, the variable z. No error was generated. It is a bit nasty looking, because the numbers are comprised of rather large ratios.
In fact, that error is not generated UNTIL I do one more thing...
double(ans)
Error using symengine (line 58)
DOUBLE cannot convert the input expression into a double array.
If the input expression contains a symbolic variable, use VPA.
Error in sym/double (line 523)
Xstr = mupadmex('symobj::double', S.s, 0);
So somehow, you are doing something additional to X, that you did not tell us. The error message, or what little you reported of it, told me that. And it told you that too! All you had to do was READ the error message and think about what it said. It would have been more clear had you given us the entire error message, including what you tried to do.
You cannot convert a truly symbolic object into a matrix of doubles. In order to do that, the result must itself be comprised of numbers. As you can see in the example I made up, X was itself a function of z. (I was actually surprised that linsolve succeeded, but it did not fail.)
By the way, the error message also told you to use vpa to make those nasty looking numbers more readable.
  3 Comments
John D'Errico
John D'Errico on 14 Dec 2014
PLEASE don't add an answer if you have a question about my answer. There are comments. USE THEM. You can put anything into a comment that you can into an answer! As you can see, I moved your answer into a comment.
Anyway, there are many undefined variables in the expression for M. So this is not the complete code. And it has NOTHING to do with division of large number. See that my example had a symbolic variable in the result, z. That is part of your problem. You have something in there that you are not showing me so far.
Again, please don't keep adding answers for every comment you make.
farzad
farzad on 9 Feb 2015
Dear John , I don't get notified when someone comments , that was why

Sign in to comment.

More Answers (0)

Tags

Products

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!