Implementing Runge kutta method in place of ode45
6 views (last 30 days)
I want to solve set of 1st order odes, for that i used ode45 function.
But with ode45, it is taking hours and hours of time to compile(i runned for 10 hours but still running no result yet).
So i want to use runge kutta method in place of this ode45, but i dont know how to implement that.
I gave my script below and i skipped some initial lines which contains A, B, C matrices(which are interms of theta) formation for some confidentiality.
% A, B, C matrices formed interms of theta
myfun = @(t,y)scriptname(t,y,A,B,C);
tspan = [0 1];
y0 = zeros(27, 1);
sol = ode45(myfun,tspan,y0);
h = figure;
function dydt = scriptname(t,y,A,B,C)
Wr = 2*pi*50;
% evaluation of C (numerical) with theta = y(27)
Cn = double(subs(C,y(27)));
% evaluation of A and B (numerical) with theta = y(27)
An = double(subs(A,y(27)));
Bn = double(subs(B,y(27)));
dydt = Bn\V-(An*y);
How to implement rk method in this???
Bjorn Gustavsson on 14 Sep 2021
You simply take the RK-scheme that suits your preferences and needs, for example from: Runge-Kutta methods, and plug that into a matlab-function that steps forward from an initial condition for the sufficient number of steps to reach your end-time (1). What part of that are you having problems with?