% Usage: r = d1fd2p_varh(f,x,h0,s,n) % 2-point forward difference formula for 1-st 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=d1fd2p(@sin,0,1,0.1,20); % r=d1fd2p(@myfunc,0,1,0.1,50); here 'myfunc' is a user-defined function in M-file % r=d1fd2p(inline('sin(x)'),0,.1,.5,50); % r=d1fd2p(inline('sin(x)-cos(x)'),0,1,0.1,20); function [r,hh] = d1fd2p_varh(f,x,h0,s,n) r = []; h = h0; for i = 1:n r(i) = d1fd2p(f,x,h); hh(i) = h; h = h * s; end;