Question: Help me make a C program that will perform the Secant Method that will solve the equation f(x) = -13 - 20x +19x 2 -3x

Help me make a C program that will perform the Secant Method that will solve the equation f(x) = -13 - 20x +19x2 -3x3. The program should allow the user to input the upper and lower bounds arbitrarily but it also has to ensure that a root exists between the interval given by the user. Use an error criterion of 0.1%. Show the results of all iterations in tabular form on the screen or a text file. Submit videos showing the screen output of the program from start to finish, using five different ranges of upper and lower bounds, with at least three of them obtaining the root. Please include comments so that it will be easier for me to follow :)

C program for False Position Method, please help me alter this to Secant Method.

// Used for input & output function

#include

// Used for mathematic function

#include

// Create a function to solve

double f(double x)

{

// Return function value at x

return -13-20*x+19*x*x-3*x*x*x;

}

// Main function

int main()

{

// Used to store lower bound, upper bound & root value

float xl, xu, xr;

// Used to store iteration number

int itr = 1;

// Used to store error criterion

float e = 0.001;

// Take lower & upper bound

printf("Enter lower & upper bound of interval: ");

scanf("%f %f", &xl, &xu);

// If the guess is not contain root

if( f(xl)*f(xu) > 0.0)

{

// Print an error

printf("Error: Root not exist in interval ");

return 0;

}

// Print table header

printf(" Step\t\txl\t\txu\t\txr\t\tf(xr) ");

// Loop till error criterion occurr

while(1)

{

// Compute root valeu using false position method

xr = xl - (xl-xu) * f(xl)/(f(xl)-f(xu));

// Print values

printf("%d\t\t%f\t%f\t%f\t%f ",itr, xl, xu, xr, f(xr));

// If multiplication of function value

// at xl & xr is less than 0

if(f(xl)*f(xr) < 0)

{

// Set xu to xr

xu = xr;

}

// If multiplication of function value at xl & xr

// is greater than r equal 0

else

{

// Set xl to xr

xl = xr;

}

// INcrease iteration by 1

itr = itr + 1;

// If ansolute value of function at xr is less than e

if(fabs(f(xr)) < e)

// Exit from loop

break;

}

// Print the root

printf(" Root of the function is: %f", xr);

return 0;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!