From eecdd1537c5bc3a62d32f823387ddf8854856973 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Sun, 14 May 2023 22:18:10 +0300 Subject: [PATCH] no --- newton_differentiation.m | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/newton_differentiation.m b/newton_differentiation.m index 82163e5..4702562 100644 --- a/newton_differentiation.m +++ b/newton_differentiation.m @@ -1,4 +1,5 @@ Y = [] %it doesn't like when I don't add this +% ze basic functions for differentiating function y = f_newt_diff1(Y,h) y = ( Y(2) - Y(1) ) / h end @@ -12,17 +13,18 @@ function y = b_newt_diff1(Y,h) y = ( Y(1) - Y(2) ) / h end - +% this one retrieves elements from "table" and decides which one to usejava +% uses Centered when possible function y = newt_diff_fr1(Y,X,x,h) idx = find(X==x); - if (idx == length(X)) + if (idx == length(X)) %backwards elems = [Y(idx), Y(idx-1)] y = b_newt_diff1(elems,h) - elseif (idx == 1) + elseif (idx == 1) %forwards elems = [Y(idx), Y(idx+1)] y = f_newt_diff1(elems,h) - else + else %centered elems = [Y(idx-1), Y(idx+1)] y = c_newt_diff1(elems,h) endif @@ -41,7 +43,7 @@ newt_diff_fr1(Y,X,1,1) - +% functions but...level 2! function y = f_newt_diff2(Y,h) y = ( Y(3) - 2 * Y(2) + Y(1) ) / h^2 end @@ -58,8 +60,8 @@ end - -function y = newt_diff_fr2(Y,X,x,h) +%Defaults to center level 2 +function y = newt_diff_fr2(Y,X,x,h) %Y -> f(x), X -> x, x -> value we want, h.. idx = find(X==x); if (idx == length(X)) %forwards elems = [Y(idx), Y(idx-1), Y(idx-2)]