#include <stdio.h>
#include <math.h>
double f(double x)
{
return pow(x,2)-3*x+2; //Given equation may will be changed
}
double ff(double x)
{
return 2*x-3; //Given equation may will be changed
}
int main()
{
float x1,x2,x0,E;
printf("Enter initial value of X: ");
scanf("%f",&x1);
printf("Enter the tolerance value: ");
scanf("%f",&E); // Tolerance may vary 0.0001
do
{
x0 = x1;
x1 = x0 - (f(x0)/ff(x0));
}while(fabs((x1-x0)/x1)>E);
printf("Root is: %.2f\n",x0);
return 0;
}
//Reference : Nemerical Methods by E Balagurusamy (2016-2017) pages (146 -147)
#include <math.h>
double f(double x)
{
return pow(x,2)-3*x+2; //Given equation may will be changed
}
double ff(double x)
{
return 2*x-3; //Given equation may will be changed
}
int main()
{
float x1,x2,x0,E;
printf("Enter initial value of X: ");
scanf("%f",&x1);
printf("Enter the tolerance value: ");
scanf("%f",&E); // Tolerance may vary 0.0001
do
{
x0 = x1;
x1 = x0 - (f(x0)/ff(x0));
}while(fabs((x1-x0)/x1)>E);
printf("Root is: %.2f\n",x0);
return 0;
}
//Reference : Nemerical Methods by E Balagurusamy (2016-2017) pages (146 -147)
No comments:
Post a Comment