QuestionQuestion

Transcribed TextTranscribed Text

If Y (t) is the solution of the following Initial Value Problem (IVP): y/=6e"ly-20)72 y(0) = -1, our final goal is to obtain the value Y(1) by solving numerically the IVP. a) Check that the function Y (t) = 2t - e-6t is the solution of this IVP. It is not necessary to deduce it, but only substitute it in the ODE. In general, we do not know an analytical expression of the solution. It will be used to check the goodness of the numerical solution. b) Apply the Euler method for h = 0.05, h = 0.1 and h = 0.15. Plot from t = 0 to t = 1 in the same picture: the exact solution and the solutions obtained for these three values of h. Discuss what you see in this picture. c) Compute and plot the same as b) but applying the fourth-order Runge-Kutta (RK4) method. Discuss now what you see in this picture. d) Fill in the following table for the step size h = 0.05, where YE and YRK4 are the solutions by Euler and RK4 method respectively ti Y (ti) YE (ti) YRK4(ti) E(ti) = y/E (ti) - Y (ti) ERK4 = - 0.0 -1 -1 -1 0.05 1 Plot in the same picture the errors eg(t)) and ERK4(ti). What do you think is the cause of the difference in results between different methods? e) We assume that, for a step hi, the error for a numerical method of order p is where C is a constant does not depend on hi. Fill in the following table with errors Ei and hi Ei = |ye(1) - Y(1) In(Ei) Ei = - Y(1) In(zi) 0.01 0.02 0.05 0.1 0.15 We are interested in the order of the methods. Thus, forgetting the constant C, plot in the same picture the two straight lines: The slopes will be the orders of the methods. Thus, the highest slope implies the best method. Which method is the best? Is this to be expected? e) Make a similar table as d) for h = 0.2 and discuss the results obtained.

Solution PreviewSolution Preview

These solutions may offer step-by-step problem-solving explanations or good writing examples that include modern styles of formatting and construction of bibliographies out of text citations and references. Students may use these solutions for personal skill-building and practice. Unethical use is strictly forbidden.

clear; close all; clc;
%% Part a. Check the function given is a solution
% In order to compare the different numerical methods use to solve
% differential equation, in this first part you should verify the function
% given:
%%
%
% $$Y(t) = 2\,t - \exp(-6t)$$
%
% is a solution of
%%
%
% $$y'(t) = 6\:\exp(6t) * (y(t) - 2t)^2 + 2 ,\quad y(0) = -1$$
%
% Thus, the symbolic approach is used to verify them

syms t y
f1 = 6 * exp(6*t) * (y - 2*t)^2 + 2; % y'(t)
f2 = 2*t - exp(-6*t);                % Y(t)
Yprime = diff(f2);

% Now let check if f1 and f2are related.
% In f1 let us substitute t = 0 and y = -1, while in Yprime let us do it
% with t = 0

val_f1 = vpa(subs(f1,[t, y],[0, -1]));
val_f2 = vpa(subs(Yprime,t,0));

if double(val_f1) == double(val_f1)
    fprintf('the function Y(t) is solution of d(y(t)dt)\n')
else
    fprintf('the function Y(t) is solution of d(y(t)dt)\n')
end

%% Part b. Applying Euler method
% For three values of h solve the differential equation and compare with
% the exact solution at IVP y(0) = -1.

h = [0.05, 0.1];
t0 = 0;         % Initial time
t1 = 1;         % Final time
y0 = -1;       % Value of y function at t0

solPartB = struct();
for i=1:length(h)
    solPartB.(sprintf('H_%d', i)) = euler_h(matlabFunction(f1), ...
       t0, t1, y0, h(i));
end

% This part is just for h = 0.15. The initial condition was set to y(0.01)
% calculated before using h = 0.05

solPartB.('H_3') = [0, -1; euler_h(matlabFunction(f1), ...
       0.1, t1, solPartB.H_1(3,2), 0.15)];

exactSolution = double(vpa(subs(f2,t,1)));

figure1 = figure;
axes1 = axes('Parent',figure1);
hold(axes1,'on');
plot(solPartB.H_1(:,1), solPartB.H_1(:,2),...
    'DisplayName','h = 0.05','LineStyle','none',...
    'MarkerSize',8,'Marker','v','LineWidth',2);
plot(solPartB.H_2(:,1), solPartB.H_2(:,2),...
    'DisplayName','h = 0.1','LineWidth',2,...
    'MarkerSize',10,'Marker','o');
plot(solPartB.H_3(:,1), solPartB.H_3(:,2),...
    'DisplayName','h = 0.15','LineWidth',2,...
    'MarkerSize',8,'Marker','s');
plot(1,exactSolution,'DisplayName','Exact',...
    'MarkerFaceColor',[0 0 0],'MarkerSize',15,...
    'Marker','pentagram',...
    'LineStyle','none',...
    'Color',[0 0 0]);
ylabel('y(t)');
xlabel('t');
%ylim(axes1,[-2 10])
box(axes1,'on');
set(axes1,'FontSize',12,'XGrid','on','YGrid','on');
legend1=legend(axes1,'show');
set(legend1,'Location','best')

%% Part c. Applying RK4 method
% For three values of h solve the differential equation and compare with
% the exact solution at IVP y(0) = -1.

solPartC = struct();
for i=1:length(h)...

By purchasing this solution you'll be able to access the following files:
Solution1.zip and Solution2.pdf.

$40.00
for this solution

or FREE if you
register a new account!

PayPal, G Pay, ApplePay, Amazon Pay, and all major credit cards accepted.

Find A Tutor

View available MATLAB for Mathematics Tutors

Get College Homework Help.

Are you sure you don't want to upload any files?

Fast tutor response requires as much info as possible.

Decision:
Upload a file
Continue without uploading

SUBMIT YOUR HOMEWORK
We couldn't find that subject.
Please select the best match from the list below.

We'll send you an email right away. If it's not in your inbox, check your spam folder.

  • 1
  • 2
  • 3
Live Chats