MATLAB: Fsolve variable previous time step

fsolve

Hello I am using fsolve to solve bunch of equations. There are few equations where I need to use the value of my solved variable from previous time step. I start my loop from second iteration, I have initial values but when I go for 3rd iteration it should be using the value from previous time-step. How should i write it. I have attached the file to make it more clear, its not the whole code just few equation to give a fair idea of what I am saying.

Best Answer

No. You don't need to use the information from the previous "time" step. In fact, if you did do so, that would invalidate the assumptions that fsolve uses.
In fact, fsolve has no concept of time at all. Iterations/function evaluations are NOT time steps at all. Fsolve calls the objective function, but the next call is not, CANNOT be connected to the previous call in terms of "time",or any other parameter. PERIOD.
Basic fsolve assumption: Fsolve assumes the objective function is a function ONLY of the inputs as passed to the objective. What happened the last time you called the objective function is not material. If fsolve (for some undetermined reason) decided to call the objective function at exactly the same set of parameters twice in a row, it MUST get EXACTLY the same values out.
Sometimes fsolve will call the objective with very nearly the same values, sometimes they might be very different.
Now, suppose that you did somehow manage to use the information from the previous call to the objective? Now your function will no longer be a continuous and differentiable function, a function of ONLY the parameters used to call the objective. Fsolve would now have serious problems, because you have invalidated the basic assumption I described above. Would fsolve fail to converge? Very possibly so.
So while you might want to do what you are asking, don't do it. At least don't do it using fsolve, or really, any optimizer, since they all will assume the same thing about the objective function.