% localPolynomialFiniteDifferenceStencilExample clear, home, format compact % weights for approximating the first derivative by % fitting a second degree polynomial through 3 points % p_2(x) = a2*x^2 + a1*x + a0 stencil = [0 1 2]; % h=1 center = 1; % must be a point in the stencil B = vander(stencil) % basis functions % x^2, x, and 1 (columns) % evaluated at each point (rows) of the stencil % H = [2 0 0]; % second derivative H = [2*center 1 0] % differentiated basis function % 2x, 1, and 0 % at the evaluation point (center) % p_2^\prime = 2x*a2 + a1 + 0*a0 w = H/B % w = H*inv(B) % now the weights can be used as f_x(x*) = w*f(stencil) format