#include<stdio.h> #define F(x) (x*x - 4) #define FPrime(x) (2*x) #define MAX_ITER 100 float Newton(float x0) { int iter = 0; float x1; while(iter < MAX_ITER) { x1 = x0 - F(x0)/FPrime(x0); x0 = x1; iter++; } return x0; } int main() { printf("Finding root of a continuous function using Newton's method.\n"); float x0 = 1; printf("Root of the given function is : %f\n", Newton(x0)); return 0; }
Wednesday, 17 December 2014
Find root using Newton's method
Labels:
Root finding
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment