Newton's method-numerical analysis

  • MHB
  • Thread starter evinda
  • Start date
  • Tags
    Analysis
In summary, the conversation discusses the termination criteria for the Newton-Raphson method, the maximum number of iterations needed for convergence, and the calculation of error in the last iteration. The participants also mention the use of a different method to arrive at an accurate initial approximation, and the unpredictability of Newton's method in certain cases. The conversation ends with a discussion about plotting the first five approximations of the method in MATLAB.
  • #1
evinda
Gold Member
MHB
3,836
0
Hello again..! ;) I also wrote a program of the Newton mathod,with the same termination criteria (The program should end if the number of iterations surpass the maximum number of iterations,or if one or both of these conditions :
[tex]\left | x_{k}-x_{k-1} \right | [/tex] < ε and [tex] \left | f(x_{k}) \right | [/tex] < ε
are valid. )
At the bisection method I found the maximum number of iterations needed so that the method converges,using the formula [tex] n=log_{2}(\frac{b-a}{ε}) [/tex] (or am I wrong? ).Is there a similar formula to find the maximum number of iterations needed so that the Newton method converges?
 
Mathematics news on Phys.org
  • #2
Re: Newton method-numerical analysis

evinda said:
Hello again..! ;) I also wrote a program of the Newton mathod,with the same termination criteria (The program should end if the number of iterations surpass the maximum number of iterations,or if one or both of these conditions :
[tex]\left | x_{k}-x_{k-1} \right | [/tex] < ε and [tex] \left | f(x_{k}) \right | [/tex] < ε
are valid. )
At the bisection method I found the maximum number of iterations needed so that the method converges,using the formula [tex] n=log_{2}(\frac{b-a}{ε}) [/tex] (or am I wrong? ).Is there a similar formula to find the maximum number of iterations needed so that the Newton method converges?

The convergence of the Newton-Raphson method is strongly dependent from the initial point $x_{0}$. A non properly 'inspired' choice of $x_{0}$ can produce slow convergence or even divergence as described in...

http://mathhelpboards.com/discrete-mathematics-set-theory-logic-15/difference-equation-tutorial-draft-part-i-426.html#post2492

A good strategy is to use a different method [... like the bisection method for example...] to arrive to an 'accurate enough' approximation of the solution and use that as $x_{0}$ for the Newton's iterations...

Kind regards

$\chi$ $\sigma$
 
  • #3
Re: Newton method-numerical analysis

evinda said:
Hello again..! ;) I also wrote a program of the Newton mathod,with the same termination criteria (The program should end if the number of iterations surpass the maximum number of iterations,or if one or both of these conditions :
[tex]\left | x_{k}-x_{k-1} \right | [/tex] < ε and [tex] \left | f(x_{k}) \right | [/tex] < ε
are valid. )
At the bisection method I found the maximum number of iterations needed so that the method converges,using the formula [tex] n=log_{2}(\frac{b-a}{ε}) [/tex] (or am I wrong? ).Is there a similar formula to find the maximum number of iterations needed so that the Newton method converges?

Your maximum iteration formula for bisection looks correct. :)

But there is not really such a formula for Newton's method.
Newton's method is a bit unpredictable in that respect.
It may not converge at all, or converge only linearly if it has a duplicated multiple root, or converge slowly if there are a couple of roots close together.

As I know it, the best we can say, is that under "normal" circumstances, it converges quadratically, which is way faster than the bisection method.
 
  • #4
Re: Newton method-numerical analysis

I understand...thank you both for your help! :)

Could you give me also for the Newton method an example of the results with a specific initial value xo,a specific maximum number of iterations and a specific T0L of the function e^x+x+1,so I can check my output??

Also,could you tell me how I can find the error [tex] \left | x_{k}-B \right | [/tex] of the last iteration of the method?? (B is the real solution of the function and [tex] x_{k} [/tex] the approximation of the last iteration of the Newton method) :confused:
 
  • #5
Re: Newton method-numerical analysis

evinda said:
I understand...thank you both for your help! :)

Could you give me also for the Newton method an example of the results with a specific initial value xo,a specific maximum number of iterations and a specific T0L of the function e^x+x+1,so I can check my output??

