How to repeat previous steps from the output
5 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
Angel Ani
le 19 Juin 2021
Commenté : Angel Ani
le 28 Juin 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?
0 commentaires
Réponse acceptée
Sulaymon Eshkabilov
le 19 Juin 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
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Problem-Based Optimization Setup dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!