开发者

Solving numerical problems using Newtons method

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开发者_如何学Python 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.


If you want to use Newton's Method, you will need to know the derivative of the function and code it in.

Otherwise, you can go with the Secant Method which doesn't require knowing the derivative. But it converges at a slower rate.


Depending on how the function is given, you can do a couple of things

  1. symbolic differentiation, if you have a symbolic representation of your function
  2. Numerical differentiation, if you only have point-value pairs
  3. Interpolate with a polynomial and differentiate that (symobolically of course)

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 this

float f (float x) {
    // ...
}

And thus:

float df_dx (float x) {
    // ...
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