Lab10 - >> tc(1)=0; yc(1)=1; h=0.05;...

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

View Full Document Right Arrow Icon
Exercise 1 t(1)=0, y(1)=1, h=0.4 for n=1:5, y(n+1)=y(n)+h*(y(n)+2*t(n)), t(n+1)=t(n)+h, end plot(t,y); a=0:0.04:2; b=3*exp(a)-2*a-2; plot(t,y,'r:p'); hold on; plot(a,b,'g:s'); hold off; tc(1)=0; yc(1)=1; h=0.04; for n=1:50; yc(n+1)=yc(n)+h*(yc(n)+2*tc(n)); tc(n+1)=tc(n)+h; end; plot(t,y,'r:p'); hold on; plot(tc,yc,'b:d'); plot(a,b,'g:s'); hold off; 0 0.5 1 1.5 2 2.5 0 2 4 6 8 10 12 14 16 18 t y Lab 10 - Ex. 1 Previous Approx. New Approx. Exact Soln.
Background image of page 1

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

View Full DocumentRight Arrow Icon
Exercise 2 >> t(1)=0; y(1)=1; h=0.5; >> for n=1:12; y(n+1)=y(n)+h*((1/2)*y(n)-2*cos(t(n))); t(n+1)=t(n)+h; end; >> a=0:0.05:6; >> b=(1/5)*exp(a/2)+(4/5)*cos(a)-(8/5)*sin(a);
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: >> tc(1)=0; yc(1)=1; h=0.05; >> for n=1:120; yc(n+1)=yc(n)+h*((1/2)*yc(n)-2*cos(tc(n))); tc(n+1)=tc(n)+h; end; >> plot(t,y,'r:p'); hold on; >> plot(tc,yc,'b:d'); plot(a,b,'g:s'); hold off; 1 2 3 4 5 6-2-1 1 2 3 4 5 6 Lab 10 - Ex. 2 t y Original Approx. New Approx. Exact Soln. Exercise 3 >> [ts,ys]=rk4('horse',[0,6],1,0.05); >> [tr,yr]=eul('horse',[0,6],1,0.05); >> plot(tr,yr,'r:p'); hold on; >> plot(ts,ys,'b:d'); hold off; 1 2 3 4 5 6-2-1 1 2 3 4 5 6 y t Lab 10 - Ex. 3 - f(t,y) = (1/2) y-2 cos t Euler Approx. RK4 Approx....
View Full Document

Page1 / 3

Lab10 - >> tc(1)=0; yc(1)=1; h=0.05;...

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