필터 지우기
필터 지우기

Constraining equilibrium solver to positive values (fsolve, lsqnonlin)

조회 수: 6 (최근 30일)
From my understanding, it's impossible to constrain fsolve to only find positive zeros but that it is possible using lsqnonlin (see this thread: http://www.mathworks.com/matlabcentral/newsreader/view_thread/280353). I see how I can use bound constraints with lsqnonlin to only return positive values, but how do I "minimize the residuals to 0"? Thank you!

채택된 답변

Andrew Newell
Andrew Newell 2011년 5월 17일
Suppose you started with a function myfun(x) that inputs a vector x and outputs a vector, for example:
myfun = @(x) x.^2-1;
x0 = [-1.5 1.5];
x1 = fsolve(myfun,x0)
x1 =
-1.0000 1.0000
To incorporate your constraints, you could do this:
lb = zeros(size(x0)); %lower bound of zero
ub = Inf*ones(size(x0));
x2 = lsqnonlin(myfun,x0,lb,ub)
x2 =
1.0000 1.0000
As John D'Errico implies, the minimization may give you an answer that is not a root, so you then need to check your answer:
myfun(x2)
ans =
1.0e-08 *
0.3056 0.0030
(Note: answer rewritten completely.)

추가 답변 (1개)

John D'Errico
John D'Errico 2011년 5월 17일
There is NO assurance that you can minimize the residuals to zero. What is the root of y=x^2+1, with x restricted to real values?
Just wanting to solve a problem does not mean there will be a solution.

카테고리

Help CenterFile Exchange에서 Solver 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