필터 지우기
필터 지우기

problem in solving linear equations in symbolic matlab

조회 수: 1 (최근 30일)
farzad
farzad 2014년 12월 14일
댓글: farzad 2015년 2월 9일
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.

채택된 답변

John D'Errico
John D'Errico 2014년 12월 14일
편집: John D'Errico 2014년 12월 14일
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
John D'Errico
John D'Errico 2014년 12월 14일
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 2015년 2월 9일
Dear John , I don't get notified when someone comments , that was why

댓글을 달려면 로그인하십시오.

추가 답변 (0개)

태그

제품

Community Treasure Hunt

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

Start Hunting!

Translated by