Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Consider the Runge-Kutta method for solving the ODE dy/dx = f(x, y) x_n + 1 = x_

ID: 3111354 • Letter: C

Question

Consider the Runge-Kutta method for solving the ODE dy/dx = f(x, y) x_n + 1 = x_n + h k_1 = f(x_n, y_n) k_2 = f(x_n + h/2, y_n + hk_1/2) k_3 = f(x_n + h/2, y_n + hk_2/2) k_4 = f(x_n + 1, y_n + hk_3) y_n + 1 = y_n + h/6 (k_1 + 2k_2 + 2k_3 + k_4). Write a MATLAB program to implement this algorithm. Test your code by solving the initial value problem dy/dx = 1/3 y(8 - y) y(0) = 1 on the interval 0 lessthanorequalto x lessthanorequalto 5 with N = 50 grid points. Find the exact solution of the given IVP and plot it together with the approximate solution calculated using your code. Email the MATLAB code and figure to the TA.

Explanation / Answer

clc

clear all

x0=0;

x=5;

n=50; %% number of nodes

h=(x-x0)/n; %% step size

i=1;

y(1)=1;

while i<=n

k1=y(i)*(8+y(i))/3;

k2=(y(i)+(h*k1/2))*((8-y(i)-(h*k1/2)));

k3=(y(i)+(h*k2/2))*((8-y(i)-(h*k2/2)));

k4=(y(i)+(h*k3))*((8-y(i)-(h*k3)));

y(i+1)=y(i)+(k1+k2+k3+k4)/6;

end

y=[y']

t=x0:h:x

plot(t,y)

I am sorry I dont have MATLAB software in my laptop, so that i could not run, and upload plot,

Its 100% correct solution and run in your computer you will definitely got plot. and let me know if you have any doubts, or errors in that through your comments.