sol_hw9 - CE 335 Solutions to Homework 9 8)...

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

View Full Document Right Arrow Icon
CE 335 Solutions to Homework 9 8) function dfdx = richardson(f, x0, tol) %estimate the derivative of a function f at a point x0 using  Richardson interpolation %attempt to supply an answer with fractional accuracy to within tol %use a default tolerance if one is not supplied if nargin < 3 || tol <= 0 tol = 1E-6; end n = 0; nmax = 50; %maximum number of iterations h0 = 1; %initial stepsize to take for centered-difference estimate err = tol + 1; while err > tol h = h0 / (2^n); D(n + 1, 1) = (f(x0 + h) - f(x0 - h)) / (2*h); %centered finite  difference estimate %make higher-order corrections based on sequence of previous  estimates for m = 1:n D(n + 1 - m, m + 1) = D(n + 2 - m, m) + (D(n + 2 - m, m) -  D(n + 1 - m, m)) / (4^m - 1); end %estimate the fractional error from the difference between  estimates if n > 0 err = abs((D(1, n + 1) - D(2 , n)) / D(1, n + 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 08/30/2011 for the course CGN 3350 taught by Professor Lybas during the Spring '11 term at University of Florida.

Page1 / 3

sol_hw9 - CE 335 Solutions to Homework 9 8)...

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