显式四阶Adams方法 代码中出现subscript requires array or pointer type问题,是什么意思?0
wzx12232015.07.25浏览53次分享举报
#include"stdio.h"
#include"math.h"
#include"iostream.h"
#include"iomanip.h"
double f(double x,double y)
{
return -x*y*y;
}
void main()
{
int n,i;
double h,k1,k2,k3,k4;
n=10;
double *x=new double [n+1];
double *y=new double [n+1];
h=1.0/n;
y[0]=2;
for(i=0;i<=n;i++)
{
x[i]=i*h;
if(i<4)
{
k1=f(x[i],y[i]);
k2=f(x[i]+h/2,y[i]+k1*h/2);
k3=f(x[i]+h/2,y[i]+k2*h/2);
k4=f(x[i]+h,y[i]+k3*h);
y[i+1]=y[i]+(k1+2*k2+2*k3+k4)*h/6;
cout<
}
else
{
y[i]=y[i-1]+h*(55*f[x[i-1],y[i-1]]-59f[x[i-2],y[i-2]]+37*f[x[i-3],y[i-3]]-9*f[i-4],y[i-4])/24;
cout<
}
}
}
else
{
y[i]=y[i-1]+h*(55*f[x[i-1],y[i-1]]-59f[x[i-2],y[i-2]]+37*f[x[i-3],y[i-3]]-9*f[i-4],y[i-4])/24;
cout<
}这个部分有问题,但我看不出来!!!!
https://www.gofarlic.com\1\1.cpp(33) : error C2109: subscript requires array or pointer type
https://www.gofarlic.com\1\1.cpp(33) : error C2297: '*' : illegal, right operand has type 'double (__cdecl *)(double,double)'
https://www.gofarlic.com\1\1.cpp(33) : error C2059: syntax error : 'bad suffix on number'
https://www.gofarlic.com\1\1.cpp(33) : error C2146: syntax error : missing ')' before identifier 'f'
https://www.gofarlic.com\1\1.cpp(33) : error C2059: syntax error : ')'
执行 cl.exe 时出错.