f = function(x) x**2 * sin(x-3) * exp(-0.5*x)
f.prime=Deriv(f)
f.double.prime=Deriv(f.prime)
newton=function(f.prime, f.double.prime, x0, tol){
x=x0
while(abs(x-x0)>tol){
x=x0-(f.prime(x0)/f.double.prime(x0))
}
return(x)
}
Hey guys, I am trying to implement the Newton Method with a single variable into R. I think the above code should be correct so far, however I have troubles defining that the variable increase with each iteration. So basically for
while(abs(x-x0)>tol){
x=x0-(f.prime(x0)/f.double.prime(x0))
I dont know how to write that the 2 new variables should be checked for the while condition.
I hope its kind of clear what I mean. can anyone give me a hint? Thanks in advance