Main Content

制約のある非線形方程式系、問題ベース

この例では、問題ベースのアプローチを使用して、制約のある非線形方程式系を解こうとする方法を示します。

範囲制約

問題に範囲制約のみがある場合、問題を解くプロセスは単純です。たとえば、次の方程式系の正の成分をもつ解を求めるとします。

(x1+1)(10-x1)1+x221+x22+x2=0(x2+2)(20-x2)1+x121+x12+x1=0,

この場合、下限を 0 とする最適化変数を作成するだけです (これらの方程式には、x1=-1 または x1=10 の場合、および x2=-2 または x2=20 の場合の 4 つの解があります)。

x = optimvar('x',2,"LowerBound",0);
expr1 = (x(1) + 1)*(10 - x(1))*((1 + x(2)^2))/(1 + x(2)^2 + x(2));
expr2 = (x(2) + 2)*(20 - x(2))*((1 + x(1)^2))/(1 + x(1)^2 + x(1));
eqn1 = expr1 == 0;
eqn2 = expr2 == 0;
prob = eqnproblem;
prob.Equations.eqn1 = eqn1;
prob.Equations.eqn2 = eqn2;
x0.x = [15,15];
[sol,fval,exitflag] = solve(prob,x0)
Equation problem has bound constraints. Reformulating as a least squares problem.

Solving problem using lsqnonlin.

Equation solved.

lsqnonlin completed because the vector of function values is near zero
as measured by the value of the function tolerance, and
the problem appears regular as measured by the gradient.
sol = struct with fields:
    x: [2x1 double]

fval = struct with fields:
    eqn1: 0
    eqn2: 0

exitflag = 
    EquationSolved

解を表示します。

sol.x
ans = 2×1

    10
    20

一般的制約

問題に一般的制約がある場合、方程式問題ではなく最適化問題として、問題を定式化します。方程式は等式制約として設定します。たとえば、非線形不等式制約 x210 を条件として前述の方程式を解くには、x の範囲を削除し、目的関数のない最適化問題として問題を定式化します。

x.LowerBound = [];
circlecons = x(1)^2 + x(2)^2 <= 10;
prob2 = optimproblem;
prob2.Constraints.circlecons = circlecons;
prob2.Constraints.eqn1 = eqn1;
prob2.Constraints.eqn2 = eqn2;
[sol2,fval2,exitflag2] = solve(prob2,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.
sol2 = struct with fields:
    x: [2x1 double]

fval2 = 0
exitflag2 = 
    OptimalSolution

解を表示します。

sol2.x
ans = 2×1

   -1.0000
   -2.0000

最小二乗法の目的を使用した一般的制約

目的関数を二乗和として設定し、制約として一般的制約を設定することで、問題を定式化することもできます。この別の定式化を行うと、数学的には等価な問題になりますが、異なる解が得られることがあります。定式化が変わると、ソルバーでの反復回数が変わるからです。

prob3 = optimproblem;
prob3.Objective = expr1^2 + expr2^2;
prob3.Constraints.circlecons = circlecons;
[sol3,fval3,exitflag3] = solve(prob3,x0)
Solving problem using lsqnonlin.

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.
sol3 = struct with fields:
    x: [2x1 double]

fval3 = 8.5058e-16
exitflag3 = 
    OptimalSolution

解を表示します。

sol3.x
ans = 2×1

   -1.0000
   -2.0000

この場合、最小二乗法の目的によって、制約しか使用していない先ほどの定式化と同じ解が得られます。

制約のある方程式の求解の詳細

一般的に、solve は、方程式要素の二乗和を最小にすることにより非線形方程式系を解こうとします。つまり、LHS(i) が方程式 i の左辺の式であり、RHS(i) が右辺の式である場合、solvesum((LHS RHS).^2) を最小化しようとします。

これに対し、非線形制約式を満たそうとする場合、solve は一般的に fmincon を使用し、別の方法で制約を満たそうとします。

どちらの場合も、ソルバーは方程式の求解に失敗する可能性があります。ソルバーが失敗した際に、求解を試みるために使用できる方法については、fsolve が方程式を解けないを参照してください。

参考

関連するトピック