how to add a constraint condition to fsolve?

100 ビュー (過去 30 日間)
Stanley Cheng
Stanley Cheng 2013 年 11 月 19 日
編集済み: Matt J 2013 年 12 月 8 日
Hi everyone,
These days I want to solve a system of nonlinear equations with matlab. In the equations, there are all four unkonwns, A(1),A(2),A(3)and A(4) to be solved but only three equations. therefore, the 'levenberg-marquardt' algorithm is applied to get the results. However, for physical meaning, an additional constraint is required, i.e. A(3)should be larger than zero. and with the 'levenberg-marquardt' algorithm, in the the obtained result, A(3) is negative.
Does anyone know how to add this constraint condition to fsolve ? Your help will be highly appreciated!

採用された回答

John D'Errico
John D'Errico 2013 年 11 月 19 日
While Sean is correct in his answer, there is a trick that ail make it trivial to solve using solve for simple constraints like this.
If A(3) MUST be positive, then in your objective function, square whatever number is passed in and use that in your calculations. The square of a number will always be positive, so in effect we have implemented an inequality constraint.
For the starting value for A(3), pass in the sqrt of what ever value you would have passed in otherwise.
And finally, when the result is returned, square A(3) to get the value used in the computation.
This transformation trick is a nice one, but one that seems to be forgotten too easily.
  3 件のコメント
John D'Errico
John D'Errico 2013 年 11 月 20 日
Matt, there can always be conditioning issues. Optimization is an art, that is best done when you use the available tools to best effect, while watching for problems. As well, if you are careful and understand the methods involved, you can always construct a problem that will cause failure for any numerical method that works on a black box.
The point is, use the tools you have, but do so carefully. If it succeeds, as the advice I have offered will do most of the time, then it has solved the problem simply and at the cost of little additional effort. When that advice fails, then look to see if you have stumbled on a singularity, and if necessary, look for a different tool.
Matt J
Matt J 2013 年 12 月 8 日
編集済み: Matt J 2013 年 12 月 8 日
One other thing to be careful of with this method is to avoid choosing A(3)=0 as the initial guess. The gradient of the objective function F(x) will always be zero at x=0 after making the transformation F(x^2), e.g.,
>> fsolve(@(x)1-x,0,optimset('Display','none'))
ans =
1
versus
>> fsolve(@(x)1-x^2,0,optimset('Display','none'))
ans =
0
versus
>> fsolve(@(x)1-x^2,0.5,optimset('Display','none'))
ans =
1.0000

サインインしてコメントする。

その他の回答 (3 件)

Sean de Wolski
Sean de Wolski 2013 年 11 月 19 日
fsolve does not provide the ability to use constraints. You'll need fmincon for this.

Matt J
Matt J 2013 年 11 月 19 日
編集済み: Matt J 2013 年 11 月 19 日
However, for physical meaning, an additional constraint is required, i.e. A(3)should be larger than zero.
If your constraints are simply non-negativity and bound constraints, you should probably use lsqnonlin. lsqnonlin is a bit more specialized than fmincon, and there may be advantages to that.
lsqnonlin is also set up to take exactly the same objective function format as fsolve, whereas fmincon doesn't.

Alan Weiss
Alan Weiss 2013 年 11 月 20 日
Alan Weiss
MATLAB mathematical toolbox documentation

カテゴリ

Help Center および File ExchangeSolver Outputs and Iterative Display についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by