Also,could you tell me how I can find the error [tex] \left | x_{k}-B \right | [/tex] of the last iteration of the method?? (B is the real solution of the function and [tex] x_{k} [/tex] the approximation of the last iteration of the Newton method) :confused:

When the method is converging to the root, the remaining error is less than the difference with the last approximation.

With x[0] = -1 and TOL = 0.001, I get:

x[2] = -1.278454624, f(x[2]) = 0.000012681, upper bound for error = 0.009513202.
 
  • #6
Re: Newton method-numerical analysis

I like Serena said:
When the method is converging to the root, the remaining error is less than the difference with the last approximation.

With x[0] = -1 and TOL = 0.001, I get:

x[2] = -1.278454624, f(x[2]) = 0.000012681, upper bound for error = 0.009513202.

Nice...I get the same x[2] and f(x[2])!But...How did you find the upper bound for error? :confused:
 
  • #7
Re: Newton method-numerical analysis

evinda said:
Nice...I get the same x[2] and f(x[2])!But...How did you find the upper bound for error? :confused:

The difference between this approximation and the one before it.
Which error do you have? :rolleyes:
 
  • #8
Re: Newton method-numerical analysis

I had not calculated it before..Now,I found the difference [tex] \left |x_{k}-x_{k-1} \right | [/tex] and the result is the same as yours! :D

Last but not least ;) :eek: :eek: I have to plot the 5 first approximations of the Newton method in Matlab.I am confused now..What do I have to plot??Only the x of each iteration?? :eek:
 
  • #9
Re: Newton method-numerical analysis

evinda said:
I had not calculated it before..Now,I found the difference [tex] \left |x_{k}-x_{k-1} \right | [/tex] and the result is the same as yours! :D

Good! :cool:
Last but not least ;) :eek: :eek: I have to plot the 5 first approximations of the Newton method in Matlab.I am confused now..What do I have to plot??Only the x of each iteration?? :eek:


Perhaps f(x) versus x?
 
  • #10
Re: Newton method-numerical analysis

I wrote the following loop in the function:
Code:
 for k=1:5
    if (g(x_o)==0)
        return;
    end
    x_1=x_o-f(x_o)/g(x_o);
    t=@(x) g(x_1)*(x-x_1)+f(x_1);
    plot(x_1,f(x_1))
    hold on
    x_o=x_1;  
end
where g the derivative of f.
I don't get a plot..:confused: Where is my error?
 
  • #11
Re: Newton method-numerical analysis

evinda said:
I wrote the following loop in the function:
Code:
 for k=1:5
    if (g(x_o)==0)
        return;
    end
    x_1=x_o-f(x_o)/g(x_o);
    t=@(x) g(x_1)*(x-x_1)+f(x_1);
    plot(x_1,f(x_1))
    hold on
    x_o=x_1;  
end
where g the derivative of f.
I don't get a plot..:confused: Where is my error?

Perhaps you should collect the data first in 2 vectors before plotting?

Something like:
Code:
N = 5;
x = zeros(N, 1);
fx = zeros(N, 1);
x(1) = x_o;
fx(1) = f(x(1));

for k=2:N
    x(k) = x(k-1)-fx(k-1)/fp(x(k-1));
    fx(k) = f(x(k));
end

plot(x, fx);

Btw, I do not have Matlab.
 
  • #12
Re: Newton method-numerical analysis

I like Serena said:
Perhaps you should collect the data first in 2 vectors before plotting?

Something like:
Code:
N = 5;
x = zeros(N, 1);
fx = zeros(N, 1);
x(1) = x_o;
fx(1) = f(x(1));

for k=2:N
    x(k) = x(k-1)-fx(k-1)/fp(x(k-1));
    fx(k) = f(x(k));
end

plot(x, fx);

Btw, I do not have Matlab.

I ran your code and the result is just one line... :confused: :confused:
 
  • #13
Re: Newton method-numerical analysis

evinda said:
I ran your code and the result is just one line...

That sounds about right for exp(x)+x+1 and an initial value of x = -1. ;)
Try it with x = 5.
Then you should get a curve.

Btw, I guess your original code should work as well?? :confused:
 
  • #14
Re: Newton method-numerical analysis

