X-Git-Url: http://gitweb.michael.orlitzky.com/?p=octave.git;a=blobdiff_plain;f=forward_euler.m;fp=forward_euler.m;h=0000000000000000000000000000000000000000;hp=ec678a15c741ee29bb7aec50929e6330959a7adc;hb=437324f2edf6b26c772080f8cbe3b321dda8d70f;hpb=f32a60e5aceefce5b4b7497b9d295c8175297110 diff --git a/forward_euler.m b/forward_euler.m deleted file mode 100644 index ec678a1..0000000 --- a/forward_euler.m +++ /dev/null @@ -1,43 +0,0 @@ -function coefficients = forward_euler(integer_order, xs, x) - ## - ## Return the coefficients of u(x0), u(x1), ..., u(xn) as a vector. - ## Take for example a first order approximation, with, - ## - ## xs = [x0,x1,x2,x3,x4] - ## - ## f'(x=x1) ~= [f(x2)-f(x1)]/(x2-x1) - ## - ## This would return [0, -1/(x2-x1), 2/(x2-x1), 0, 0]. This aids - ## the solution of linear systems. - ## - if (integer_order == 0) - df = x; - return; - end - - if (even(integer_order)) - offset_b = integer_order / 2; - offset_f = offset_b; - else - ## When the order is odd, we need one more "forward" point than we - ## do "backward" points. - offset_b = (integer_order - 1) / 2; - offset_f = offset_b + 1; - end - - ## Zero out the coefficients for terms that won't appear. We compute - ## where `x` is, and we just computed how far back/forward we need to - ## look from `x`, so we just need to make the rest zeros. - x_idx = find(xs == x); - first_nonzero_idx = x_idx - offset_b; - last_nonzero_idx = x_idx + offset_f; - leading_zero_count = first_nonzero_idx - 1; - leading_zeros = zeros(1, leading_zero_count); - trailing_zero_count = length(xs) - last_nonzero_idx; - trailing_zeros = zeros(1, trailing_zero_count); - - targets = xs(first_nonzero_idx : last_nonzero_idx); - cs = divided_difference_coefficients(targets); - - coefficients = horzcat(leading_zeros, cs, trailing_zeros); -end