Filter löschen
Filter löschen

How do I automate this fmincon code so it will return values from 10 variations of two variables contained in the constraint file? The variables I am varying are not variables that are being optimized.

2 Ansichten (letzte 30 Tage)
ObjFcn = @myObjective;
x0 = [10 0.001 7];
LB = [0 0 0];
UB = [50 0.5 7.5];
ConsFcn = @myConstraints;
[x] = fmincon(ObjFcn,x0,[],[],[],[],LB,UB,ConsFcn);
disp(x)
disp(myObjective(x))
  1 Kommentar
Scott Sanders
Scott Sanders am 2 Apr. 2018
I have managed to get it to work to the extent where it performs the right amount of optimizations for the varying variables outside the optimization. However for each optimization it overwrites the previous values, meaning at the end there is only 1 set of values when there should be 100. I know it is performing all 100 optimizations because of the "disp(x)" is showing 100 sets of values but just not storing them as an array in the workspace.
for X=1:1:10
for Y=1:1:10
ObjFcn = @myObjective;
x0 = [10 0.001 7];
LB = [0 0 0];
UB = [50 0.5 7.5];
ConsFcn = @(x)myConstraints(x,X,Y);
[x] = fmincon(ObjFcn,x0,[],[],[],[],LB,UB,ConsFcn);
disp(x)
disp(myObjective(x))
end
end

Melden Sie sich an, um zu kommentieren.

Akzeptierte Antwort

Matt J
Matt J am 1 Apr. 2018
  1 Kommentar
Scott Sanders
Scott Sanders am 1 Apr. 2018
Thanks that worked. I just had to incorporate a for loop as well to make sure the matrix ran outside the constraints and not inside.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (0)

Kategorien

Mehr zu Get Started with Optimization Toolbox finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by