Newton iterative method for C language implementation

Source: Internet
Author: User

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

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.