This is a Matlab assignment for MAT275 (differential equation class). Please hel
ID: 3757048 • Letter: T
Question
This is a Matlab assignment for MAT275 (differential equation class). Please help me with the script I need to turn in for the assignment! Thank you all! :)
4. Consider the IVP y 4y, y(0) 2 0t 0.5 (a) Determine the Improved Euler's approximation for N-50, N-500 and N 5000. Fill in the following table with the values of the approximations, errors and ratios of consecutive errors at t-0.5. One of the values has already been entered based on the computations we Include the table in your report, as well as the MATLAB commands used to find the entries. ratio N/A did above. Recall that the exact solution to the ODE is y 2e4. N approximation error 14.2016 50 500 (b) Examine the last column. How does the ratio of the errors relate to the number of steps used? Your answer to this question should confirm the fact that Improved Euler's method is of "order h2 ", that is, every time the stepsize is decreased by a factor k, the error is reduced (approximately) by a factor of k2Explanation / Answer
Matlab Code:
a)
y = 2;
N = 5;
h = 0.5/N;
for i=1:N
m1 = 4*y;
m2 = 4*(y + h*m1);
y = y + 0.5*h*(m1 + m2);
end
disp('For N = 5');
fprintf('Approximation: %f ', y);
fprintf('Error: %f ', abs(y - 2*exp(3*0.5)));
fprintf('Actual/Approximation: %f ', 2*exp(3*0.5)/y);
% for N = 50
y = 2;
N = 50;
h = 0.5/N;
for i=1:N
m1 = 4*y;
m2 = 4*(y + h*m1);
y = y + 0.5*h*(m1 + m2);
end
disp('For N = 50');
fprintf('Approximation: %f ', y);
fprintf('Error: %f ', abs(y - 2*exp(3*0.5)));
fprintf('Actual/Approximation: %f ', 2*exp(3*0.5)/y);
% for N = 500
y = 2;
N = 500;
h = 0.5/N;
for i=1:N
m1 = 4*y;
m2 = 4*(y + h*m1);
y = y + 0.5*h*(m1 + m2);
end
disp('For N = 500');
fprintf('Approximation: %f ', y);
fprintf('Error: %f ', abs(y - 2*exp(3*0.5)));
fprintf('Actual/Approximation: %f ', 2*exp(3*0.5)/y);
% for N = 5000
y = 2;
N = 5000;
h = 0.5/N;
for i=1:N
m1 = 4*y;
m2 = 4*(y + h*m1);
y = y + 0.5*h*(m1 + m2);
end
disp('For N = 5000');
fprintf('Approximation: %f ', y);
fprintf('Error: %f ', abs(y - 2*exp(3*0.5)));
fprintf('Actual/Approximation: %f ', 2*exp(3*0.5)/y);
b)
The errors for N=5, 50, 500, 5000:
Error1: 5.238264
Error2: 5.807087
Error3: 5.814655
Error4: 5.814733
If your observe, e2 = 0.01*e1, i.e., e2 is approximately equal to (k^2)*e1, where k = 10, as the number of steps in second column (50) = 10 times of the number of steps in column one (5).
The above condition is true for all the remaining cases
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.