#include
const int N=200;
//帶入原函式後所得的值
double f(float x)
{
return (x*x*x-1.8*x*x+0.15*x+0.65);
}
//帶入一階導函式後所得的值
double f1(double x)
return (3*x*x-3.6*x+0.15);
//牛頓迭代函式
double F(double x)
double x1;
x1=x-1.0*f(x)/f1(x);
return (x1);
void main()
double x0,D_value,x1,y[4];
int k=0,count=0;
for(;;)
if(count==3)break;
cout
cin>>x0;
do
k++;
x1=F(x0);
D_value=fabs(x1-x0);
x0=x1;
while((D_value>0.000005)&&(k
for(int j=0,flag=0;j
#include
#include
#include
const int N=200;
//帶入原函式後所得的值
double f(float x)
{
return (x*x*x-1.8*x*x+0.15*x+0.65);
}
//帶入一階導函式後所得的值
double f1(double x)
{
return (3*x*x-3.6*x+0.15);
}
//牛頓迭代函式
double F(double x)
{
double x1;
x1=x-1.0*f(x)/f1(x);
return (x1);
}
void main()
{
double x0,D_value,x1,y[4];
int k=0,count=0;
for(;;)
{
if(count==3)break;
cout
cin>>x0;
do
{
k++;
x1=F(x0);
D_value=fabs(x1-x0);
x0=x1;
}
while((D_value>0.000005)&&(k
for(int j=0,flag=0;j