"Vectorized" fsolve
Mostra commenti meno recenti
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 Commenti
Sean de Wolski
il 8 Giu 2012
How slow is the for-loop and how important is speed?
Keep it simple and stupid.
Matt
il 8 Giu 2012
Risposte (1)
Sargondjani
il 8 Giu 2012
0 voti
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 Commenti
Matt
il 8 Giu 2012
Sargondjani
il 8 Giu 2012
i personally would not try to solve all 2720 equations simultaniously, as solving 16 equations for 16 unknows is already quite intensive... you could try multiple workers though (look up documentation on 'parfor')
however, you should definitely supply the "jacobpattern" for the finite differences for each 16 equations. this will be crucial to improve computation speed
Matt
il 8 Giu 2012
Sargondjani
il 8 Giu 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?
Categorie
Scopri di più su Linear Algebra in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!