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

Thank you!! Please let me know if this is better? Thanks very much just need hel

ID: 3069368 • Letter: T

Question

Thank you!! Please let me know if this is better? Thanks very much just need help with exercise 1

Instructions: For your lab write-up follow the instructions of LAB 1. Euler's Method To derive Euler's method start from y(toyo and consider a Taylor expansion at tto h: y(ti) - y(to) +y'(to) (t1 -to)+... -yo hf (to, yo) +... For small enough h we get an approximation y for y(ti) by suppressing the ..., namely The iteration (L3.1) is repeated to obtain y2 ^ y(t2),... such that yn+1 yn + hf (tn, yn) = y(t1) Geometrically, the approximation made is equivalent to replacing theVi solution curve by the tangent line at (to, yo). From the figure we have y1 - yo from which (L3.1) follows As an example consider the IVP t1 C0 y'-4y-f (t, y) with y(0) 2 Note that here f does not explicitly depend on t (the ODE is called autonomous), but does implicitly through y -y(t). To apply Euler's method we start with the initial condition and select a step size h Since we are constructing arrays t and y without dimensionalizing them first it is best to clear these names in case they have been used already in the same MATLAB work session >> clear t y % no comma between t and y! type help clear for more info

Explanation / Answer

% DEFINING THE FUNCTION

function [t,y] = euler (f, tspan, y0, N)

m= length(y0);

t0= tspan(1);

tf= tspan(2);

h= (tf - t0)/N;

t= linespace(t0, tf, N+1);

y= zeros(m, N+1);

y(: ,1)= y0;

for k= 1: N

y(: , k+1)= y(: , k) + h*f( t(k) , y(: , k) );

end

t = t' ;

y = y' ;

end

% ACTUAL MATLAB CODE TO SOLVE THE EQUATION

f = inline('2*y' , 't' , 'y');

t= linespace(0, 0.5, 100);

y= 3* exp(2*t) ; % given equation

[t5, y5] = euler(f, [0,0.5], 3, 5); % calling function with N=5

[t50, y50] = euler(f, [0,0.5], 3, 50); % calling function with N=50

[t500, y500] = euler(f, [0,0.5], 3, 500); % calling function with N=500

[t5000, y5000] = euler(f, [0,0.5], 3, 5000); % calling function with N=5000

% PLOTTING THE RESULTS

plot(t5, y5, 'o-', t50, y50, 'x-', t500, y500, '*-', t5000, y5000, '@-', t, y, 'k-');

legend( 'Euler N= 5', 'Euler N= 50', 'EULER N= 500', 'EULER N= 5000',4);

% CALCULATING THE ERROR

e5= y(end) - y5(end);

e50= y(end)- y50(end);

e500= y(end)- y500(end);

e5000= y(end)- y5000(end);

%CALCULATING THE RATIOS OF THE ERRORS

ratio1= e5/e50;

ratio2= e50/e500;

ratio3= e500/e5000;

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote