1#include <stdio.h>2#include <stdlib.h>3#include <math.h>4#include <float.h>5#include <time.h>6 7 #definePi 3.14159265358979323846/* pi */8 #defineΕ1.0e-129 intMain ()Ten { One Doublex0 = PI;//the initial value taken A DoubleX1 =0.0;//with x0 calculated x1, the initial value is given 0 first . - DoubleFX =0.0;//f (x) - DoubleFXP =0.0;//derivative of f (x) the DoubleFaix =0.0;//computed results, Newton iteration format Faix =x-(FX/FXP) - inti =0;//number of iterations calculated - while(Fabs ((x0-x1)/x1) >ε)//comparison of relative error and accuracy between two iteration variables - { +x1 = x0;//store the last x0 with X1. -FX = sin (x0)-x0/2; +FXP = cos (x0)-0.5; AFaix = X0-FX/FXP; atx0 = Faix;//assigns the result of the iteration to the last-generation-value variable for the next generation -in use -i++;//Number of calculations -printf"for%d iterations, the iteration result is:,%+.12e \ n", I, X1); - } -}
Title: Calculates the root of the SINX=X/2.
Analysis: Newton method in a wide range of convergence theorems:
The function f (x) has a second-order continuous derivative on the interval [a, b], and satisfies 4 conditions:
1. F (a) *f (b) <0
2. When x belongs to [A, b], the function's derivative value is not equal to zero.
3. When x belongs to [A, b], the second derivative of the function is a number.
4. A-f (a)/F ' (a) <=b, and b-f (b)/F ' (b) <=a
Calculation Result:
Newton iterative method for C language implementation