{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

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

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

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

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

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

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
Ask a homework question - tutors are online