| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 416 人关注过本帖
标题:解释下错误!!
只看楼主 加入收藏
leeloo2
Rank: 1
等 级:新手上路
帖 子:6
专家分:0
注 册:2006-6-28
收藏
 问题点数:0 回复次数:2 
解释下错误!!
代码:
#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
谢谢了!!
搜索更多相关主题的帖子: 解释 
2006-11-20 09:34
nuciewth
Rank: 14Rank: 14Rank: 14Rank: 14
来 自:我爱龙龙
等 级:贵宾
威 望:104
帖 子:9786
专家分:208
注 册:2006-5-23
收藏
得分:0 

数组下标越界.
f1[3];
for(i=1;i<4;i++)
{
f1[i]=(y[i+1]-y[i])/(x[i+1]-x[i]);
cout<<f1[i]<<endl;

}
f2[2]同.


倚天照海花无数,流水高山心自知。
2006-11-20 10:37
smartwind
Rank: 1
等 级:新手上路
威 望:1
帖 子:277
专家分:0
注 册:2006-11-13
收藏
得分:0 
数组下标如楼上所述,应该是0到n-1
#include <iostream>
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=0;i<3;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=0;i<2;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 t) //函数中使用了全局变量,因此不要让局部变量与全局变量同名
{
n1();
n2();
n3();
double N;
N=y[1]
+f1[1]*(t-x[1])
+f2[1]*(t-x[1])*(t-x[2])
+f3*(t-x[1])*(t-x[2])*(t-x[3]);
cout<<N<<endl;
return 0;
}
int main() //C++必须明确写出类型名
{
double x;
cin>>x;
N(x);
return 0;
}

2006-11-20 12:11
快速回复:解释下错误!!
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.018990 second(s), 8 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved