HW1_1b - t=E1,1 u1 = 1(1/1.01(sin(2*t-0.1*cos(2*t...

Info iconThis preview shows pages 1–3. Sign up to view the full content.

View Full Document Right Arrow Icon
Problem 1 (b) Solve the equation for 0<t<=7 using the explicit Euler scheme with the following time steps: h = 0,2; 0,05; 0,025; 0,006. clear;clc a=0;b=7;ya=1; h1=0.2; h2=0.05; h3=0.025; h4=0.006; [email protected](t,y) -0.2*y-2*cos(2*t)*y^2; E1 =euler(f,a,b,ya,h1); E2 =euler(f,a,b,ya,h2); E3 =euler(f,a,b,ya,h3); E4 =euler(f,a,b,ya,h4); t=0:0.001:7; u = 1./(1./1.01*(sin(2*t)-0.1*cos(2*t))+1.11/1.01*exp(0.2*t)); figure(1) plot (E1(:,1),E1(:,2), '-' ,E2(:,1),E2(:,2), ':' ,E3(:,1),E3(:,2), '-.' ,E4(:,1),E4(:,2) , hold on l=plot(t,u, 'k' ); set(l, 'linewidth' ,1.5); hold off axis([0 7 0 1.4]) xlabel( 'time' ) ylabel( 'v' ) legend( 'h=0.2' , 'h=0.05' , 'h=0.025' , 'h=0.006' , 'exact' ) title( 'Problem 1-Euler Method' ) Warning: Size vector should be a row vector with integer elements. Warning: Size vector should be a row vector with integer elements. 1
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full Document Right Arrow Icon
Discuss Explict Euler Method is second order accurete over a single time step and first-order accurate globally.
Background image of page 2
Background image of page 3
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: t=E1(:,1); u1 = 1./(1./1.01*(sin(2*t)-0.1*cos(2*t))+1.11/1.01*exp(0.2*t)); diff1 = u1-E1(:,2); t=E2(:,1); u2 = 1./(1./1.01*(sin(2*t)-0.1*cos(2*t))+1.11/1.01*exp(0.2*t)); diff2 = u2-E2(:,2); t=E3(:,1); u3 = 1./(1./1.01*(sin(2*t)-0.1*cos(2*t))+1.11/1.01*exp(0.2*t)); diff3 = u3-E3(:,2); t=E4(:,1); u4 = 1./(1./1.01*(sin(2*t)-0.1*cos(2*t))+1.11/1.01*exp(0.2*t)); diff4 = u4-E4(:,2); figure(2) plot(E1(:,1),diff1, '-' ,E2(:,1),diff2, ':' ,E3(:,1),diff3, '-.' ,E4(:,1),diff4, '--' ) legend( 'h=0.2' , 'h=0.05' , 'h=0.025' , 'h=0.006' ) xlabel( 'time' ) ylabel( 'difference' ) title( 'The difference between EE and exact solution' ) Problem 1 (b) 2 Published with MATLAB® 7.10 Problem 1 (b) 3...
View Full Document

{[ snackBarMessage ]}

Page1 / 3

HW1_1b - t=E1,1 u1 = 1(1/1.01(sin(2*t-0.1*cos(2*t...

This preview shows document pages 1 - 3. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online