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

Consider the IVPs dy d-109) asisb, va) d12yostsi, s(O)1 1. Write a Matlab functi

ID: 2313094 • Letter: C

Question

Consider the IVPs dy d-109) asisb, va) d12yostsi, s(O)1 1. Write a Matlab function called RK2 that solve(1) using Order 2 Runge-Kutta method. Use this method to solve the IVP (2) with N-20,50, 100. Call y0, yl, y2, the three results and plot the three solutions on the same graph. Make a loglog plot of absolute error at 1 versus the number of intervals for all three methods on the same plot. Compare the solution at t 1 with the exact solution at t 1 Create Err a vector that stores the absolute error of the three solutions at t 1, Comment on the result (is the method converging or not, etc.) using %. 2. Write a Matlab function called RK4 that solve (1) using Order 4 Runge-Kutta method. Use this method to solve the IVP (2) with N- 20,50, 100. Call y3, y4, y5, the three results and plot the three solutions on the same graph. Make a loglog plot of absolute error at t 1 versus the number of intervals for all three methods on the same plot. Compare the solution at t 1 with the exact solution at t = 1 Create Erri a vector that stores the absolute error of the three solutions at t = 1, Comment on the result (is the method converging or not, etc.) using %. 3. Write a Matlab function called AB4 that solve (1) using four-step Adams-Bashforth method. You may use your textbook to get the coefficients. Use this method to solve the IVP (2) with N20,50, 100. Call y6, y7, y8, the three results and plot the three solutions on the same graph. Notice: be careful on how to evaluate the first steps Make a loglog plot of absolute error at 1 versus the number of intervals for all three methods on the same plot. Compare the solution at t 1 with the exact solution at t 1. Create Err2 a vector that stores the absolute error of the three solutions at t = 1, Comment on the result (is the method converging or not, etc.) using 4. Write a Matlab function called AM4 that solve (1) using four-step Adams-Moulton method. You may use your textbook to get the coefficients. Cody Coursework now recognizes the function syms and solve. Use this method to solve the IVP (2) with N- 10,20,50. Call y9, y10, yll, the three results and plot the three solutions on the same graph. Notice: be careful on how to evaluate the first steps ! Make a loglog plot of absolute error at t1 versus the number of intervals for all three methods on the same plot. Compare the solution at t 1 with the exact solution at t 1-Create Err3 a vector that stores the absolute error of the three solutions at t 1, Comment on the result (is the method converging or not, etc.) using .

Explanation / Answer

Save the following code in Matlab and get the results-

clc

clear

close all;

syms x y

% Range of x

xspan=[2,3];

% Step size

h=0.1;

% Initial values

y0=3;

x0=2;

y(1)=y0;

x(1)=x0;

% No. of steps

steps=(xspan(2)-xspan(1))/h;

%% Define f(x,y)

f= @(x,y)x*(y-x);

%% Exact Solution

[Xe,Yexact]=ode45(f,xspan,y0);

Xe=Xe(1:4:end);

Yexact=Yexact(1:4:end);

Exact_Sol=vpa([Xe Yexact],5);

%% Adam-Bashworth predictor

for k=5:steps+1

   x(k,1)=x(k-1)+h;

  

   y(k,1)=y(k-1) +(h/24)*( -9*f(x(k-4),y(k-4)) +37*f(x(k-3),y(k-3))...

                       -59*f(x(k-2),y(k-2)) +55*f(x(k-1),y(k-1)));

end

p=y;

Adam_Bashworth=vpa([x p],5);

% Mean Square Error

mse = vpa(norm(Yexact-y,2),5);

%% Adam-Moulton corrector

for k=5:steps+1

   x(k,1)=x(k-1)+h;

  

   y(k,1)=y(k-1) +(h/24)*( f(x(k-3),y(k-3)) -5*f(x(k-2),y(k-2))...

                       +19*f(x(k-1),y(k-1)) +9*f(x(k),p(k)));

end

Adam_Moulton=vpa([x y],5);

% Mean Square Error

mse = vpa(norm(Yexact-y,2),5);

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