"Vectorized" fsolve
6 views (last 30 days)
Show older comments
Hi,
I have a system of about 16 or so nonlinear equations that I would like to solve with fsolve. These equations contain two parameters, beta and delta, that I would like to vary and find the solution to the equations for each combination of these parameters. There are somewhere around 170 combinations of beta and delta(possibly more, depending on whether I need better resolution or not).
To be more clear, I want to make a carpet plot(same idea as the picture here http://www.vikingaero.com/images/range_carpet_plot.png ) of the variables in the nonlinear equations versus beta and delta. In the picture, delta C sub D0 and delta W sub T0 would be beta and delta and R would be one of the variables that I'd be solving for in the non linear equations.
Is there any way that I can "vectorize" with fsolve, or do I have to loop through all my beta and delta combinations and call fsolve for each combination?
2 Comments
Sean de Wolski
on 8 Jun 2012
How slow is the for-loop and how important is speed?
Keep it simple and stupid.
Answers (1)
Sargondjani
on 8 Jun 2012
first of all, if you loop through R and use the solution of the last loop as starting value, that will already help quite abit (less iterations needed compared to using same starting values)
but you could do without the loop by just specifiying alll 170 equations + 2 x 170 input variables and solve simultaniously. For speed you absolutely need to let matlab know that all equations are independent, so you have to either set the JacobPattern (for finite difference, otherwise it will take ages) or supply the analytical jacobian.
let us know if you have problems settings the JacobPattern (post some of your code)
4 Comments
Sargondjani
on 8 Jun 2012
yes fsolve does automatically compute the jacobian. however it assumes that it is a full matrix, which it will not be unless all 16 unknowns show up in every equation. and since you can know in advance which values in the jacobian will be zero, you should provide the zeros otherwise matlab will try to estimate them (use sparse matrix)....
for example IF all your equations would be independent you would just have to calculate the diagonal of your jacobian, instead of a full 16x16 matrix. see the point?
See Also
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!