f<-function(x){log(x)-cos(x)}

curve(f,0.2,100)

# Bisection's method
a=0.01  # Initial guess 
b=200   # Initial guess 
n=10    

for (i in 1:n){
c=(a+b)/2
if (f(a)*f(c)>0){a=c}
else b=c
}

a;b
f(b) # Test approximation

# Newton's method
df<-function(x){1/x+sin(x)}
curve(df,0.1,exp(1))

x=a # initial guess
for (i in 1:n){x=x-f(x)/df(x)}
x
f(x) # Test of approximation

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: