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)) == f[xs]. Used to solve linear systems.

12 ##

14 coefficients = [];

16 for xj = xs

17 this_coeff = 1;

18 for xi = xs

19 if (xi != xj)

20 this_coeff = this_coeff * (1 / (xj - xi));

21 end

22 end

23 coefficients(end+1) = this_coeff;

24 end

25 end