Originally Posted by
Daved
Yes, please post the code that exhibits that behavior. You should be able to make a small example that shows the error. If you can't make a small example, then the problem is somewhere in the code you're not showing.
O.K. Daved, this is the program
Code:
#include<stdio>
#include<stlib>
#include<iostream>
#include<math>
#define PI 3.14159265358979324
using namespace std;
float foriginal(float x)
{
float z= 1/2.0-x*tan(x)+x
return(z);
}
float iterar(int n)
{
float a,b,xn,x,c,eps;
eps=0.001;
c= (float) (2*n+1)*PI/2.0-PI/180.0;// when i==1 the error appears!!!!
xn=c;
do
{
x=xn;
xn=foriginal(x);
}
while (fabs(xn-x)>eps);
printf("the root is %9.7f ,f(x)=%9.7f\n",x,foriginal(x)-x);
}
int main()
{
int i; float a,b;
for(i=0;i<10;i++)
{
iterar(i);
}
}//end program