You are on page 1of 4

15

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:

INPUT: An equation F(x)= x3 −(8x) – 4 and it’s derivative


E(x)= 3x2 − 8
OUTPUT: An isolated root xn

PROCESS:

Step 1: The equation and it’s derivative defined by ‘macro’ F(x) and E(x)
Respectively.

Step 2: Create the function “void main()”


16

[‘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.2: Set a  b

Step 2.3: Set b  b+1.0


[End of Step 2.1 ‘While’ loop]

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.6: Set s  a

Step 2.7: Do Step 2.8 to Step 2.14

Step 2.8: Set p  s

Step 2.9: Set m  F(p)

Step 2.10: Set n  E(p)

Step 2.11: Set h  −(m/n)

Step 2.12: Set s  p+h

Step 2.13: Print “m,n,h,s”

Step 2.14: While (fabs(s-p)>err) then go to Step 2.7 repeatedly

[End of Step 2.7 ‘do-while’ loop]

Step 2.15: Display the value of the root correct up to 4 decimal places i.e. print “s”

[End of the function “void main()”].

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;
}

printf("\n Lower bound and upper bound: %f and %f",a,b);


printf("\n\n Enter error: ");
scanf("%f",&err);
printf("\n\n f(xn) f'(xn) h x(n+1)\n");
printf("\n -----------------------------------------------------\n");
s=a;

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.

You might also like