RK4 2nd order ODE | Numerical Methods | LetThereBeMath |

preview_player
Показать описание
In this video we apply RK4 to the solution of a 2nd order ODE and compare it to the exact solution.
Рекомендации по теме
Комментарии
Автор

Since you did not take any shortcuts, I could understand the whole thing... very good!

euclidesdacunha
Автор

God bless you my friend, very practical and transparent programming. Thank you!

josemontano
Автор

Very understandable, would you upload Matlab code!, I think the K4x, its second term is xi, not vi

knighttime
Автор

Great discussion. I implemented this to solve VIV problems in my CFDFOAM

kamaukingora
Автор

thank you so much bro, in french we say "t'es un bon"

emilehomerin
Автор

Excellent explanation!!
Helped me out with the 2D equations of motion for a planet and a sun.

hergestron
Автор

Excellent video, thank you very much!

joaovict
Автор

For the viewers i've typed all the code.. as it is useful to my project also.. pls enjoy

clear all; clc; close all;
dt=0.1;
k=1;
m=1;
x0=3;
v0=0;
t=0:dt:100;

%exact solution
x_exact = x0*cos(sqrt(k/m)*t);
v_exact =

%RK
f1 = @(t, x, v) v;
f2 = @(t, x, v) -k/m*x;
h=dt;

x = zeros(length(t), 1);
v = zeros(length(t), 1);
x(1) = x0;
v(1) = v0;

for i=1:(length(t)-1) % calculation loop
k1q = f1(t(i), x(i), v(i));
k1x = f2(t(i), x(i), v(i));
k2q = f1(t(i)+0.5*h, x(i)+0.5*h*k1q, v(i)+0.5*h*k1x);
k2x = f2(t(i)+0.5*h, x(i)+0.5*h*k1q, v(i)+0.5*h*k1x);
k3q = f1((t(i)+0.5*h), (x(i)+0.5*h*k2q), (v(i)+0.5*h*k2x));
k3x = f2((t(i)+0.5*h), (x(i)+0.5*h*k2q), (v(i)+0.5*h*k2x));
k4q = f1((t(i)+h), (x(i)+k3q*h), (v(i)+k3x*h)); % Corrected
k4x = f2((t(i)+h), (x(i)+k3q*h), (v(i)+k3x*h));

x(i+1) = x(i) + % main equation
v(i+1) = v(i) + % main equation

end
%plots
subplot(121);
plot(t, x_exact, 'b', t, x, 'r');
legend('EXACT', 'RK4');
xlabel('Time(s)');
ylabel('Displacement (m)');
title('Displacement');

subplot(122);
plot(t, v_exact, 'b', t, v, 'r');
legend('Exact', 'RK4');
xlabel('Time (s)');
ylabel('Velocity (m/s)');
title('Velcoiy');

krishnakadiyam
Автор

Thank you for the video. we consider RK4 as 4th order and Euler as 1st order, (based on Taylors) when implying codes for programming, RK4 is much more complex than Euler, however if we decrease the iteration interval 4 times, the result would be the same. I mean Euler with h=10e-4 is exactly the same as RK4 with h=1.0 Am I right?

vatanema
Автор

It is just what i needed. THANK YOU!! But still my analytical solution does not match with the RK4 solution maybe my analytical solution is wrong because i did everything same :(

canaslan
Автор

How to solve when you have a Neumann Boundary Condition?

abdulbasithashraf
Автор

sir, can you please show an example how to solve 3coupled equations using rk4?

krishnakadiyam
Автор

Can u make a video about second order bvp finite diff method, pls ?

osamayakop
Автор

hello. What if you have 2 (coupled) 2nd-order ODEs? Would you have to simplify it into 4 1st-order ODEs?

kovanovsky
Автор

I tried using the RK4 and Euler Methods side by side and it looks like the Rung Kutta method is vastly superior.

someone
Автор

Hey
any chance to upload a movie to show how to solve a 2nd Order ODE by Taylor 4th rank?
i have a big problem in Taylor 4th second order ODE solution

mn