解释下错误!!
代码:#include <iostream>
#include <math.h>
using namespace std;
double x[4]={0.56160,0.56280,0.56401,0.56521};
double y[4]={0.82741,0.82639,0.82577,0.82495};
double f1[3];
double f2[2];
double f3;
double n1()
{
int i;
for(i=1;i<4;i++)
{
f1[i]=(y[i+1]-y[i])/(x[i+1]-x[i]);
cout<<f1[i]<<endl;
}
return(0);
}
double n2()
{
int i;
for(i=1;i<3;i++)
{
f2[i]=(f1[i+1]-f1[i])/(x[i+1]-x[i]);
cout<<f2[i]<<endl;
}
return(0);
}
double n3()
{
f3=(f2[2]-f2[1])/(x[2]-x[1]);
cout<<f3<<endl;
return(0);
}
double N(double x)
{
n1();
n2();
n3();
double N;
N=y[1]
+f1[1]*(x-x[1])
+f2[1]*(x-x[1])*(x-x[2])
+f3*(x-x[1])*(x-x[2])*(x-x[3]);
cout<<N<<endl;
return 0;
}
main()
{
double x;
cin>>x;
N(x);
return 0;
}
有六个相同的错误:E:\C++\Newton插值\newton.cpp(44) : error C2109: subscript requires array or pointer type
谢谢了!!