[Solved] Solve a large number of independent nonlinear equations with fsolve without loops
4 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am running a large number of simulations and for each simulation I need to solve a single nonlinear equation. I have found that my code is significantly faster if I avoid loops as much as possible. Each simulation produces a M×N matrix, and instead of looping K times for K simulations, I simply produce a M×NK matrix.
The one area where I've been having trouble avoiding loops is with solving the nonlinear equation for each simulation. For small K (around 1000) it's faster to simply do fsolve with K nonlinear equations than to do K loops of fsolve with a single nonlinear equation. With K larger than that, however, it becomes impossible to do this, as it becomes slower than loops and requires too much memory.
I understand the problem is that fsolve thinks that it's solving a system of K equations, and doesn't realize that the solution to each equation is independent from the other. I don't know how to solve my problem however, and "tell" fsolve that the solution to each equation is independent and that I actually want to solve K systems of a single equation rather than a single system of K equations.
Does anybody know if there is a solution to this problem, or is the only option to use loops?
--EDIT-- Solution ended up being very simple. Provide information on the structure of the Jacobian using 'JacobPattern' (diagonal matrix) and use the 'trust-region-reflective' algorithm.
0 comentarios
Respuestas (0)
Ver también
Categorías
Más información sobre Numerical Integration and Differential Equations en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!