Home » C Programs » Newton Raphson Method Program in C

# Newton Raphson Method Program in C

Newton raphson method program in c. In the c programming language, this program implements the Newton Raphson method for finding the real root of a nonlinear equation. The Newton–Raphson technique, named after Isaac Newton and Joseph Raphson, is a root-finding procedure in numerical analysis that gives successively improved approximations to the roots of a real-valued function.

## Newton Raphson is Fast and Why

The Newton technique is a higher-order method that results in a more accurate approximation of your function. In most cases, the Newton technique precisely minimises the second order approximation of a function f.

The Newton–Raphson technique is a root-finding algorithm named after Isaac Newton and Joseph Raphson that gives successively improved approximations to the roots of a real-valued function.

## Math Header File in C

math. h is a header file in the C programming language’s standard library that is used for basic mathematical operations. The majority of the functions make use of floating point numbers. A math function is defined as a relationship that maps elements from one set (A) to another (B), with each element of the first set mapped to only one element of the second set.

## Stdlib.h in C

stdlib. h is a general-purpose standard header that includes Dynamic Memory Allocation functions and other Standard Functions. The getch() function necessitates the inclusion of the stdlib header. Library functions are used to execute the program like newton raphson method program in c language for beginners.

## Data Types in C Program

In C, data types refer to a comprehensive system for declaring variables or functions of various types. A variable’s type determines how much storage space it takes up and how the bit pattern stored is interpreted.

A data type is a property associated with a piece of data that instructs a computer system on how to interpret its value. Understanding data types ensures that data is collected in the desired format and that each property’s value is as expected.

## Newton Raphson Method Program in C

``````//Newton Raphson Method Program in C
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
#define f(x) 3*x - cos(x) -1
#define g(x) 3 + sin(x)
void main()
{
float x0, x1, f0, f1, g0, e;
int step = 1, N;
clrscr();
printf("\nEnter initial guess\n");
scanf("%f", &x0);
printf("Enter tolerable error\n");
scanf("%f", &e);
printf("Enter maximum iteration\n");
scanf("%d", &N);
printf("\nStep\t\tx0\t\tf(x0)\t\tx1\t\tf(x1)\n");
do
{
g0 = g(x0);
f0 = f(x0);
if(g0 == 0.0)
{
printf("Mathematical Error");
exit(0);
}
x1 = x0 - f0/g0;
printf("%d\t\t%f\t%f\t%f\t%f\n",step,x0,f0,x1,f1);
x0 = x1;
step = step+1;
if(step > N)
{
printf("Not Convergent");
exit(0);
}
f1 = f(x1);
}
while(fabs(f1)>e);
printf("\nRoot is %f", x1);
getch();
}

``````

Enter initial guess
45
Enter tolerable error
4
Enter maximum iteration
2

Step x0 f(x0) x1 f(x1)
1 45.000000 133.474670 10.339390 0.000000
2 10.339390 30.628267 -3.534155 30.628267
Not Convergent