C program for secant method for solving a non-linear equation

Share

Assume given function :

f(x) = 2x2+4x-10

#include <stdio.h>
#include <stdlib.h>
#include <math.h>

float f(float X){
    return 2*X*X + 4*X - 10; //change this expression according to given non linear function
}

int main()
{
    float x0,x1,x2,fx1,fx0,E,ER=0;
    
    printf("X0 : ");
    scanf("%f",&x0);
    
    
    printf("X1 : ");
    scanf("%f",&x1);
    
    printf("E : ");
    scanf("%f",&E);
    
    do{
        fx0 = f(x0);
        fx1 = f(x1);
        x2 = x1 - (fx1*(x1-x0))/(fx1-fx0);
        ER = fabs((x2-x1)/x2);
        x0 = x1;
        x1 = x2;
        
    }while(E<ER);
    
    printf("Root : %.3f",x2);

    return 0;
}

C Program for Newton-Raphson’s Method to solve a non-linear equation.

C Program for Bisection Method to solve a non-linear equation

Share
Sudeep Mishra

Sudeep Mishra

Healing

Leave a Reply

Your email address will not be published.

%d bloggers like this: