How to repeat previous steps from the output

3 Ansichten (letzte 30 Tage)
Angel Ani
Angel Ani am 19 Jun. 2021
Kommentiert: Angel Ani am 28 Jun. 2021
x=1 for a=[5 6 7 8] %solved optimization problem to get "x" end
Now, the new "x" is not 1, but the optimal value and Continue this to 5 iteration
How to do the last (above) step?

Akzeptierte Antwort

Sulaymon Eshkabilov
Sulaymon Eshkabilov am 19 Jun. 2021
Here is a simple optimization problem from MATLAB help documentation taken as an example to solve within a loop iteration.
x = optimvar('x',2);
eq1 = exp(-exp(-(x(1) + x(2)))) == x(2)*(1 + x(1)^2);
eq2 = x(1)*cos(x(2)) + x(2)*sin(x(1)) == 1/2;
prob = eqnproblem;
prob.Equations.eq1 = eq1;
prob.Equations.eq2 = eq2;
show(prob)
x0.x = [0 0];
[sol,fval,exitflag] = solve(prob,x0);
disp(sol.x);
disp(sol.x);
% Solve in iteration
for a=[5 6 7 8 9 10]
eq1 = exp(-exp(-(x(1) + x(2)))) == a*x(2)*(1 + x(1)^2); % Variabel "a" is used in the example equation
eq2 = x(1)*cos(x(2)) + x(2)*sin(x(1)) == 1/2;
prob = eqnproblem;
prob.Equations.eq1 = eq1;
prob.Equations.eq2 = eq2;
[sol,fval,exitflag] = solve(prob,sol);
disp(sol.x);
end

Weitere Antworten (0)

Kategorien

Mehr zu Problem-Based Optimization Setup 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