Optimization using fval function
Ältere Kommentare anzeigen
I am having trouble getting this code to run. The goal is to minimize the cost of a dumpster while keeping within a certain volume range using lagrange multipliers. My code runs but the error message that comes up is "Failure in initial objective function evaluation. FSOLVE cannot continue.". I am pretture sure lines 9 and 10 are wrong but can someone help me with this?
function F = Dumpster(quad)
L = quad(1);
W = quad(2);
H = quad(3);
X = quad(4);
F = [5*W+6*H-(W*H),5*L+6*H-(H*L),6*L+6*W-(W*L),L*W*H-1056];
test1 = [1,2,3,4];
[w1,fval] = fsolve(@Dumpster,test1);
w1;
fval;
end
6 Kommentare
Michael Hay
am 6 Mär. 2021
Stephen23
am 6 Mär. 2021
Note that you have written a recursive function. This means you call Dumpster, inside which you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster. Then inside that Dumpster call you call fsolve which in turn calls Dumpster... etc.
Is that your intention?
Michael Hay
am 6 Mär. 2021
Stephen23
am 6 Mär. 2021
"How can I fix that?"
Don't call Dumpster (even indirectly) inside Dumpster.
Probably you want to to call fsolve outside of Dumpster.
Michael Hay
am 6 Mär. 2021
Michael Hay
am 6 Mär. 2021
Antworten (0)
Kategorien
Mehr zu Surrogate Optimization finden Sie in Hilfe-Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!