質問

Feel free to close this if I'm not understanding fminsearch or just butchering the lingo, but here's my question.

Can I use fminsearch with a constraint on multiple parameters together?

fminsearch(@(x) func(x(1), x(2)), [2,2], such that x(1) * x(2) = 4 or something like that)
役に立ちましたか?

解決

Nonlinear optimization is a very difficult problem, so no method is guaranteed to work for every case. For your case, you can solve x(2) analytically from x(1). So you can make it into an unconstrained optimization problem.

func_cstr = @(x) func(x, 4/x);
fminsearch(func_cstr, initial_x1)

If you cant make an explicit relationship between x(1) and x(2), then you can try a penalty method:

pen = 1e5;
constraint = @(x) (x(1)*x(2)-4)
func_cstr = @(x) func(x)+pen*constraint(x)^2;
[x,fval] = fminsearch(func_cstr, initial_x1_and_x2);

There is also a constrained optimization solver fmincon provided by MATLAB.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top