各位大虾,我这c语言程序哪错了?

来源:百度知道 编辑:UC知道 时间:2024/05/18 01:52:17
(求解矩阵最大和最小特征值)返回结果是floating point error:domain谢谢了!
#define N 501
#define B 0.16
#define C -0.064
#define E 0.000000000001
#include<stdio.h>
#include<math.h>

double c[6][N+1];
double min(double a,double b)
{return a<b?a:b;}
double max(double a,double b)
{return a>b?a:b;}

void main()

{ /*ju zhen chun chu*/
double a[N+1],r[N+1],rs,r1,rm,rm1,rm2,y[N+1];
int i,j,k,t,m,n,s;
double u[N+1],n1,b1,b2;
double b[6][N+1];
s=2;
for(i=1;i<N+1;i++)
a[i]=(1.64-0.024*i)*sin(0.2*i)-0.64*exp(0.1/i); /*调用函数*/
for(i=0;i<=5;i++)
for(j=0;j<=N;j++)
c[i][j]=0;
for(j=3;j<=N;j++)
c[1][j]=C;
for(j=2;j<=N;j++)
c[2][j]=B;
for(j=1;j<=N;j++)
c[3][j]=a[j];
for(j=1;j<=N-1;j++)
c[4][j]=B;
for(j=1;j<=N-2;j++)
c[5][j]=C;

程序编译通过,但是运行出现非法操作。
在第50行
for(t=1;t<=N;t++)
{
printf("t=%d, (j-t+s+1)=%d\n",t,j-t+s+1); //这句是我加上去的
u[j]=u[j]+c[j-t+s+1][t]*y[t];
}

运行结果
t=1, (j-t+s+1)=3
t=2, (j-t+s+1)=2
t=3, (j-t+s+1)=1
t=4, (j-t+s+1)=0
t=5, (j-t+s+1)=-1
t=6, (j-t+s+1)=-2
t=7, (j-t+s+1)=-3
t=8, (j-t+s+1)=-4
t=9, (j-t+s+1)=-5
t=10, (j-t+s+1)=-6 这里出现非法操作

从前面程序来看,s=2不变, 也就是说 是j-t+2+1
c为一数组,出现负数下标,不非法操作才怪。。。