If you want, you might also draw a line from (x[k], f(x[k])) to (x[k+1], 0).
And perhaps another one from (x[k+1], 0) to (x[k+1], f(x[k+1])).

Those lines show how the algorithm works: the tangent line at x[k] is used to find the next approximation (where it intersects the x-axis).
 
  • #15
Re: Newton method-numerical analysis

At my graph, except form the five first approximation there should also be the function f and its tangent.. My code is the following:
Code:
tan=@(x) g(x_o)*(x-x_o)+f(x_o);
plot(x,f(x),'m',x,tan(x),'g')
 hold on
for k=1:5
    if (g(x_o)==0)
        return;
    end
    x_1=x_o-f(x_o)/g(x_o);
    t=@(x) g(x_1)*(x-x_1)+f(x_1);
    plot(x_o,f(x_o),x,t(x))
   hold on
    x_o=x_1;   
end
The plot that comes out is this: (see attachment).
Is this right?

How can I show how the algorithm works as you said in your last post??because when I do it like that
Code:
 plot(x(k),f(x(k)),x(k+1),0);
    hold on
it says that there is somewhere an error...
:confused::(
 

Attachments

  • plot.jpg
    plot.jpg
    33.5 KB · Views: 66
  • #16
Re: Newton method-numerical analysis

evinda said:
At my graph, except form the five first approximation there should also be the function f and its tangent.. My code is the following:
Code:
tan=@(x) g(x_o)*(x-x_o)+f(x_o);
plot(x,f(x),'m',x,tan(x),'g')
 hold on
for k=1:5
    if (g(x_o)==0)
        return;
    end
    x_1=x_o-f(x_o)/g(x_o);
    t=@(x) g(x_1)*(x-x_1)+f(x_1);
    plot(x_o,f(x_o),x,t(x))
   hold on
    x_o=x_1;   
end
The plot that comes out is this: (see attachment).
Is this right? :confused::(

Perhaps you can replace
Code:
    t=@(x) g(x_1)*(x-x_1)+f(x_1);
    plot(x_o,f(x_o),x,t(x))
by
Code:
    t=@(x) g(x_o)*(x-x_o)+f(x_o);
    plot(x_o,f(x_o),x_1,t(x_1))
??
How can I show how the algorithm works as you said in your last post??because when I do it like that
Code:
    plot(x(k),f(x(k)),x(k+1),0);
    hold on
it says that there is somewhere an error...

Not entirely sure since I don't have Matlab.
But perhaps it's trying to access x(6) even though it does not exist?
What error does it give?
 

FAQ: Newton's method-numerical analysis

What is Newton's method in numerical analysis?

Newton's method, also known as the Newton-Raphson method, is a numerical algorithm used to find the root of a function. It is an iterative method that starts with an initial guess and repeatedly improves the guess until it reaches the root of the function. It is commonly used to solve equations that cannot be solved analytically.

How does Newton's method work?

Newton's method uses the tangent line of a function to approximate the root. It starts with an initial guess and calculates the slope of the tangent line at that point. The next guess is then calculated by finding the x-intercept of the tangent line. This process is repeated until the root is found or the maximum number of iterations is reached.

What are the advantages of using Newton's method?

One advantage of Newton's method is its fast convergence rate. It can find the root of a function with high accuracy in just a few iterations. It is also versatile and can be used to find multiple roots of a function simultaneously. Additionally, it can handle complex functions with multiple variables.

What are the limitations of Newton's method?

One limitation of Newton's method is that it may fail to converge if the initial guess is not close enough to the root. It also requires the calculation of the derivative of the function, which may be difficult or impossible in some cases. Additionally, it can only find real roots of a function, and may not work for complex roots.

How is Newton's method used in real-life applications?

Newton's method is commonly used in various fields such as engineering, physics, and economics to solve complex problems. It is used in optimization problems, such as finding the minimum or maximum of a function. It is also used in computer graphics to generate realistic images and in machine learning to find optimal parameters for models.

Similar threads

Replies
9
Views
2K
Replies
1
Views
2K
Replies
38
Views
7K
Replies
1
Views
10K
Replies
1
Views
9K
Replies
1
Views
10K
Replies
7
Views
2K
Replies
21
Views
3K
Replies
1
Views
10K
Back
Top