回复 6楼 我菜119
*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<time.h>
#include"v_quatization.h"
#include"dist.h"
#include"spa.h"
#include"sample_g.h"
#include"p_history.h"
#define Nagent 147
#define Nanchor 6
/*已知坐标的节点位置*/
const struct position anchor[Nanchor]={{100,100},{100,200},{100,300},{300,100},{300,200},{300,300}};
/**基站位置固定在中心*/
const double b_x=200;
const double b_y=200;
void main()
{
int i,s;
FILE *fp0,*fp;
struct position *agent_pos,agent[Nagent];
double d_agent[Nagent];
double toa[Nagent];
double err=0;
agent_pos=0;
/*调用g_s()函数,获得存储了相应用于运算的样值,即原来的i=1:1:50*/
void g_s();
/*调用g_p(),获得初始码书,用于矢量量化*/
void g_p();
/*打开文件,以准备更新矢量量化所需的各个样值*/
/*读取需要定位的点的真实位置和测量距离测量时间*/
fp=fopen("C:\\agent_pos.txt","r");
if(fp==NULL)
{
printf("cannot opent the file \n");
exit(0);
}
for(i=0;i<Nagent;i++)
{
fscanf(fp,"%lf,%lf,%lf,%lf\n",&agent[i].x,&agent[i].y,&d_agent[i],&toa[i]);
}
agent_pos=spa(d_agent[Nagent],toa[Nagent]);
/*计算误差,并更新w_samp.txt*/
fp0=fopen("C:\\w_samp.txt","w");
if(fp0==NULL)
{
printf("cannot opent the file \n");
exit(0);
}
for(i=0;i<Nagent;i++)
{
fprintf(fp0,"%lf,%lf,%lf,%lf\n",(*(agent_pos+i)).x,(*(agent_pos+i)).y,d_agent[i],toa[i]);
err=dist((*(agent_pos+i)).x,(*(agent_pos+i)).y),&agent[i].x,agent[i].y))*dist((*(agent_pos+i)).x,(*(agent_pos+i)).y),&agent[i].x,agent[i].y));
}
rewind(fp0);
err/=Nagent;
printf("the error of location is: %lf\n",err);
fclose(fp);
fclose(fp0);
}
这是主函数