Filter löschen
Filter löschen

Hi all; when i run the optimtool i got this message error: ( Optimization running. Error running optimization. Inner matrix dimensions must agree.) so kindly can any one explaine what is the problem

1 Ansicht (letzte 30 Tage)
I try to use optimtool (fmincon) to find the optimal values for two variable(x1,x2), I use SQP as the algorithm, the start point [0,0], bounds [0,0], [50,50], and the objective function is @objfun
function f = objfun(x1,x2)
a1=1;
a2=5;
a3=-4;
b1=1;
b2=2;
f=a1*(x1-b1)*(x1-b1)+a2*(x2-b2)*(x2-b2)+a3*x1*x2;
end

Akzeptierte Antwort

Walter Roberson
Walter Roberson am 5 Mär. 2016
Your objective function will be passed a single variable which is a vector of values. It will not be passed two scalars.
function f = objfun(x)
x1 = x(1); x2 = x(2);
a1=1;
a2=5;
a3=-4;
b1=1;
b2=2;
f=a1*(x1-b1)*(x1-b1)+a2*(x2-b2)*(x2-b2)+a3*x1*x2;
end

Weitere Antworten (0)

Kategorien

Mehr zu Problem-Based Optimization Setup finden Sie in Help Center und File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by