Too Many Output Arguments
7 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
Tyler Reohr
el 6 de Oct. de 2020
Comentada: Walter Roberson
el 7 de Oct. de 2020
I'm using Matlab to solve for the constrained optimization of f(x,y,z) = 6x+6y+5z with a constraint of 3x^2+3y^2+5z^2 = 29.
My code looks like this:
clc
syms x y z t l
f = 6*x + 6*y +5*z
c = 3*x^2+3*y^2+5*z^2
c1 = 29
gFunc = gradient(f)
gConst = gradient(c)
eqn1 = gFunc(1,1) == l * gConst(1,1)
eqn2 = gFunc(2,1) == l * gConst(2,1)
eqn3 = gFunc(3,1) == l * gConst(3,1)
eqn4 = c == c1
[xsoln,ysoln,zsoln,lsoln] = solve([eqn1,eqn2,eqn3,eqn4],[x,y,z,l])
When I run the code, I get an error in saying that [xsoln,ysoln,zsoln,lsoln] = ... has too many output arguments, but I am solving 4 equations for 4 variables, and want 4 outputs, so I don't see how I am getting this error.
Any tips? Thanks!
0 comentarios
Respuesta aceptada
Walter Roberson
el 7 de Oct. de 2020
clc
syms x y z t l
f = 6*x + 6*y +5*z
c = 3*x^2+3*y^2+5*z^2
c1 = 29
gFunc = gradient(f)
gConst = gradient(c)
eqn1 = gFunc(1,1) == l * gConst(1,1)
eqn2 = gFunc(2,1) == l * gConst(2,1)
eqn3 = gFunc(3,1) == l * gConst(3,1)
eqn4 = c == c1
[xsoln,ysoln,zsoln,lsoln] = solve([eqn1,eqn2,eqn3,eqn4],[x,y,z,l])
Works for me in R2020a and R2020b . Which release are you using?
7 comentarios
Walter Roberson
el 7 de Oct. de 2020
You had accidentally assigned a value to a variable named solve
Más respuestas (0)
Ver también
Categorías
Más información sobre Descriptive Statistics en Help Center y File Exchange.
Productos
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!