Secantmethodexp 4
Secantmethodexp 4
#include<stdio.h>
#include<conio.h>
#include<math.h>
#include<stdlib.h>
void main()
{
float x0, x1, x2, f0, f1, f2, e;
int step = 1, N;
clrscr();
/* Inputs */
printf("\nEnter initial guesses:\n");
scanf("%f%f", &x0, &x1);
printf("Enter tolerable error:\n");
scanf("%f", &e);
printf("Enter maximum iteration:\n");
scanf("%d", &N);
printf("%d\t\t%f\t%f\t%f\t%f\
n",step,x0,x1,x2, f2);
x0 = x1;
f0 = f1;
x1 = x2;
f1 = f2;
step = step + 1;
if(step > N)
{
printf("Not Convergent.");
exit(0);
}
}while(fabs(f2)>e);
Step x0 x1 x2 f(x2)
1 1.000000 2.000000 2.200000
1.248001
2 2.000000 2.200000 2.088968 -
0.062124
3 2.200000 2.088968 2.094233 -
0.003554
4 2.088968 2.094233 2.094553
0.000012
5 2.094233 2.094553 2.094552
0.000001