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

*********Reposting again********** This will be the 3rd time posting this questi

ID: 2267966 • Letter: #

Question

*********Reposting again********** This will be the 3rd time posting this question. Please help! I just need help with the Matlab script The one attached is using Euler's method. I need to manipulate it for Improved Euler's. Please do not answer if you don't know what I'm asking. Please!!!! clear all: close all: clc: syms t Yo--0.5: t-e(t) 1 (yo 1) (exp (cos(t)-1)) fplot (e (t) f(t)): xlabel (' ylabel ('y' axis(to 20 -1 1]) hold on: 10 12 13-h 1.0/16.0 14 15 16 17-1 y(n+1) = y(n) 18-end 19-plot (x,y,'E 20xlabel ('t' 21ylabel('y' x 0:h:20; for n = 1:size (x, 2)-1 + h* (sin(x (n)). (1 -y(n))); 23-legend ('Original Function'Euler Output 25- 26- figure plot (x, log (abs (y- xlabel('x' f (x)) ) ) 28 ylabel ("Log (error)') Problem 1: Consider the following Initial Value Problem (IVP) where y is the dependent variable and t is the independent variable -sin(t) (1-y) with y(0)-yo and t20 Note: the analytic solution for this IVP is Part 1B: Approximate the solution to the IVP using the Improved Euler's method with the following conditions: Initial condition yotme steandtime nterval t e 1o20) +Derive the recursive formula for the Improved Euler's method applied to this IVP +Plot the Improved Euler's method approximation +Plot the absolute error between the approximation and the exact solution using a semilog plot

Explanation / Answer

Hello,

Below is the script for the Improved Eulers method implementation, which is just manipulation of your Euler script. The improved eulers formula is also mentioned in the script.

Please try :

%% Improved Euler method (matlab script similar to the above Euler Method)

clear all;
close all;
clc;

syms t;
y0 = -0.5;

f = @(t) (1+(y0 - 1)*(exp(cos(t) -1)));
fplot(@(t) f(t));

xlabel('t')
ylabel('y')
axis([0 20 -1 1])
hold on;

h = 1/16;
y(1) = -.5;
x = 0:h:20;

%   Improved Euler method
%   yn+1 = yn + h/2(s1 + s2)
%   where
%   s1 = f(tn,yn), and
%   s2 = f(tn + h,yn + h*s1)
%   below is the implementation

for n =1:size(x,2) -1
    s1 = sin(x(n))*(1-y(n));
    s2 = sin(x(n)+h)*(1-(y(n) + h*(sin(x(n))*(1-y(n)))));
    y(n+1) = y(n) + .5*h*(s1+s2);
end

plot(x,y,'*')
xlabel('t')
ylabel('y')

legend('Original Function', 'Improved Euler Output')

figure
plot(x,log(abs(y - f(x))))
xlabel('x')
ylabel('log(error)');