You are on page 1of 7

Home

C Programs

C Compiler

C Tutorials

Mathematics

Algorithms

Windows Programming

C program of Newton Raphson Method | C code champ


MR CODER AUGUST 20, 2012 4

Search here..

+2 Recommend this on Google

C program of Newton Raphson Method : Newton Raphson method is a method of approximating a root of the polynomial equation also called the method of tangents. In Newtons method, the initial (first) approximation x = a1 is used to find a second, more accurate, approximation by drawing the tangent to the graph of y = f(x) at the point A[a1, f(a1)] up to the intersection of the tangent with the x-axis. The point of intersection is

x = a1 f(a1)/f(a1)

Ccodechamp
and is adopted as the new value a2 of the root. By repeating this process as necessary, we can obtain
Like

on Facebook

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

increasingly accurate approximations a2, a3, of the root provided that the derivative f(x) is monotonic and preserves its sign on the segment containing root. How to use the C program :

55 people like Ccodechamp.

P riyank

N izamudheen hant P ras hmita P ras

J unaid

Shas hank

Consider an example : f(x) = x^2 - 4 as our polynomial equation. We want to calculate its root and say first approximation =6. Then maximum power of X = 2, coefficients of x^0 = -4, x^1 = 0, x^2 = 1 & first approximation =6. Now C program of Newton Raphson Method will display the iterations and root of the polynomial as output.
Fac ebook s oc ial plugin

C program of Newton Raphson Method :


#include<conio.h> #include<stdio.h> #include<stdlib.h> #include<math.h> int max_power,i=0,cnt=0,flag=0; int coef[10]={0}; float x1=0,x2=0,t=0; float fx1=0,fdx1=0; int main() { printf("-----------------------------------------------------------\n"); printf("----------------------Made by C code champ-----------------\n"); printf("-----------------------------------------------------------\n\n"); printf("\n\n\t C PROGRAM FOR NEWTON RAPHSON METHOD"); printf("\n\n\n\tENTER THE MAXIMUM POWER OF X = "); scanf("%d",&max_power); for(i=0;i<=max_power;i++) { printf("\n\t x^%d = ",i); scanf("%d",&coef[i]); } printf("\n"); printf("\n\tTHE POLYNOMIAL IS = "); for(i=max_power;i>=0;i--)/*printing coefficients*/ { printf(" %dx^%d",coef[i],i); } Enter your email address to subscribe:

Subscribe

Categories
Select Category

Sitemap
August 2012 (51)

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

printf("\n\n\tFirst approximation x1 ----> "); scanf("%f",&x1); printf("\n\n-----------------------------------------------------------\n"); printf("\n ITERATION \t x1 \t F(x1) \t \tF'(x1) "); printf("\n-----------------------------------------------------------\n"); do {

cnt++; fx1=fdx1=0; for(i=max_power;i>=1;i--) { fx1+=coef[i] * (pow(x1,i)) ; } fx1+=coef[0]; for(i=max_power;i>=0;i--) { fdx1+=coef[i]* (i*pow(x1,(i-1))); } t=x2; x2=(x1-(fx1/fdx1)); x1=x2; printf("\n\t %d \t%.3f \t %.3f\t\t%.3f ",cnt,x2,fx1,fdx1);

}while((fabs(t - x1))>=0.0001); printf("\n\n\n\t THE ROOT OF EQUATION IS = %f",x2); getch();

We hope that you all have enjoyed the C program of Newton Raphson Method. If you have any doubts related to the program ask us in form of comments.

TAGS algorithms in C, C code of New ton Raphson Method, C program of New ton Raphson Method, C programs, New ton Raphson in C, New ton Raphson Method in C POSTED IN Algorithms, C Programs, Equations, Mathematics

About the author: Mr Coder

View all posts by Mr Coder

Well, I am application developer in Tata Consultancy Services and love to code. My hobbies is to do Hacking, Coding, Blogging, Web Designing and playing online games. Feel free to contact me at shiviskingg@gmail.com or lokesh@hackingloops.com

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Related Articles
C program to print reverse pyramid of alphabets C program to Print Pascal Triangle | C code champ C code to draw pyramid using stars | C code champ C program of Newton Backward Interpolation Formula C program of Booths multiplication algorithm C program of Bubble sort using linked list C program of Knapsack problem using Backtracking C program for Travelling Salesman Problem using Branch and Bound C program to find determinant of Matrix | C code champ C program of Travelling Salesman Problem C program of Regula Falsi method to find root C program of Hopfield Networks | C code champ C program of Shell Sort Algorithm | C code champ C program for Radix Sort Algorithm C program for Pigeonhole Sort Algorithm | C code champ C program of Pancake Sort Algorithm | C code champ C program for Insertion Sort Algorithm C program of Heap Sort Algorithm | C code champ C program of Gnome Sort Algorithm | C code champ C program for Counting Sort Algorithm C program for Comb Sort Algorithm | C code champ C program for Cocktail Sort algorithm | C code champ C program for quick sort algorithm C program for Bucket sort algorithm

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

4 Comments
Mr Coder August 20, 2012 at 8:38 pm - Reply testing

Mr Coder August 20, 2012 at 8:39 pm - Reply comments level two testing..

collectiva August 22, 2012 at 10:55 am - Reply It is very useful for the Beginners.

Mr Coder August 23, 2012 at 8:53 pm - Reply thanks!

Leave A Response
Name (required)

Email (required)

Website

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Comment

Post Comment

Recent Articles
C program to print reverse pyramid of alphabets Download Turbo C++ for Windows 7 Full screen bug fixed C program to Print Pascal Triangle | C code champ C code to draw pyramid using stars | C code champ C program of Newton Backward Interpolation Formula C program of Booths multiplication algorithm

Latest Feeds
C program to print reverse pyramid of alphabets Download Turbo C++ for Windows 7 Full screen bug fixed C program to Print Pascal Triangle | C code champ C code to draw pyramid using stars | C code champ C program of Newton Backward Interpolation Formula C program of Booths multiplication algorithm

Recent Comments
download windows 7 on How to install Turbo C Compiler in Windows Tester on C program of Newton Backward Interpolation Formula Mr Coder on C program of Newton Raphson Method | C code champ collectiva on C program of Newton Raphson Method | C code champ Mr Coder on C program of Newton Raphson Method | C code champ

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

Copyright 2011 -CCodeChamp. All rights reserved.

Powered by C code champ

Back to Top

open in browser PRO version

Are you a developer? Try out the HTML to PDF API

pdfcrowd.com

You might also like