f<-function(x){x*cos(x)+1}
curve(f,0,5)
# Bisection's method
a=0 # Initial guess
b=3 # Initial guess
n=10
for (i in 1:n){
c=(a+b)/2
if (f(a)*f(c)>0){a=c}
else b=c
print(c)
}
a;b
print("Approximated solution c:");c
print("Test to f(c)"); f(c) # Test approximation
To embed this project on your website, copy the following code and paste it into your website's HTML: