Pl ease find the separate attachment for spreadsheet templates or you can make y
ID: 3184769 • Letter: P
Question
Pl ease find the separate attachment for spreadsheet templates or you can make your own. #5) Given the differential equation, y,3x2 +4), y(1)=2. a.) Use Eulers Method to approximate the value of y(1.5) using h b) Use Euler's Method to approximate the value of y(1.5) using h = 0.1 c) Use Euler's Method to approximate the value of y(1.5) using h=0.05 d) Use Euler's Improved Method to approximate the value of y(1,5) using h =0.5 e.) Use Euler's Improved Method to approximate the value of J'(1.5) using h=0.1 f.) Use Euler's Improved Method to approximate the value of y(1.5) using h = 0.05 g) Use Runge-Kutta Fourth Order Method to approximate the value of y(1.5) using h = 0.5 h) Use Runge-Kutta Fourth Order Method to approximate the value of y(1.5) using h = 0.1 i.) Use Runge-Kutta Fourth Order Method to approximate the value of y(1.5) using h = 0.05 Notes: Problem #5 also serves as Quiz #12. Problem #5 will be graded out of30 points. For Euler's Method, please provide the following columns: n , , +1 For Euler's Improved Method, please provide the following columns: " y For RK-Method, please provide the following columns: n, x. , M Mr M. Twi ). M,,M2·My M4, M. TwiExplanation / Answer
Please find the Matlab script for the problems a,b,c,d,e,f, below. If one want to plot Euler Method plots for h = 0.5, 0.1, 0.05 use the command hold on in first figure and at the end of the third figure for h = 0.05 hus the command hold off so that one can see all the Euler plots in same figure for diferent h vales. Repeat it for modified Euler method also if needed.
Euler Method starts from here
%%for h = 0.5 Euler Method
clc % Clears old time steps and
clear all % y values from previous runs
% Defining given data
a=1; % Initial time
b=1.5; % Final time
h=0.5; % Step Size
N=(b-a)/h; % Number of time steps
x1 = linspace(1,1.5,N); % descritization of the interval
y1=2; % Initial value y(a)
x(1)=1; % Initial value x(1)
y(1)=y1; % Initial value y(a)
f = @(x,y) 3*x.^2 + 4*y; % Given function
for n=1:N % For loop, sets next x,y values % Approximate solution
x(n+1)= x(n)+h;
y(n+1)=y(n) + h*f(x(n),y(n)) % Calls the function f(x,y)=dy/dx
end
figure
plot(x,y)
title('Euler Method h = 0.5','Interpreter','Latex','Fontsize',24)
legend('h=0.5','InterPreter','Latex')
%%for h = 0.1 Euler Method
clc % Clears old time steps and
clear all % y values from previous runs
% Defining given data
a=1; % Initial time
b=1.5; % Final time
h=0.1; % Step Size
N=(b-a)/h; % Number of time steps
x1 = linspace(1,1.5,N); % descritization of the interval
y1=2; % Initial value y(a)
x(1)=1; % Initial value x(1)
y(1)=y1; % Initial value y(a)
f = @(x,y) 3*x.^2 + 4*y; % Given function
for n=1:N % For loop, sets next x,y values % Approximate solution
x(n+1)= x(n)+h;
x(n+1)= x(n)+h;
y(n+1)=y(n) + h*f(x(n),y(n)) % Calls the function f(x,y)=dy/dx
end
figure
plot(x,y)
title('Euler Method h = 0.1','Interpreter','Latex','Fontsize',24)
legend('h=0.1','InterPreter','Latex')
%% plotting approximate solution
%for h = 0.05 Euler Method
clc % Clears old time steps and
clear all % y values from previous runs
% Defining given data
a=1; % Initial time
b=1.5; % Final time
h=0.05; % Step Size
N=(b-a)/h; % Number of time steps
x1 = linspace(1,1.5,N); % descritization of the interval
y1=2; % Initial value y(a)
x(1)=1; % Initial value x(1)
y(1)=y1; % Initial value y(a)
f = @(x,y) 3*x.^2 + 4*y; % Given function
for n=1:N % For loop, sets next x,y values % Approximate solution
x(n+1)= x(n)+h;
x(n+1)= x(n)+h;
y(n+1)=y(n) + h*f(x(n),y(n)) % Calls the function f(x,y)=dy/dx
end
figure
plot(x,y)
title('Euler Method h = 0.05','Interpreter','Latex','Fontsize',24)
legend('h=0.05','InterPreter','Latex')
%Modified Euler method strarts from here
%% for h = 0.5 Modified Euler Method
clc % Clears old time steps and
clear all % y values from previous runs
% Defining given data
a=1; % Initial time
b=1.5; % Final time
h=0.5; % Step Size
N=(b-a)/h; % Number of time steps
x1 = linspace(1,1.5,N); % descritization of the interval
y1=2; % Initial value y(a)
x(1)=1; % Initial value x(1)
y(1)=y1; % Initial value y(a)
f = @(x,y) 3*x.^2 + 4*y; % Given function
for n=1:N % For loop, sets next x,y values % Approximate solution
x(n+1)= x(n)+h;
x(n+1)= x(n)+h;
y(n+1)=y(n) + (h*f(x(n),y(n))+f(x(n+1),y(n)+h*f(x(n),y(n))))/2 % Calls the function f(x,y)=dy/dx for modified Euler method
end
figure
plot(x,y)
title('Euler Method h = 0.5','Interpreter','Latex','Fontsize',24)
legend('h=0.5','InterPreter','Latex')
%% for h = 0.1 Modified Euler Method
clc % Clears old time steps and
clear all % y values from previous runs
% Defining given data
a=1; % Initial time
b=1.5; % Final time
h=0.1; % Step Size
N=(b-a)/h; % Number of time steps
x1 = linspace(1,1.5,N); % descritization of the interval
y1=2; % Initial value y(a)
x(1)=1; % Initial value x(1)
y(1)=y1; % Initial value y(a)
f = @(x,y) 3*x.^2 + 4*y; % Given function
for n=1:N % For loop, sets next x,y values % Approximate solution
x(n+1)= x(n)+h;
x(n+1)= x(n)+h;
y(n+1)=y(n) + (h*f(x(n),y(n))+f(x(n+1),y(n)+h*f(x(n),y(n))))/2 % Calls the function f(x,y)=dy/dx for modified Euler method
end
figure
plot(x,y)
title('Euler Method h = 0.1','Interpreter','Latex','Fontsize',24)
legend('h=0.1','InterPreter','Latex')
%% for h = 0.05 Modified Euler Method
clc % Clears old time steps and
clear all % y values from previous runs
% Defining given data
a=1; % Initial time
b=1.5; % Final time
h=0.05; % Step Size
N=(b-a)/h; % Number of time steps
x1 = linspace(1,1.5,N); % descritization of the interval
y1=2; % Initial value y(a)
x(1)=1; % Initial value x(1)
y(1)=y1; % Initial value y(a)
f = @(x,y) 3*x.^2 + 4*y; % Given function
for n=1:N % For loop, sets next x,y values % Approximate solution
x(n+1)= x(n)+h;
x(n+1)= x(n)+h;
y(n+1)=y(n) + (h*f(x(n),y(n))+f(x(n+1),y(n)+h*f(x(n),y(n))))/2 % Calls the function f(x,y)=dy/dx for modified Euler method
end
figure
plot(x,y)
title('Euler Method h = 0.05','Interpreter','Latex','Fontsize',24)
legend('h=0.05','InterPreter','Latex')