Beruflich Dokumente
Kultur Dokumente
ASSIGNMENT 6
TO COMPUTE ROOT OF AN EQUATION BY USING SECANT METHOD
STATEMENT:
In numerical analysis, the secant method is a root-finding algorithm that uses a succession
of roots of secant lines to better approximate a root of a function f. The secant method can
be thought of as a finite difference approximation of Newton's method.
The secant method is defined by the recurrence relation:
𝑓(𝑥𝑛 )
𝑥𝑛+1 = 𝑥𝑛 − (𝑥𝑛 − 𝑥0 )
𝑓(𝑥𝑛 )−𝑓(𝑥0 )
As can be seen from the recurrence relation, the secant method requires two initial values,
x0 and x1, which should ideally be chosen to lie close to the root.
ALGORITHM:
PROCESS:
[‘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 and 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’.
[End of ‘If’]
Step2.11: Set y x
[End of ‘If’]
[End of ‘Else’]
Step 2.19: Display the value of the root correct up to 4 decimal places i.e. print “x”
Step 3: Stop
PROGRAM CODE:
#include <stdio.h>
#include <conio.h>
#include <math.h>
float f(float x)
{
return ((3*x)-sin(x)-1);
}
void main( )
{
while(f(a)*f(b)>0)
{
a=a-1.0;
b=b+1.0;
26
}
printf("\n\tRoot lies between: %f and %f",a,b);
scanf("%f",&err);
printf("\n\t----------------------------------------\n");
if(f(a) > 0)
{
a=a+b;
b=a-b;
a=a-b;
}
do
y=x;
x=b-((f(b)/(f(b)-f(a)))*(b-a));
if(f(x) < 0)
a=x;
else
b=x;
printf("\n\t%f\t%f\t%f",a,b,x);
printf("\n\t----------------------------------------\n");
getch( );
OUTPUT:
27
DISCUSSION:
The secant method does not require that the root remain bracketed like the bisection
method does, and hence it does not always converge. The false position method (or regula
falsi) uses the same formula as the secant method. However, it does not apply the formula
on and , like the secant method, but on and on the last iterate such that
and have a different sign. This means that the false position method always
converges. The recurrence formula of the secant method can be derived from the formula
for Newton's method. If we compare Newton's method with the secant method, we see that
Newton's method converges faster.