X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=divided_difference_coefficients.m;fp=divided_difference_coefficients.m;h=a40f5597d6b47712ad7e0b397585d71641b80ec8;hp=0000000000000000000000000000000000000000;hb=876e38fb99680748dfdf334ba450f633566d9b6a;hpb=62d652799ded51169bda744d8728e1d33582fa5f diff --git a/divided_difference_coefficients.m b/divided_difference_coefficients.m new file mode 100644 index 0000000..a40f559 --- /dev/null +++ b/divided_difference_coefficients.m @@ -0,0 +1,25 @@ +function coefficients = divided_difference_coefficients(xs) + ## Compute divided difference coefficients of `f` at points `xs`. + ## + ## INPUTS: + ## + ## * ``xs`` - A vector containing x-coordinates. + ## + ## OUTPUTS: + ## + ## * ``coefficients`` - The vector of coefficients such that + ## dot(coefficients, f(xs)) == f[xs]. Used to solve linear systems. + ## + + coefficients = []; + + for xj = xs + this_coeff = 1; + for xi = xs + if (xi != xj) + this_coeff = this_coeff * (1 / (xj - xi)); + end + end + coefficients(end+1) = this_coeff; + end +end