From f00312c5069f095b6e3184fa7be131f62d11f2c8 Mon Sep 17 00:00:00 2001 From: LinlyBoi Date: Sun, 7 May 2023 17:22:01 +0300 Subject: [PATCH] closed estimators but fr this time (DERIVATIVES IN OCTAVE WOO) --- My balls/closed_poopers.m | 50 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) create mode 100644 My balls/closed_poopers.m diff --git a/My balls/closed_poopers.m b/My balls/closed_poopers.m new file mode 100644 index 0000000..e23f9e4 --- /dev/null +++ b/My balls/closed_poopers.m @@ -0,0 +1,50 @@ +clear clc +# Bi section +pkg load symbolic; + +f = @(x) 3*x.^2 - e.^x +a = 0 +b = 1 +# bisection method +function root = bisection(f,a,b) + counter = 0; + while(true) + c = (a + b) / 2; + if (abs(f(c)) < eps) #break at f(c) < eps + break + endif + if(f(c) * f(a) < 0) #find where c lies from the range + b = c; + else + a = c; + endif +counter+=1; +endwhile +counter +root = c +endfunction + +function root = false_position(f,a,b) + counter = 0; + while(true) + c = (a*f(b) - b*f(a)) / (f(b) - f(a));#literally the only difference from bisection + if (abs(f(c)) < eps) #break at f(c) < eps + break + endif + if(f(c) * f(a) < 0) #find where c lies from the range + b = c; + else + a = c; + endif +counter += 1; +endwhile +counter +root = c +endfunction + +printf("FALSE POSITION!!!!") +false_position(f,a,b); +printf("BIIIIIIIYYEEEEEEE") +bisection(f,a,b); + +