]> gitweb.michael.orlitzky.com - octave.git/blob - divided_difference.m
Update the poisson_matrix test with negated values.
[octave.git] / divided_difference.m
1 function dd = divided_difference(f, xs)
2 ## Compute divided difference of `f` at points `xs`. The argument `xs`
3 ## is assumed to be a vector containing at least one element. If it
4 ## contains n elements, the (n-1)st divided difference will be
5 ## calculated.
6 ##
7 ## INPUTS:
8 ##
9 ## * ``f`` - The function whose divided differences we want.
10 ##
11 ## * ``xs`` - A vector containing x-coordinates. The length of `xs`
12 ## determines the order of the divided difference.
13 ##
14 ##
15 ## OUTPUTS:
16 ##
17 ## * ``dd`` - The divided difference f[xs(1), xs(2),...]
18 ##
19 if (exist('../homework1/src', 'dir'))
20 addpath('../homework1/src');
21 end
22
23 order = length(xs) - 1;
24
25 if (order < 0)
26 ## Can't do anything here. Return nothing.
27 dd = NA;
28 elseif (order == 0)
29 ## Our base case.
30 dd = f(xs(1));
31 else
32 ## Order >= 1.
33 cs = divided_difference_coefficients(xs);
34 dd = dot(cs, f(xs));
35 end
36 end