필터 지우기
필터 지우기

how to add a constraint condition to fsolve?

조회 수: 50 (최근 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 CenterFile Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by