Hello,
I am using fsolve within fsolve. That is, for each iteration of the outer fsolve loop, matlab solves the inner fsolve problem.
Is there a possibility to use the previous guess for the inner fsolve problem. I tried the following
function F = solvep(p,x0,par)
% some calculations
x = fsolve(@(x) solvex(x,par2),x0);
x0 = x;
% some more calculations
F = p*x - 1;
end
But for some reason, matlab does not update x0. That is, x0 is always set to x0 as given in the first line. I hope to speed up the procedure a bit by using the previous guess because most of the time, the changes in p that matlab considers are quite minor.
Thanks!

댓글 수: 1

Matt J
Matt J 2022년 5월 15일
In your code, the sub-problem and its solution x does not appear to depend on p. Therefore, you should probably just pre-compute it.

댓글을 달려면 로그인하십시오.

 채택된 답변

Matt J
Matt J 2022년 5월 15일

0 개 추천

function F = solvep(p,x0,par)
persistent X0
if isempty(X0), X0=x0; end
% some calculations
x = fsolve(@(x) solvex(x,par),X0);
X0 = x;
% some more calculations
F = p*x - 1;
end

추가 답변 (1개)

Walter Roberson
Walter Roberson 2022년 5월 15일

0 개 추천

Have solvep() return x0 as well, and update the appropriate variable in the calling function.
Or you could back-calculate what x would have to be in order to produce the given F.
Both possibilities imply using a real function for the outer layer instead of an anonymous function. Values bound into an anonymous function cannot be changed by using techniques such as assignin()

카테고리

도움말 센터 및 File Exchange에서 Systems of Nonlinear Equations에 대해 자세히 알아보기

태그

질문:

2022년 5월 15일

댓글:

2022년 5월 15일

Community Treasure Hunt

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

Start Hunting!

Translated by