高手帮我看一下这个C语言小程序错在哪里了 50
#include<stdio.h>#include<math.h>#defineN2#defineM3floatout_num[N][2*M];floatave[2*M]...
#include <stdio.h>
#include <math.h>
#define N 2
#define M 3
float out_num[N][2*M];
float ave[2*M],ave_a[M],ave_b[M],ave_ab[M];
float del[M],var[M];
float err1_a[M],err1_b[M],err1_ab[M],err2_ab[M];
float x[M],ya[M];
void aver(void)
{int i,j;
float s;
for(j=0;j<2*M;j++)
{for(i=0,s=0;i<N;i++)
s+=out_num[i][j];
ave[j]=s/(float)N;
}
}
void line_a(void)
{float k,b;
int i;
float x1=x[0],x2=x[M-1];
float y1=ave_ab[0],y2=ave_ab[M-1];
float x[M],ya[M];
k=(float)(y1-y2)/(x1-x2);
b=(float)(y1+y2-k*(x1+x2))/2;
for(i=0;i<M;i++)
ya[i]=k*x[i]+b;
}
void s_var(void)
{int i,j;
float s,t;
s=0;
for(j=0;j<2*M;j++)
{
{for(i=0;i<N;i++)
s+=out_num[i][j]*out_num[i][j];
}
t=s/(float)N-ave[j]*ave[j];
var[j]=sqrt(t);
}
}
float highest_del()
{float high_del;
int i;
high_del=del[0];
for(i=1;i<M;i++)
{if(high_del>del[i]) high_del=del[i];}
return(high_del);
}
float highest_erra()
{float high_erra;
int i;
high_erra=err1_a[0];
for(i=1;i<M;i++)
{if(high_erra>err1_a[i]) high_erra=err1_a[i];}
return(high_erra);
}
float highest_errb()
{float high_errb;
int i;
high_errb=err1_b[0];
for(i=1;i<M;i++)
{if(high_errb>err1_b[i]) high_errb=err1_b[i];}
return(high_errb);
}
void main( )
{float Yh,Yr,Yl,Ylh,Yfs,A;
float a,b,c,d,e,s,t;
int i,j;
printf("Please input xbers:%8.5f\n");
for(i=0;i<M;i++)
scanf("%f",&x[i]);
printf("Please input out_numbers:%8.5f\n");
for(i=0;i<N;i++)
for(j=0;j<2*M;j++)
scanf("%f",&out_num[i][j]);
aver( );
for(i=0;i<M;i++)
ave_a[i]=ave[i];
for(i=M,j=0;i<2*M;i++)
ave_b[j++]=ave[i];
for(i=0,s=0;i<M;i++)
{s=ave_a[i]+ave_b[i];
ave_ab[i]=s/2;
}
for(i=0;i<M;i++)
del[i]=ave_b[i]-ave_a[i];
line_a( );
for(i=0;i<M;i++)
{err1_a[i]=ya[i]-ave_a[i];
err1_b[i]=ave_b[i]-ya[i];
err1_ab[i]=ave_ab[i]-ya[i];
}
s_var( );
for(i=0,s=0,t=0;i<2*M;i++)
{s+=var[i]*var[i];
t+=var[i];
}
e=sqrt(s/N-(t/N)* (t/N));
a=highest_erra();
b=highest_errb();
c=(float)((a-b)/2);
for(i=0;i<M;i++)
{err2_ab[i]=err1_ab[i]+c;}
d=highest_del( );
Yfs=ave_ab[M-1]-ave_ab[0];
Yh=d/Yfs;
Yr=3*e/Yfs ;
Yl=c/Yfs;
Ylh=(a+b)/(2*Yfs);
A=Ylh+Yr;
printf("Nh=: %8.5f\n",Yh);
printf("Yr=: %8.5f\n",Yr);
printf("Yl=: %8.5f\n",Yl);
printf("Ylh=: %8.5f\n",Ylh);
printf("A=: %8.5f\n",A);
getchar();
} 展开
#include <math.h>
#define N 2
#define M 3
float out_num[N][2*M];
float ave[2*M],ave_a[M],ave_b[M],ave_ab[M];
float del[M],var[M];
float err1_a[M],err1_b[M],err1_ab[M],err2_ab[M];
float x[M],ya[M];
void aver(void)
{int i,j;
float s;
for(j=0;j<2*M;j++)
{for(i=0,s=0;i<N;i++)
s+=out_num[i][j];
ave[j]=s/(float)N;
}
}
void line_a(void)
{float k,b;
int i;
float x1=x[0],x2=x[M-1];
float y1=ave_ab[0],y2=ave_ab[M-1];
float x[M],ya[M];
k=(float)(y1-y2)/(x1-x2);
b=(float)(y1+y2-k*(x1+x2))/2;
for(i=0;i<M;i++)
ya[i]=k*x[i]+b;
}
void s_var(void)
{int i,j;
float s,t;
s=0;
for(j=0;j<2*M;j++)
{
{for(i=0;i<N;i++)
s+=out_num[i][j]*out_num[i][j];
}
t=s/(float)N-ave[j]*ave[j];
var[j]=sqrt(t);
}
}
float highest_del()
{float high_del;
int i;
high_del=del[0];
for(i=1;i<M;i++)
{if(high_del>del[i]) high_del=del[i];}
return(high_del);
}
float highest_erra()
{float high_erra;
int i;
high_erra=err1_a[0];
for(i=1;i<M;i++)
{if(high_erra>err1_a[i]) high_erra=err1_a[i];}
return(high_erra);
}
float highest_errb()
{float high_errb;
int i;
high_errb=err1_b[0];
for(i=1;i<M;i++)
{if(high_errb>err1_b[i]) high_errb=err1_b[i];}
return(high_errb);
}
void main( )
{float Yh,Yr,Yl,Ylh,Yfs,A;
float a,b,c,d,e,s,t;
int i,j;
printf("Please input xbers:%8.5f\n");
for(i=0;i<M;i++)
scanf("%f",&x[i]);
printf("Please input out_numbers:%8.5f\n");
for(i=0;i<N;i++)
for(j=0;j<2*M;j++)
scanf("%f",&out_num[i][j]);
aver( );
for(i=0;i<M;i++)
ave_a[i]=ave[i];
for(i=M,j=0;i<2*M;i++)
ave_b[j++]=ave[i];
for(i=0,s=0;i<M;i++)
{s=ave_a[i]+ave_b[i];
ave_ab[i]=s/2;
}
for(i=0;i<M;i++)
del[i]=ave_b[i]-ave_a[i];
line_a( );
for(i=0;i<M;i++)
{err1_a[i]=ya[i]-ave_a[i];
err1_b[i]=ave_b[i]-ya[i];
err1_ab[i]=ave_ab[i]-ya[i];
}
s_var( );
for(i=0,s=0,t=0;i<2*M;i++)
{s+=var[i]*var[i];
t+=var[i];
}
e=sqrt(s/N-(t/N)* (t/N));
a=highest_erra();
b=highest_errb();
c=(float)((a-b)/2);
for(i=0;i<M;i++)
{err2_ab[i]=err1_ab[i]+c;}
d=highest_del( );
Yfs=ave_ab[M-1]-ave_ab[0];
Yh=d/Yfs;
Yr=3*e/Yfs ;
Yl=c/Yfs;
Ylh=(a+b)/(2*Yfs);
A=Ylh+Yr;
printf("Nh=: %8.5f\n",Yh);
printf("Yr=: %8.5f\n",Yr);
printf("Yl=: %8.5f\n",Yl);
printf("Ylh=: %8.5f\n",Ylh);
printf("A=: %8.5f\n",A);
getchar();
} 展开
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询