X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=divided_difference.m;h=261abeded4ccf9eabf468f817d1b9fa9eafe0994;hp=785b66f27e812ff0d908bdbf317b05077e15d694;hb=302a62bb7c0adf581916fcd1f93faa719e8d51e8;hpb=437324f2edf6b26c772080f8cbe3b321dda8d70f diff --git a/divided_difference.m b/divided_difference.m index 785b66f..261abed 100644 --- a/divided_difference.m +++ b/divided_difference.m @@ -1,32 +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),...] - ## - addpath('../homework1/src'); + % 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