Why is fsolve not changing input vector during iterations?

8 views (last 30 days)
I'm soling a non-square system of non-linear equations using fsolve, so it is defaulting to 'levenberg-marquardt' algorithm. My function has an input vector and a single scalar output. During each iteration the solver calls my function n number of times, where n is the length of my vector + 1. I would expect it to change the input vector during each call, but it appears to be plugging in the same input vector. I do not understand why it is doing that. I assume it would converge quicker if it changed the input vector during each iteration, but instead it only changes it between each iteration.
Is there something I can do so it only calls the function once during each iteration? Or at least get it to change the input vector during iteration?
  1 Comment
Matt J
Matt J on 24 Jan 2015
My function has an input vector and a single scalar output.
Meaning, you have 1 equation and multiple unknowns? If so, you probably should expect difficulties in convergence and, of course, quite unpredictable results...

Sign in to comment.

Answers (1)

Matt J
Matt J on 24 Jan 2015
Edited: Matt J on 24 Jan 2015
It is doing that as part of the Jacobian calculation, which by default fsolve approximates using finite differences. It is not plugging in the same vector every time. It is making small finite difference increments to each component of the vector which you possibly cannot see because you are only displaying the vector to a limited number of decimal places.
If the analytical calculation of the Jacobian is tractable, you can supply your own calculation using the 'Jacobian' option. That would reduce the number of function evaluations per iteration and also give more accurate results.
  2 Comments
Matt M
Matt M on 24 Jan 2015
Would the Jacobian be a vector of the same length that would have values of the change that should be made in the next iteration?
Matt J
Matt J on 24 Jan 2015
Edited: Matt J on 24 Jan 2015
The Jacobian is the matrix of partial derivatives of your function, see for example,
However, I would worry first about my comment here.

Sign in to comment.

Categories

Find more on Systems of Nonlinear Equations in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!