Professional Documents
Culture Documents
ASSIGNMENT 4
TO COMPUTE ROOT OF AN EQUATION BY USING NEWTON
RAPHSON METHOD
STATEMENT:
‘Newton Raphson’ method is an iterative method and is used to find isolated roots of an equation
f(x)=0. The object of this method is to correct the approximate root x0 (say) successively to its exact
value α. Initially , a crude approximation small interval [a0 , b0] is found out in which only one root α
(say) of f(x)=0 lies.
In this method:
𝑓(𝑥0 )
𝑥𝑛+1 = 𝑥0 −
𝑓′(𝑥0 )
ALGORITHM:
PROCESS:
Step 1: The equation and it’s derivative defined by ‘macro’ F(x) and E(x)
Respectively.
[‘a’ and ‘b’ are two float type variables and initially a=0.0 and b=1.0]
Step 2.1: While (F(a)*F(b) > 0) then repeat Step 2.2 to Step 2.3
Step 2.4: Display the two integer values ‘a’ and ‘b’ in which the root lies i.e.
print “a,b”.
Step 2.5: Take the value of Error in a float type variable ‘err’.
Step 2.15: Display the value of the root correct up to 4 decimal places i.e. print “s”
Step 3: Stop
PROGRAM CODE:
#include<stdio.h>
#include<conio.h>
#include<math.h>
#define F(x) (((x)*(x)*(x))-(8*(x))-4)
#define E(x) ((3*(x)*(x))-8)
17
void main( )
{
float a=0.0,b=1.0,s=0.0,h,m,n,p=0.0,err;
while(F(a)*F(b)>0)
{
a=b;
b=b+1.0;
}
do
{
p=s;
m=F(p);
n=E(p);
h=-(m/n);
s=p+h;
printf(" %f %f %f %f\n",m,n,h,s);
} while(fabs(s-p) > err);
printf("\n -----------------------------------------------------\n");
printf("\n\n Ans: %.4f(correct upto 4 decimal places)",s);
getch( );
}
PROGRAM OUTPUT:
18
DISCUSSION:
If Єn be a tolerable error, we should terminate the iteration when |xn+1−xn| ≤Єn. Newton Raphson
Method fails when, f’(x)=0 or very small in the neighbourhood of the root. If the initial
approximation is very close to the root , then the convergence in Newton-Raphson Method is faster
than the iteration method. The initial approximation must be taken very close to the root, otherwise
the iterations may diverge. This program is not flexible i.e this program is only for the particular
function f(x)=x3−9x+1. We can not use this program to find the root of any other function.