Implementing Runge kutta method in place of ode45

조회 수: 8 (최근 30일)
Bathala Teja
Bathala Teja 2021년 9월 14일
답변: Bjorn Gustavsson 2021년 9월 14일
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
Jan
Jan 2021년 9월 14일
Please avoid to ask multiple questions about the same problem.
ODE45 is a very efficient Runge-Kutta integrator. Writing your own solver will not be faster. The actual problem is still hidden in the part of the code, you do not post: What is A, B, C? I understand, that these formulas might be "confidential", but the core of the problem can be found there, so a discussion without the important detail is meaningless.
Is the problem stiff? Did you try to use a stiff solver already?
Bathala Teja
Bathala Teja 2021년 9월 14일
i pinned you with my entire script in another question please look into that.

댓글을 달려면 로그인하십시오.

답변 (1개)

Bjorn Gustavsson
Bjorn Gustavsson 2021년 9월 14일
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?

제품


릴리스

R2021a

Community Treasure Hunt

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

Start Hunting!

Translated by