I am solving an ODE very often, so efficiency is important. The ODE I am solving calls other functions, because the ode is very general, but the details depend on the problem.
What I am doing now is this ( not working code, but the relevant snippets)
h_dydt = @(t,y)f_dydt(t,y,params,h1);
solution = ode45(h_dydt,...
Where the ode function is
function [dydt] = f_dydt(t,y,params,h)
The problem is, that aproach 2) takes 60% more time than aproach 1), and I wonder if there is a way to have the same flexibility without the huge added cost. As it is now, I have to do aproach 1) and write a separate dydt function for each problem.
Thanks for looking into this!