fmincon()を使う
jp.mathworks.com
@nonlconの「@」がキモ
clear; close all; f = @(x) x(1)^2+x(2)^2; A = []; b = []; Aeq = []; beq = []; x0 = [0,0]; lb = []; ub = []; fmincon(f, x0, A, b, Aeq, beq, lb, ub, @nonlcon) function [c,ceq] = nonlcon(x) x1 = x(1); x2 = x(2); c = [x1^2/20-x2+1,-x1+x2^2/20+1]; ceq = []; end
実行結果
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. <stopping criteria details> ans = 1.0557 1.0557 >>
あっている