Updating endogenous variables during fsolve iterations

Is it possible to update solution-dependent parameters passed as constants in the objective function handle?
For a square system of nonlinear equations, where
  • fun(x,a,b,c) is the objective function;
  • x is the problem variable, which needs to be guessed by the solver;
  • a = ƒ(x), is one of the objective function input variables, x-dependent;
The code for solving the problem, if a wasn't x-dependent, would be:
x = fsolve(@(x) fun(x,a,b,c),x0,options);
But this fixes the value for a at the moment of the creation of the anonymous function handle, while it should be computed inside fun to be updated in each solver iteration.
Is it possible to get a as an output from fun and pass it to fun itself in the next fsolve iteration?

 채택된 답변

John D'Errico
John D'Errico 2015년 9월 9일

0 개 추천

Even if you COULD do so, you would not want to do so!
You would then be using the prior value for x to determine a, so your function would be out of step. The current value of x and a would be inconsistent.
If a depends on x, then compute it inside the function, AS A FUNCTION OF x. Why try to pass it in?

댓글 수: 4

Yes right, I'm trying to pass it in because calculation of a(x) is iterative inside the objective function, so I thought the code would be faster that way
Well, the code will be even faster if you just fix a at some value. Personally, I like 17. It won't give you the correct result, but it will be faster.
My point is, if a is a function of x, then you MUST compute it for every value of x.
I know it’s been a while since you answered, but maybe you’ll see this.
So as long as the values dependent on the initial guess of fsolve are computed inside the function fed to fsolve, they will update properly as fsolve iterates?
@Samuel Nabarrette Did you find the answer to the question you have posted?

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

추가 답변 (0개)

카테고리

도움말 센터File 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