Error using solve command, says input and output are inconsistent?
조회 수: 5 (최근 30일)
이전 댓글 표시
When I type in my code it tells me that an input of 2 variables and an output of 7 variables is inconsistent. What am i doing wrong? I'm pretty the problem is with this last bit of code
syms I x1 x2 x3 x4 x5 g1 g2 lambda1 lambda2
I==1.06*x1+1.08*x2+1.1*x3+1.12*x4+1.15*x5
g1==x1+x2+x3+x4+x5
g2==x2+1.5*x3+2.5*x4+5*x5
[x1 x2 x3 x4 x5 lambda1 lambda2]=solve(diff(I,x1)-lambda1==0,diff(I,x2)-lambda1-lambda2==0,diff(I,x3)-lambda1-1.5*lambda2==0,diff(I,x4)-lambda1-2.5*lambda2==0,diff(I,x5)-lambda1-5*lambda2==0,g1==250000,g2==500000,x1,x2,x3,x4,x5,lambda1,lambda2)
댓글 수: 0
답변 (1개)
Andrew Newell
2015년 2월 8일
편집: Andrew Newell
2015년 2월 8일
Are you using the Matlab editor? If so, the orange marks indicate problems with syntax that are causing your problems. For example, hover your mouse over the double equals sign in
I==1.06*x1+1.08*x2+1.1*x3+1.12*x4+1.15*x5
and you will see a message like "Possible inappropriate use of == operator. Use = if assignment is intended." Hover it over the variable x2 in [x1 x2 ...] and you will see "Best practice is to separate output variables with commas." Fix all the highlighted problems and you get:
syms I x1 x2 x3 x4 x5 g1 g2 lambda1 lambda2
I=1.06*x1+1.08*x2+1.1*x3+1.12*x4+1.15*x5;
g1=x1+x2+x3+x4+x5;
g2=x2+1.5*x3+2.5*x4+5*x5;
[x1, x2, x3, x4, x5, lambda1, lambda2]=solve(diff(I,x1)-lambda1==0,diff(I,x2)-lambda1-lambda2==0,diff(I,x3)-lambda1-1.5*lambda2==0,diff(I,x4)-lambda1-2.5*lambda2==0,diff(I,x5)-lambda1-5*lambda2==0,g1==250000,g2==500000,x1,x2,x3,x4,x5,lambda1,lambda2);
For which you get the response, "Warning: Explicit solution could not be found." Oh, well.
NOTE ADDED: I see why you don't get any solutions. The first five equations in the solve command evaluate to:
53/50 - lambda1 = 0
27/25 - lambda2 - lambda1 = 0
11/10 - (3*lambda2)/2 - lambda1 = 0
8/25 - (5*lambda2)/2 - lambda1 = 0
23/20 - 5*lambda2 - lambda1 = 0
Five incompatible equations in two unknowns.
댓글 수: 0
참고 항목
카테고리
Help Center 및 File Exchange에서 Get Started with MuPAD에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!