]> gitweb.michael.orlitzky.com - octave.git/blob - divided_difference_coefficients.m
Add the divided_difference_coefficients() function and reimplement divided_difference...
[octave.git] / divided_difference_coefficients.m
1 function coefficients = divided_difference_coefficients(xs)
2 ## Compute divided difference coefficients of `f` at points `xs`.
3 ##
4 ## INPUTS:
5 ##
6 ## * ``xs`` - A vector containing x-coordinates.
7 ##
8 ## OUTPUTS:
9 ##
10 ## * ``coefficients`` - The vector of coefficients such that
11 ## dot(coefficients, f(xs)) == dd. Used to solve linear systems.
12 ##
13
14 coefficients = [];
15
16 for xj = xs
17 this_coeff = 1;
18 for xi = xs
19 if (xi != xj)
20 ## Append (xj - xi) to the vector of coefficients.
21 this_coeff = this_coeff * (1 / (xj - xi));
22 end
23 end
24 coefficients(end+1) = this_coeff;
25 end
26 end