I am studying numerical analysis and also solving algorithms which is described in book. My problem is about Newton’s method. In general, if some function is given and we have to find root, how can we determine derivative of function in code? or even limit? because as you know Newton’s method involves derivative and makes iteration like this.
Suppose some function f(x) and initial guess,p0, then p(n)=p(n-1)+f(p(n-1))/f'(p(n-1)) here f' denotes derivative of f.
How can I approximate it in code? Thanks a lot.
Depending on how the function is given, you can do a couple of things
All Options are viable. Which of these is most suited to your problem depends on the function and also the time you want to invest in coding and/or reading up on how to do it.
Edit: If you already know the function before execution time, then compute the differential by hand and implement it as a function. You should also already have implemented your
f(x)as a function like thisAnd thus: