I would like to approxiamte and plot the following system of equations: { u' = v ; v' = -4*u' - 5 u} using the Runge Kutta method.
I am able to plot it for the second equation, but having difficulties incorporating the u' = v to reflect the full system.
the exact solution I am comparing to is: x(t) = 3.*exp(-2.*t) .* cos(t) + exp(-2.*t) .* sin(t) corresponding to equation: ??′′(??)+4??′(??)+5??(??)=0 with ??(0)=3 and ??′(0)=−5. as initial conditions.
clear all
close all
clc
h = .1;
x = 0:h:5;
y = zeros(1,length(x));
y(1) = 3;
n = length(x)-1;
y_dot =@(x,y)(-4*x-5*y);
for i = 1:n
k1 = y_dot(x(i),y(i));
k2 = y_dot(x(i)+.5*h,y(i)+.5*k1*h);
k3 = y_dot(x(i)+.5*h,y(i)+.5*k2*h);
k4 = y_dot(x(i)+h,y(i)+k3*h);
y(i+1) = y(i)+((k1+2*k2+2*k3+k4)/6)*h;
end
Please explain the any updates yu make, since I am new to ML and need to conceptually understand the fundamentals.
Thanks.
3 Comments
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/492904-runge-kutta-for-system-of-eqs#comment_771299
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/492904-runge-kutta-for-system-of-eqs#comment_771299
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/492904-runge-kutta-for-system-of-eqs#comment_771349
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/492904-runge-kutta-for-system-of-eqs#comment_771349
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/492904-runge-kutta-for-system-of-eqs#comment_771351
Direct link to this comment
https://fr.mathworks.com/matlabcentral/answers/492904-runge-kutta-for-system-of-eqs#comment_771351
Sign in to comment.