% Usage: r = d2cd3p_varh(f,x,h0,s,n) % 3-point centered-difference formula for 2-nd derivative, for varying % stepsize h % % Input: % f - Matlab inline function % x - point where the derivative is computed % h0 - initial value of stepsize % s - factor by which the stepsize is multiplied at each iteration % n - number of total iteration % % Output: % r - matrix containing computed values of the derivative % % Examples: % r=d2cd3p(@sin,0,1,0.1,20); % r=d2cd3p(@myfunc,0,1,0.1,50); here 'myfunc' is a user-defined function in M-file % r=d2cd3p(inline('sin(x)'),0,.1,.5,50); % r=d2cd3p(inline('sin(x)-cos(x)'),0,1,0.1,20); function [r,hh] = d2cd3p_varh(f,x,h0,s,n) r=[]; h=h0; for i = 1:n r(i) = d2cd3p(f,x,h); hh(i) = h; h = h * s; end;