Secant Method PDF

Title Secant Method
Course Numerical and Engineering Optimization Methods
Institution Delhi Technological University
Pages 9
File Size 493.1 KB
File Type PDF
Total Downloads 90
Total Views 146

Summary

Numerical and Engineering Optimization Methods...


Description

Secant Meth Method od Secant method is an iterative tool of mathematics and numerical methods to find the approximate root of polynomial equations. During the course of iteration, this method assumes the function to be approximately linear in the region of interest.

Although secant method was developed independently, it is often considered to be a finite difference approximation of Newton’s method. But, being free from derivative, it is generally used as an alternative to the latter method.

Mathematical Derivation of Secant Method: Consider a curve f(x) = 0 as shown in the figure below:

Secant method estimates the point of intersection of the curve and the X- axis (i.e. root of the equation that represents the curve) as exactly as possible. For that, it uses succession of roots of secant line in the curve.

Assume x0 and x1 to be the initial guess values, and construct a secant line to the curve through (x0, f(x0)) and (x1, f(x1)). The equation of this secant line is given by:

If x be the root of the given equation, it must satisfy: f(x) = 0 or y= 0. Substituting y = 0 in the above equation, and solving for x, we get:

Now, considering this new x as x2, and repeating the same process for x2, x3, x4, . . . . we end up with the following expressions:

This is the required formula which will also be used in the program for secant method in Matlab.

Secant Method Algorithm: 1. Start 2. Get values of x0, x1 and e *Here x0 and x1 are the two initial guesses e is the stopping criteria, absolute error or the desired degree of accuracy* 3. Compute f(x0) and f(x1) 4. Compute x2 = [x0*f(x1) – x1*f(x0)] / [f(x1) – f(x0)] 5. Test for accuracy of x2 If [ (x2 – x1)/x2 ] > e, *Here [ ] is used as modulus sign* then assign x0 = x1 and x1 = x2 goto step 4 Else, goto step 6 6. Display the required root as x2. 7. Stop

Secant Method Flowchart:

C program of secant method #include float f(float x) { return(x*x*x-4); // f(x)= x^3-4 } float main() { float a,b,c,d,e; int count=1,n; printf("\n\nEnter the values of a and b:\n"); //(a,b) must contain the solution. scanf("%f%f",&a,&b); printf("Enter the values of allowed error and maximun number of iterations:\n"); scanf("%f %d",&e,&n); do { if(f(a)==f(b)) { printf("\nSolution cannot be found as the values of a and b are same.\n"); return; } c=(a*f(b)-b*f(a))/(f(b)-f(a)); a=b; b=c; printf("Iteration No-%d x=%f\n",count,c); count++; if(count==n) { break; } } while(fabs(f(c))>e); printf("\n The required solution is %f\n",c); }

OUTPUT

When the values for a and b, the initial guesses, are entered same, the solution can’t be obtained. In such case, enter different values for a and b such that f(a) and f(b) are not equal.

Secant Method in MATLAB: % Secant Method in MATLAB a=input('Enter function:','s'); f=inline(a) x(1)=input('Enter first point of guess interval: '); x(2)=input('Enter second point of guess interval: ');

n=input('Enter allowed Error in calculation: '); iteration=0; for i=3:1000 x(i) = x(i-1) - (f(x(i-1)))*((x(i-1) - x(i-2))/(f(x(i-1)) - f(x(i-2)))); iteration=iteration+1; if abs((x(i)-x(i-1))/x(i))*100...


Similar Free PDFs