Professional Documents
Culture Documents
ACTIVITY (Secant Method) 3
ACTIVITY (Secant Method) 3
Submitted to
Engr. Sime Camanse
Instructor
Rachelle Mae C. Tomo
BSCE 3A
I. Introduction
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. However, the secant method predates Newton's
method by over 3000 years.
The secant method does not require that the root remain bracketed, like the bisection method does,
and hence it does not always
Use any programming tool (Microsoft Excel, Matlab, Python, etc.) to locate the root of f(x) =
Ax^4+Bx^3+Cx^2 + Dx + E
Step 1: Choose i=1
#include<iostream>
#include<iomanip>
/* 'cmath' header file is included for pow and fabs functions */
#include<cmath>
double f(double );
int main()
double x0,x1,e;
int iteration_no=0;
cin>>x0;
cin>>x1;
cin>>e;
cout<<"i"<<setw(16)<<"x0"<<setw(12)<<"x1"<<setw(18)<<"xm0"<<setw(18)<<"f2"<<endl;
return 0;
double xm0,xm1,k,f1,f2;
do
cout<<*iteration_no<<setw(16)<<x0<<setw(12)<<x1<<setw(18)<<xm0<<setw(18)<<f2<<endl;
/* calulating and storing values of f(x1) and f(x2) into f1 and f2 resp */
f1=f(x0);
f2=f(x1);
*iteration_no+=1;
k = f(x0) * f(xm0);
x0 = x1;
x1 = xm0;
if (k == 0)
break;
}while( fabs(xm1 - xm0) >= e); /* check if the error is greater than the desired accuracy. fabs function is
used to return non-negative float value of its argument */
return xm0;
/* write the equation whose roots are to be determined. Here we are using equation as x^3 + x - 1 */
return res;