Predifine desired ODE slover (e.g. ode45) using a string ('ode45') or something similar?

1 view (last 30 days)
Hi, I would like to define in my matlab code which ODE solver to use (e.g. ODE45, ODE15s, etc) before I actually use it and I am wondering whether there is a way to do so, e.g. using its name as a string? Please see the following toy example to understand what I mean. Thank you in advance.
function test options = odeset('RelTol',1e-4,'AbsTol',[1e-4 1e-4 1e-5]);
ode_solver='ode45';
[T,Y] = ode45(@rigid,[0 12],[0 1 1],options);
%% Instead of the above line I would like to use something like:
%%[T,Y] = ode_solver(@rigid2,[0 12],[0 1 1],options);
plot(T,Y(:,1),'-',T,Y(:,2),'-.',T,Y(:,3),'.')
function dy = rigid(t,y) dy = zeros(3,1); % a column vector dy(1) = y(2) * y(3); dy(2) = -y(1) * y(3); dy(3) = -0.51 * y(1) * y(2);
end
end

Answers (0)

Community Treasure Hunt

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

Start Hunting!