Effacer les filtres
Effacer les filtres

Error using solve command, says input and output are inconsistent?

30 vues (au cours des 30 derniers jours)
Michael Tulkki
Michael Tulkki le 8 Fév 2015
Modifié(e) : Andrew Newell le 8 Fév 2015
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)

Réponses (1)

Andrew Newell
Andrew Newell le 8 Fév 2015
Modifié(e) : Andrew Newell le 8 Fév 2015
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.

Catégories

En savoir plus sur Get Started with MuPAD dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by