closed estimators but fr this time (DERIVATIVES IN OCTAVE WOO)

This commit is contained in:
LinlyBoi
2023-05-07 17:22:01 +03:00
parent b5b05e13ce
commit f00312c506

50
My balls/closed_poopers.m Normal file
View File

@@ -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);