Codes for R K 4th order simultaneous methods for n ODE
이전 댓글 표시
I want to solve n ODE by using RK 4 simultaneous method. please help me with proper code with example. atleast 4 equations.
댓글 수: 5
Kanishk Singhal
2023년 6월 22일
Have you tried anything yet?
John D'Errico
2023년 6월 22일
Use ODE45. There are examples in the documentation of its use, as well as many other solvers.
If you insist on an explicit Runge-Kutta solve, then you will either need to write it yourself, OR you will need to find it on the File Exchange, where I am sure many students have effectively posted their homework.
ARKA
2023년 6월 22일
tstart = 0.0;
tend = 1.0;
h = 0.01;
T = (tstart:h:tend).';
Y0 = [1 -1];
Y = runge_kutta_RK4(@f,T,Y0);
plot(T,Y)
grid on
function Y = runge_kutta_RK4(f,T,Y0)
N = numel(T);
n = numel(Y0);
Y = zeros(N,n);
Y(1,:) = Y0;
for i = 2:N
t = T(i-1);
y = Y(i-1,:);
h = T(i) - T(i-1);
k0 = f(t,y);
k1 = f(t+0.5*h,y+k0*0.5*h);
k2 = f(t+0.5*h,y+k1*0.5*h);
k3 = f(t+h,y+k2*h);
Y(i,:) = y + h/6*(k0+2*k1+2*k2+k3);
end
end
function dy = f(t,y)
B = 4;
dy = [y(2) -exp(-B*t)-y(1)+5*exp(-2*t)-2*exp(-(B+2)*t)+exp(-B*t)+t];
end
답변 (1개)
Mudit Kumar Bhugari
2023년 6월 22일
0 개 추천
Hi @ARKA
I understand that you want some examples for solving RK 4th Order Simulations. I'm sharing some resources with you which solves RK 4th Order Equations.
- https://in.mathworks.com/matlabcentral/answers/1703455-solving-for-two-variables-using-4th-order-runga-kutta-method
- https://in.mathworks.com/matlabcentral/answers/596755-4th-order-runge-kutta-code-that-can-solve-for-several-intial-conditions
- https://in.mathworks.com/matlabcentral/answers/465218-i-need-to-solve-these-4-equations-by-runge-kutta-4th-order-method-with-graphs
카테고리
도움말 센터 및 File Exchange에서 Ordinary Differential Equations에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
