Newton Iterative Method: Introduction, Principle and application

Source: Internet
Author: User

Newton Iterative Method: Introduction, Principle and application

Newton Iterative method is a tool that can find 0 points of an arbitrary function. It is much faster than the dichotomy.

The formula is: X=a-f (a)/F ' (a). Where A is the guess value and x is the new guess value. Constantly iterating, F (x) is getting closer to 0.

Principle

We will f (x) do Taylor first-order expansion: F (x) ∼f (a) + (x-a) f ' (a).

Make f (x) = 0,
∴f (a) + (x-a) f ' (a) = 0
∴f (a) +xf ' (a)-af ' (a) = 0
∴xf ' (a) =af ' (a)-f (a)
∴x=a-f (a)/F ' (a)

Example: Newton iterative method for calculating approximate value of √2

X =√2
x2 = 2
x2-2 = 0

f (x) = equation to the left , then f (x) ∼0↔x∼√2.

F ' (x) = 2x. You can then get an iterative formula:

X
= A-f (a)/F ' (a)
= A-(A2-2)/(2a)
= a-a/2+1/a
= a/2+1/a

The code is as follows (requires less than 1e-6 error):

#include <stdio.h> #include <math.h>int main (int argc, char const *argv[]) {Double A = 2.0;double Expect_error = 0.000001;double expect_answer = 1.4142135623731;double x;double actual_error;unsigned iteration_count = 0;do {if (a = = 0. 0) A = 0.1; /* Avoid except 0 */x = a/2 + 1/a;actual_error = fabs (expect_answer-x); a = x;++iteration_count;printf ("%d\t%.9f\t%.9f\n", Iteratio N_count, A, actual_error);} while (Actual_error >= expect_error);p rintf ("%d\n", Iteration_count); return 0;}

Output:

11.5000000000.08578643821.4166666670.00245310431.4142156860.00000212441.4142135620.0000000004

Iterated 4 times. In the dichotomy?

#include <stdio.h> #include <math.h>int main (int argc, char const *argv[]) {Double high = 2.0;double Low = 1.0;d ouble Expect_error = 0.000001;double expect_answer = 1.4142135623731;double x;double actual_error;unsigned iteration_ Count = 0;do {x = (High+low)/2;if (x*x-2 > 0) high = X;elselow = X;actual_error = Fabs (expect_answer-x); ++iteration_co unt;printf ("%d\t%.9f\t%.9f\n", Iteration_count, X, Actual_error); while (Actual_error >= expect_error);p rintf ("%d\n", Iteration_count); return 0;}

Output:

11.5000000000.08578643821.2500000000.16421356231.3750000000.03921356241.4375000000.02328643851.4062500000.00796356261.421 8750000.00766143871.4140625000.00015106281.4179687500.00375518891.4160156250.001802063101.4150390620.000825500111.4145507 810.000337219121.4143066410.000093078131.4141845700.000028992141.4142456050.000032043151.4142150880.000001526161.41419982 90.000013733171.4142074580.000006104181.4142112730.000002289191.4142131810.00000038219

iterated 19 times.

Newton Iterative Method: Introduction, Principle and application

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.