% Usage: r = d2cd3p(f,x,h) % 3-point centered-difference formula for 2-nd derivative % % Input: % f - Matlab inline function % x - point where the derivative is computed % h - stepsize % % Output: % r - computed value of the derivative % % Examples: % r=d2cd3p(@sin,0,0.1); % r=d2cd3p(@myfunc,0,.1); here 'myfunc' is a user-defined function in M-file % r=d2cd3p(inline('sin(x)'),0,0.1); % r=d2cd3p(inline('sin(x)-cos(x)'),0,0.1); function r = d2cd3p(f,x,h) r = (f(x+h)-2*f(x)+f(x-h))/(h*h);