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

Write separate MATLAB functions for solving the first order IVP y\'(t) = f(t,y),

ID: 3401811 • Letter: W

Question

Write separate MATLAB functions for solving the first order IVP y'(t) = f(t,y), a lessthanorequalto t lessthanorequalto b y(a) = a using Euler's Method Fourth-Order Runge-Kutta method Verify that both codes work by using them to solve the following two problems. IVP1: y' = y, y(0) = 1, t [0, 10]. Exact Solution : y(t) = e^t IVP2: y' = t/y, y(0) = 1, t [0, 10], Exact Solution : y(t) = squareroot 1+t^2 by setting the step size to h = = 10/n and test your code with n=50, 100, 200, 400, 8000, 1600, 3200. Turn in a table for each method on each initial value problem specifying the various h values and the error.

Explanation / Answer

% For IVP1 y' = y; f(t,y)=y; Vary N = 50 , 100 , 200 etc as specified in question.

a=0; % Initial time

b=10; % Final time

N=50; % Number of time steps

y0=1; % Initial value

y(a) h=(b-a)/N; % Time step

t(1)=a;

y(1)=y0;

for n=1:N % For loop, sets next t,y values

t(n+1)=t(n)+h;

y(n+1)=y(n)+h*y(n); % Calls the functionf(t,y)=dy/dt

end

plot(t,y)

% For IVP2 y' = t/y; f(t,y)=y; Vary N = 50 , 100 , 200 etc as specified in question.

a=0; % Initial time

b=10; % Final time

N=50; % Number of time steps

y0=1; % Initial value

y(a) h=(b-a)/N; % Time step

t(1)=a;

y(1)=y0;

for n=1:N % For loop, sets next t,y values

t(n+1)=t(n)+h;

y(n+1)=y(n)+h*t(n)/y(n); % Calls the functionf(t,y)=dy/dt

end

plot(t,y)

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote