MATLAB Answers

Implementing Runge kutta method in place of ode45

3 views (last 30 days)
Bathala Teja
Bathala Teja on 14 Sep 2021
Answered: Bjorn Gustavsson on 14 Sep 2021
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;
% plot
plot(sol.x,sol.y(i,:));
function dydt = scriptname(t,y,A,B,C)
Wr = 2*pi*50;
p =2;
% evaluation of C (numerical) with theta = y(27)
Cn = double(subs(C,y(27)));
for i=1:25
I(i,1)=y(i);
end
T1=1/2*p*I'*Cn*I
if t<0.5
T2=0;
else
T2=7.31;
end
V=[cos(Wr*t);
cos(Wr*t+2.*pi/3.);
cos(Wr*t-2.*pi/3.);
zeros(21, 1);
0;
(T1-T2);
y(26)]
% 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);
end
How to implement rk method in this???
  2 Comments
Bathala Teja
Bathala Teja on 14 Sep 2021
i pinned you with my entire script in another question please look into that.

Sign in to comment.

Answers (1)

Bjorn Gustavsson
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?

Products


Release

R2021a

Community Treasure Hunt

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

Start Hunting!