This is my code:
void Newton(double a,double b,double eps, double (*func)(double,double))
{
double root;
double x,y;
x=a; y=b; root=y-func(y,0.5)/((func(y,0.5)-func(x,0.5))/(y-x));
double i;
int n=(15-0.5)*10+1;
for(i=0;i<n;i++)
{
while(fabs(y-x)>eps)
{
x=y;
y=root;
root=y-func(y,((double)i/10+0.6))/((func(y,((double)i/10+0.6))-func(x,((double)i/10+0.6)))/(y-x));
}
printf("The root computed by the Newton's method for w=%lf is %lf\n",((double)i/10+0.5),root);
}
}
It is only the function computing and printing roots calculated by the Newton's method of some arbitrary equation which is stated in the function 'func'. The result printed is always the same. It should differ as long as the factors in the equation change. My function is cos(x)-w*t
, where w
are numbers {0.5,0.6,...,15.0}
.
a
and b
are my initial arguments for searching the root, eps is some arbitrarily small number which is the accuracy here.