1. Home
  2. Docs
  3. Numerical Methods
  4. Solution of Nonlinear Equations
  5. Secant Method

Secant Method

Introduction

Algorithm

Codes

C ProgramJS
#include <stdio.h>
#include <math.h>
#define f(x) (pow(x, 3) - 18)
int main()
{
    float x0, x1, x2, error;
    int i = 0;
    printf("Input Two Approximations: ");
    scanf("%f %f", &x0, &x1);
    printf("Ite\tX0\t\tX1\t\tf(X0)\t\tf(X1)\t\tError\n");
    do
    {
        x2 = ((x0 * f(x1)) - ((x1)*f(x0))) / ((f(x1) - f(x0)));
        printf("%2d\t%4.6f\t%4.6f\t%4.6f\t%4.6f\t%4.6f\n", i++, x0, x1, f(x0), f(x1), error);
        error = fabs((x2) - (x1));
        x0 = x1;
        x1 = x2;
    } while (error > 0.00005);
    return 0;
}
Was this article helpful to you? Yes No

How can we help?

Leave a Reply

Your email address will not be published. Required fields are marked *