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

(d) Modify LAB04ex2. m so that it solves (LA.7) using Euler\'s method with N 100

ID: 3802964 • Letter: #

Question

(d) Modify LAB04ex2. m so that it solves (LA.7) using Euler's method with N 1000 in the interval 0 S t S 50 (use the file euler. In from LAB 3 to implement Euler's method; do not delete the lines that implement ode45 Let [te,Yel be the output of euler, and note 6 Stefania Tracogna, SoMSS, ASU LAB sessions: Laboratory 4 ure LAh: Time series y y(t) and v v(t) y (t) (left), and phase plot v Jy vs. y for (LA.7). that Ye is a matrix with two columns from which the Euler's approximation to y(t) must be extracted. Plot the approximation to the solution y(t) computed by ode45 (in black) and the approximation computed by euler (in red) in the same window (you do not need to plot v(t) nor the phase plot). Are the solutions identical? Comment. What happens if we increase the value of N? Include the modified M-file in your report

Explanation / Answer

function [X,Y] = Euler(x,xf,y,n)
h = (xf - x)/n; % step size
X = x; % initial x
Y = y; % initial y
for i = 1 : n % begin loop
y = y + h*f(x,y); % Euler iteration
x = x + h; % new x
X = [X; x]; % update x-column
Y = [Y; y]; % update y-column
end % end loop
%[X,Y] = euler1(0,1, 1, 10); [X,Y]

This the the function which will return Euler's vector within a given interval,then you can plot

that [X,Y] and get the graph