Homework 8 - Egm 3344 Problem Set#8 Sorting Number 26...

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

View Full Document Right Arrow Icon
Egm 3344 Problem Set #8 Sorting Number 26 Problems Completed 20.1; 20.9; 20.15; 21.3; 21.6; 21.11; 22.1
Background image of page 1

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

View Full DocumentRight Arrow Icon
Problem 20.1 function Prob20_1 % Solve analytically %?????????????????????????????????????? dydt = @(t,y) y.*t.^2 - 1.1.*y; tr=linspace(0,2); yr=exp((tr.^3/3)-1.1*tr); plot(tr,yr, 'b-' ) hold on %?????????????????????????????????????? % Eulers method step .5 ti = 0; tf = 2; yi = 1; h = .5; t = (ti:h:tf)';n = length(t); y = yi*ones(n,1); fprintf( 't\ty\t\tdydt\t\n' ) for i = 1:n-1; y(i+1) = y(i) + dydt(t(i),y(i))*h; deriv(i,1) = dydt(t(i),y(i)); fprintf( '%1.1f\t%2.4f\t%2.4f\n' ,t(i),y(i),deriv(i)) end deriv(5,1) = dydt(t(5),y(5)); fprintf( '%1.1f\t%2.4f\t%2.4f\n\n' ,t(5),y(5),deriv(5)) plot(t,y, 'kx--' ) % Eulers method step .25 ti = 0; tf = 2; yi = 1; h = .25; t = (ti:h:tf)';n = length(t); y = yi*ones(n,1); fprintf( 't\ty\t\tdydt\t\n' ) for i = 1:n-1; y(i+1) = y(i) + dydt(t(i),y(i))*h; deriv(i,1) = dydt(t(i),y(i)); fprintf( '%1.1f\t%2.4f\t%2.4f\n' ,t(i),y(i),deriv(i)) end deriv(9,1) = dydt(t(9),y(9)); fprintf( '%1.1f\t%2.4f\t%2.4f\n\n' ,t(9),y(9),deriv(9)) plot(t,y, 'rd--' ) % Midpoint Method with step sizes of .5 ti = 0; tf = 2; yi = 1; h = .5; t = (ti:h:tf)';n = length(t); tm = t+h/2; y = yi*ones(n,1); fprintf( 'x\ty\t\tdydt\ttm\t\tym\n' ) for i = 1:n-1 ym(i,1) = y(i,1) + dydt(t(i),y(i))*(h/2); y(i+1,1) = y(i,1) + dydt(tm(i,1),ym(i,1))*h; deriv(i,1) = dydt(t(i),y(i)); derivm(i,1) = dydt(tm(i,1),ym(i,1)); fprintf( '%1.1f\t%2.4f\t%2.4f\t%1.2f\t%2.4f\n' ,t(i),y(i),deriv(i),tm(i),y m(i)) end plot(t,y, 'go--' )
Background image of page 2
% Runge Kutta Method ti = 0; tf = 2; yi = 1; h = .5; t = (ti:h:tf)';n = length(t); tm = t+h/2;
Background image of page 3

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

View Full DocumentRight Arrow Icon
Image of page 4
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 09/05/2011 for the course EGM 3344 taught by Professor Raphaelhaftka during the Spring '09 term at University of Florida.

Page1 / 14

Homework 8 - Egm 3344 Problem Set#8 Sorting Number 26...

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

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