Created
March 9, 2014 12:08
-
-
Save ashim888/9446847 to your computer and use it in GitHub Desktop.
Secant Method Program
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<stdio.h> | |
#include<math.h> | |
#define e 0.001 | |
#define F(x) (2*x)-3 | |
float frac(float a) | |
{ | |
float f1; | |
f1=a*a-3*a+2; | |
return f1; | |
} | |
int main() | |
{ | |
float x1,x2,f1=0,f2,er,d; | |
printf("F(x) = x^2-3x+2\n\n"); | |
printf("Enter the value of x1: "); | |
scanf("%f",&x1); | |
printf("\nx1 = %f",x1); | |
printf("\n________________________________________________________________________________\n"); | |
printf(" x1 | x2 | f1 | f'1 | |(x2-x1)/x2| | \n"); | |
printf("--------------------------------------------------------------------------------\n"); | |
do | |
{ | |
f1=frac(x1); | |
d=F(x1); | |
x2=x1-(f1/d); | |
er=fabs((x2-x1)/x2); | |
printf(" %f | %f | %f | %f | %f | \n",x1,x2,f1,d,er); | |
x1=x2; | |
} | |
while(er>e); | |
printf("--------------------------------------------------------------------------------\n\n"); | |
printf("\n Root of the equation is: %f\n",x2); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment