Question

In: Advanced Math

y′ = t, y(0) = 1, solution: y(t) = 1+t2/2 y′ = 2(t + 1)y, y(0)...

y′ = t, y(0) = 1, solution: y(t) = 1+t2/2
y′ = 2(t + 1)y, y(0) = 1, solution: y(t) = et2+2t

y′ = 5t4y, y(0) = 1, solution: y(t) = et5
y′ = t3/y2, y(0) = 1, solution: y(t) = (3t4/4 + 1)1/3

For the IVPs above, make a log-log plot of the error of Backward Euler and Implicit Trapezoidal Method, at t = 1 as a function of hwithh=0.1×2−k for0≤k≤5.

Solutions

Expert Solution

MATLAB Code (Backward Euler):

close all
clear
clc

k = 0:1:5;
H = 0.1 * 2.^(-k);

y_exact = @(t) 1 + t^2 / 2;
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + h*(t(j+1))); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Backward Euler Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Backward Euler''s Method at t = 1\nODE: y'' = t'))

y_exact = @(t) exp(t^2 + 2*t);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + h*(2*(t(j+1) + 1)*y_next)); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Backward Euler Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Backward Euler''s Method at t = 1\nODE: y'' = 2(t + 1)y'))

y_exact = @(t) exp(t^5);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + h*(5*t(j+1)^4*y_next)); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Backward Euler Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Backward Euler''s Method at t = 1\nODE: y'' = 5t^4y'))

y_exact = @(t) (3 * t^4 / 4 + 1)^(1/3);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + h*(t(j+1)^3/y_next^2)); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Backward Euler Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Backward Euler''s Method at t = 1\nODE: y'' = t^3/y^2'))

Plots:

MATLAB Code (Implicit Trapz.):

close all
clear
clc

k = 0:1:5;
H = 0.1 * 2.^(-k);

y_exact = @(t) 1 + t^2 / 2;
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + 0.5*h*(t(j) + t(j+1))); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Implicit Trapz. Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Implicit Trapz. Method at t = 1\nODE: y'' = t'))

y_exact = @(t) exp(t^2 + 2*t);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + 0.5*h*(2*(t(j) + 1)*y(j) + 2*(t(j+1) + 1)*y_next)); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Implicit Trapz. Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Implicit Trapz. Method at t = 1\nODE: y'' = 2(t + 1)y'))

y_exact = @(t) exp(t^5);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + 0.5*h*(5*t(j)^4*y(j) + 5*t(j+1)^4*y_next)); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Implicit Trapz. Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Implicit Trapz. Method at t = 1\nODE: y'' = 5t^4y'))

y_exact = @(t) (3 * t^4 / 4 + 1)^(1/3);
y(1) = 1; % Initial condition
ti = 0; tf = 1; % Interval of t
yf_vec = []; % Vector for storing y(t = 1) for different step sizes
for i = 1:length(H)
h = H(i);
t = ti:h:tf;
for j = 1:length(t)-1
syms y_next
sol = solve(y_next == y(j) + 0.5*h*(t(j)^3/y(j)^2 + t(j+1)^3/y_next^2)); % Solve foy y_next
sol = sol(1);
y(j+1) = double(sol); % Implicit Trapz. Update
end
yf_vec = [yf_vec, y(end)]; % Store the value of y(t = 1)
end
figure, loglog(H, abs(y_exact(1) - yf_vec), 'o-'), xlabel('h'), ylabel('Error')
title(sprintf('Log-Log plot of Error of Implicit Trapz. Method at t = 1\nODE: y'' = t^3/y^2'))

Plots:


Related Solutions

y′ = t, y(0) = 1, solution: y(t) = 1+t2/2 y′ = 2(t + 1)y, y(0)...
y′ = t, y(0) = 1, solution: y(t) = 1+t2/2 y′ = 2(t + 1)y, y(0) = 1, solution: y(t) = et2+2t y′ = 5t4y, y(0) = 1, solution: y(t) = et5 y′ = t3/y2, y(0) = 1, solution: y(t) = (3t4/4 + 1)1/3 For the IVPs above, make a log-log plot of the error of Explicit Trapezoidal Rule at t = 1 as a function ofhwithh=0.1×2−k for0≤k≤5.
Consider the IVP t2y''−(t2 + 2)y' + (t + 2)y = t3 with y(1) = 0...
Consider the IVP t2y''−(t2 + 2)y' + (t + 2)y = t3 with y(1) = 0 and y'(1) = 0. • One function in the fundamental set of solutions is y1(t) = t. Find the second function y2(t) by setting y2(t) = w(t)y1(t) for w(t) to be determined. • Find the solution of the IVP
Consider the IVP t2y''−(t2 + 2)y' + (t + 2)y = t3 with y(1) = 0...
Consider the IVP t2y''−(t2 + 2)y' + (t + 2)y = t3 with y(1) = 0 and y'(1) = 0. • One function in the fundamental set of solutions is y1(t) = t. Find the second function y2(t) by setting y2(t) = w(t)y1(t) for w(t) to be determined. • Find the solution of the IVP
find the solution of the given initial value problem 1.   y''+4y=t2+3et, y(0) =0, y'(0) =2 2....
find the solution of the given initial value problem 1.   y''+4y=t2+3et, y(0) =0, y'(0) =2 2. y''−2y'+y=tet +4, y(0) =1, y'(0) =1
y1(t) = (1+t)2 is a solution to y'' + p(t)y' + q(t)y = 0. Find a...
y1(t) = (1+t)2 is a solution to y'' + p(t)y' + q(t)y = 0. Find a second solution that is linearly indepentent of y1(t).
1) find the solution t the non-homogenous DE y''-16y=3e5x , y(0)=1 , y'(0)=2 2)find the solution...
1) find the solution t the non-homogenous DE y''-16y=3e5x , y(0)=1 , y'(0)=2 2)find the solution to the DE using cauchy-euler method x2y''+7xy'+9y=0 , y(1)=2 , y'(1)=3 3)find the solution to the DE using Laplace y''+8y'+16y=0 , y(0)=-1 , y'(0)=8
Given y 1 ( t ) = t2 and y2 ( t ) = t ^−...
Given y 1 ( t ) = t2 and y2 ( t ) = t ^− 1 satisfy the corresponding homogeneous equation of t^2 y ' ' − 2 y = − 3 − t , t > 0 Then the general solution to the non-homogeneous equation can be written as y ( t ) = c1y1(t)+c2y2(t)+yp(t) Use variation of parameters to find y p ( t ) .
Find the general solution of y'' + 2(sech^2 t)y = 0 (1), given that y1 =...
Find the general solution of y'' + 2(sech^2 t)y = 0 (1), given that y1 = tanh t is a solution to (1)
Consider the IVPs: (A) y'+2y = 1, 0<t<1 , y(0)=2. (B) y' = y(1-y), 0<t<1 ,...
Consider the IVPs: (A) y'+2y = 1, 0<t<1 , y(0)=2. (B) y' = y(1-y), 0<t<1 , y(0)=1/2. 1. For each one, do the following: a. Find the exact solution y(t) and evaluate it at t=1. b. Apply Euler's method with Δt=1/4 to find Y4 ≈ y(1). Make a table of tn, Yn for n=0,1,2,3,4. c. Find the error at t=1. 2. Euler's method is obtained by approximating y'(tn) by a forward finite difference. Use the backward difference approximation to y'(tn+1)...
y' = 2 + t^2 + y^2 0<t<1 y(0)=0 use the euler method to determine step...
y' = 2 + t^2 + y^2 0<t<1 y(0)=0 use the euler method to determine step size (h) to keep global truncation error below .0001
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT