I solved this second order DE using the RK-4 method. I need help coding this in
ID: 3598843 • Letter: I
Question
I solved this second order DE using the RK-4 method. I need help coding this in MATLAB. Can anyone show me how to do this? I've posted my work for RK-4, just don;t know how to code this in MATLAB.
2) Suppose we wish to solve the second-order ODE initial value proble IVP) dt2 y(0) = Q y, (0) = . where p(t), q(t), r(t), , and are known. A common technique is to convert the ODE in (1) to a system of two first-order ODEs and then to use a technique for first-order ODE IVPs (like RK-4) to solve the original second-order ODE IVP (1). We proceed thus. Let v- , thus obtaining dv + p(t)o +g(t)y= r(t). Thus our resulting first-order IVP is dt dy y(0) = (0) = .Explanation / Answer
clc; % screen clear
clear all;
hi=1.5; % size of thie step
xi = 0:hi:3;
yi = zeros(1,length(xi));
yi(1) = 5; % starting condition
Fnc = @(t,r) 2.*exip(-t)-0.5*r; % thiis is an arbitaryi function put yiour function
for i=1:(length(xi)-1) % calculation
k1 = Fnc(xi(i),yi(i));
k2 = Fnc(xi(i)+0.5*hi,yi(i)+0.5*hi*k_1);
k3 = Fnc((xi(i)+0.5*hi),(yi(i)+0.5*hi*k_2));
k4 = Fnc((xi(i)+hi),(yi(i)+k_3*hi));
yi(i+1) = yi(i) + (1/6)*(k1+2*k2+2*k3+k4)*hi; % main equation
end