修改以后的代码:
int main()
{int i
float A[4],B[3],C[2],D,
x[5]={0.4,0.55,0.65,0.8,0.9},y[5]={0.41075,0.57815,0.69675,0.88811,1.02652}
for(i=0i<5i++)
A[i]=(y[i+1]-y[i])/(x[i+1]-x[i])
for(i=0i<4i++)
printf("A[%d]=%f\t",i,A[i])
for(i=0i<4i++)
B[i]=(A[i+1]-A[i])/(x[i+2]-x[i])
for(i=0i<3i++)
printf("B[%d]=%f\t",i,B[i])
for(i=0i<3i++)
C[i]=(B[i+1]-B[i])/(x[i+3]-x[i])
for(i=0i<2i++)
printf("C[%d]=%f\t",i,C[i])
D=(C[i+1]-C[i])/(x[4]-x[0])
printf("D=%f\t",D)
return 0
}
修改以后的结论:
A[0]=1.116000 A[1]=1.186001 A[2]=1.275733 A[3]=1.384101 B[0]=0.280003 B[1]=0.358930 B[2]=0.433471 C[0]=0.197316 C[1]=0.212976 D=-0.397131
你的程序默认输入的是列向量,你输入的x,y是行向量,所以出错另外程序第四行“P(:,2)=y”应为“p(:,2)=y”
>>x=[01246]
>>y=[19233259]
>>chashang(x,y)
ans =
01.00008.00003.0000 -2.75001.8750
1.00009.0000 14.0000 -8.00008.5000 0
2.0000 23.0000 -10.0000 34.5000 0 0
4.00003.0000 128.0000 0 0 0
6.0000 259.0000 0 0 0 0
>>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)