How to repeat previous steps from the output
4 ビュー (過去 30 日間)
古いコメントを表示
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 件のコメント
採用された回答
Sulaymon Eshkabilov
2021 年 6 月 19 日
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
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Problem-Based Optimization Setup についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!