X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=divided_difference.m;h=261abeded4ccf9eabf468f817d1b9fa9eafe0994;hp=cd4b0181b10ed4eb7c460798a9a55c711ee813ab;hb=302a62bb7c0adf581916fcd1f93faa719e8d51e8;hpb=62d652799ded51169bda744d8728e1d33582fa5f diff --git a/divided_difference.m b/divided_difference.m index cd4b018..261abed 100644 --- a/divided_difference.m +++ b/divided_difference.m @@ -1,35 +1,32 @@ function dd = divided_difference(f, xs) - ## Compute divided difference of `f` at points `xs`. The argument `xs` - ## is assumed to be a vector containing at least one element. If it - ## contains n elements, the (n-1)st divided difference will be - ## calculated. - ## - ## INPUTS: - ## - ## * ``f`` - The function whose divided differences we want. - ## - ## * ``xs`` - A vector containing x-coordinates. The length of `xs` - ## determines the order of the divided difference. - ## - ## - ## OUTPUTS: - ## - ## * ``dd`` - The divided difference f[xs(1), xs(2),...] - ## - if (exist('../homework1/src', 'dir')) - addpath('../homework1/src'); - end + % Compute divided difference of `f` at points `xs`. The argument `xs` + % is assumed to be a vector containing at least one element. If it + % contains n elements, the (n-1)st divided difference will be + % calculated. + % + % INPUTS: + % + % * ``f`` - The function whose divided differences we want. + % + % * ``xs`` - A vector containing x-coordinates. The length of `xs` + % determines the order of the divided difference. + % + % + % OUTPUTS: + % + % * ``dd`` - The divided difference f[xs(1), xs(2),...] + % order = length(xs) - 1; - + if (order < 0) - ## Can't do anything here. Return nothing. + % Can't do anything here. Return nothing. dd = NA; elseif (order == 0) - ## Our base case. + % Our base case. dd = f(xs(1)); else - ## Order >= 1. + % Order >= 1. cs = divided_difference_coefficients(xs); dd = dot(cs, f(xs)); end