Error using solve command, says input and output are inconsistent?
35 次查看(过去 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!