From 4f89e5bf169e181d0c98d134e2e2676f1e1aacb4 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Sun, 7 May 2023 21:05:37 +0300 Subject: [PATCH] open root estimators (they are poo) --- My balls/open_poopers.m | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 My balls/open_poopers.m diff --git a/My balls/open_poopers.m b/My balls/open_poopers.m new file mode 100644 index 0000000..90ae91e --- /dev/null +++ b/My balls/open_poopers.m @@ -0,0 +1,39 @@ +clear clc +# Bi section +pkg load symbolic; + + +f = @(x) 3*x.^2 - e.^x +a = 0 +b = 1 +syms x; +ff = f(x) +function root = newton(f, x0) + if abs(f(x0)) < eps + root = x0; + return + endif + syms x; + df = diff(f(x)); + ff = function_handle (df); + x0 = x0 -( f(x0) / deriv(f,x0) ) + newton(f, x0) +endfunction + +newton(f, 0.5) + +function root = secant(f, x0, x1) + if abs(f(x0)) < eps + root = x0; + return + endif + syms x; + df = diff(f(x)); + ff = function_handle (df); + temp = x1; + x1 = x1 -( ( f(x1) * (x1 - x0) ) / ( f(x1) - f(x0) ) ) + x0 = temp; + secant(f, x0,x1) +endfunction +secant(f, 1, 0) +