How can i obtain the final value of x and y?
3 ビュー (過去 30 日間)
古いコメントを表示
How can i obtain the final value of x and y. both of x and y are variables? I am looking to get the final value (optimal values of x and y). The matlab workspace gives me like this below:
![](https://www.mathworks.com/matlabcentral/answers/uploaded_files/537401/image.png)
close all;
clear all;
clc
x = optimvar('x',1,'LowerBound',0,'UpperBound',10);
y = optimvar('y',1,'LowerBound',0,'UpperBound',10);
prob = optimproblem;
prob.Objective = x.^2 + y;
prob.Constraints.cons1= x >= 0;
prob.Constraints.cons2= x <= 10;
prob.Constraints.cons3= y <= 10;
prob.Constraints.cons4= x-y >= -10;
prob.ObjectiveSense = 'min';
options.Display = 'iter';
options = optimoptions(prob,'Algorithm','active-set')
0 件のコメント
採用された回答
J Chen
2021 年 3 月 3 日
Use sol = solve(prob) to solve the problem. The answer is in the sol object. You can also use sol.x and sol.y. Note that you may need to change the alogorithm to 'trust-region-reflective' or 'interior-point-convex'. The 'active-set' may have been removed.
0 件のコメント
その他の回答 (0 件)
参考
カテゴリ
Help Center および File Exchange で Get Started with Optimization Toolbox についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!