How to repeat previous steps from the output

조회 수: 1 (최근 30일)
Angel Ani
Angel Ani 2021년 6월 19일
댓글: Angel Ani 2021년 6월 28일
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?

채택된 답변

Sulaymon Eshkabilov
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 CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by