Clear Filters
Clear Filters

多変数関数の条件付き極致について

6 views (last 30 days)
mizuguti
mizuguti on 9 May 2024
Answered: Akira Agata on 10 May 2024
z=x*y*cos(x^2+y^2)という多変数関数が、x^2+y^2<(pi/2),x>0,y>0という条件がある時の極大値と極小値の値を表示させる方法がわかりません。

Answers (1)

Akira Agata
Akira Agata on 10 May 2024
たとえば Optimization Toolboxを使って、以下のようにすると極大値を与える x,y を求めることができます(極小値も同様)。
% 最適化問題の作成 (極大値を求める場合)
prob = optimproblem('ObjectiveSense', 'max');
% 制約条件
x = optimvar('x', 'LowerBound', 0);
y = optimvar('y', 'LowerBound', 0);
prob.Constraints = x^2 + y^2 <= pi/2;
% 目的関数
prob.Objective = x*y*cos(x^2 + y^2);
% 初期値を設定
x0.x = 0.1;
x0.y = 0.1;
% 最適化問題を解く
sol = solve(prob, x0);
Solving problem using fmincon. Local minimum found that satisfies the constraints. Optimization completed because the objective function is non-decreasing in feasible directions, to within the value of the optimality tolerance, and constraints are satisfied to within the value of the constraint tolerance.
% 結果を表示
disp(sol)
x: 0.6559 y: 0.6559

Community Treasure Hunt

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

Start Hunting!