128a_su09_hw6_sol

128a_su09_hw6_sol - MATH 128A, SUMMER 2009: HOMEWORK 6...

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

View Full Document Right Arrow Icon
Example code to solve the numerical problems: % Create the table of solutions (by 8 methods) to the IVP from HW6. % t(i+1): Value of t_i % w(i+1,j): Value of w at t_i using method #j % names{j}: Name 7-letter-long name for method #j % Set up the IVP: f = @(t,y) 1+y./t; h = 0.25; t = 1:h:2; n = length(t)-1; w(1,1:8) = 2; for i = 1:n names{1} = ’ Exact ’; w(i+1,1) = t(i+1).*(log(t(i+1))+2); names{2} = ’Taylor2’; df = @(t,y) 1./t; % Total derivative of f(t,y(t)) w(i+1,2) = w(i,2) + h*f(t(i),w(i,2)) + h^2/2*df(t(i),w(i,2)); names{3} = ’M.Euler’; k1 = h*f(t(i) ,w(i,3) ); k2 = h*f(t(i)+h,w(i,3)+k1); w(i+1,3) = w(i,3) + 1/2*k1 + 1/2*k2; names{4} = ’A-B (2)’; if i == 1 w(i+1,4) = w(i+1,1); % Use exact value for w_1. else w(i+1,4) = w(i,4) + h/2*(3*f(t(i),w(i,4)) - f(t(i-1),w(i-1,4))); end names{5} = ’A-M (1)’; % Algebraic solution to w = a + b*f(t,w): % w = a + b + (b/t)w ==> (1-b/t)*w = a+b sol = @(a,b,t) (a+b) ./ (1-b./t); w(i+1,5) = sol(w(i,5) + h/2*f(t(i),w(i,5)), h/2, t(i+1)); names{6} = ’APC 1,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
Image of page 2
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 04/06/2010 for the course MATH various taught by Professor Tao/analysis during the Spring '10 term at UCLA.

Page1 / 3

128a_su09_hw6_sol - MATH 128A, SUMMER 2009: HOMEWORK 6...

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

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