#include<stdio.h>
#include<time.h>
#include<math.h>
#include<gsl/gsl_linalg.h>
void linSys(gsl_matrix *A, gsl_vector *B, gsl_vector *X, int size ){
gsl_matrix *V = gsl_matrix_alloc(size,size);
gsl_vector *S = gsl_vector_alloc(size);
gsl_vector *work = gsl_vector_alloc(size);
gsl_linalg_SV_decomp (A, V, S, work);
gsl_linalg_SV_solve(A,V,S,B,X);
return;
}
void TEST_linSys(){
double a_data[] = { 0.18, 0.60, 0.57, 0.96,
0.41, 0.24, 0.99, 0.58,
0.14, 0.30, 0.97, 0.66,
0.51, 0.13, 0.19, 0.85 };
double b_data[] = { 1.0, 2.0, 3.0, 4.0 };
gsl_matrix_view a_view = gsl_matrix_view_array (a_data, 4, 4);
gsl_vector_view b_view = gsl_vector_view_array (b_data, 4);
gsl_vector *x = gsl_vector_alloc (4);
gsl_matrix * a = &a_view.matrix;
gsl_vector * b = &b_view.vector;
linSys(a,b,x,4);
printf("X = \n");
gsl_vector_fprintf(stdout, x,"%g");
}
void calcR(gsl_matrix_view P,gsl_vector_view E, gsl_vector *R){
double e0 = gsl_vector_get(&E.vector,0);
double e1 = gsl_vector_get(&E.vector,1);
double e2 = gsl_vector_get(&E.vector,2);
double r0 = sqrt(
pow(gsl_matrix_get(&P.matrix,0,0) + e0,2) +
pow(gsl_matrix_get(&P.matrix,0,1) + e1,2) +
pow(gsl_matrix_get(&P.matrix,0,2) + e2,2)
);
double r1 = sqrt(
pow(gsl_matrix_get(&P.matrix,1,0) + e0,2) +
pow(gsl_matrix_get(&P.matrix,1,1) + e1,2) +
pow(gsl_matrix_get(&P.matrix,1,2) + e2,2)
);
double r2 = sqrt(
pow(gsl_matrix_get(&P.matrix,2,0) + e0,2) +
pow(gsl_matrix_get(&P.matrix,2,1) + e1,2) +
pow(gsl_matrix_get(&P.matrix,2,2) + e2,2)
);
double r3 = sqrt(
pow(gsl_matrix_get(&P.matrix,3,0) + e0,2) +
pow(gsl_matrix_get(&P.matrix,3,1) + e1,2) +
pow(gsl_matrix_get(&P.matrix,3,2) + e2,2)
);
double r4 = sqrt(
pow(gsl_matrix_get(&P.matrix,4,0) + e0,2) +
pow(gsl_matrix_get(&P.matrix,4,1) + e1,2) +
pow(gsl_matrix_get(&P.matrix,4,2) + e2,2)
);
gsl_vector_set(R,0,r0);
gsl_vector_set(R,1,r1);
gsl_vector_set(R,2,r2);
gsl_vector_set(R,3,r3);
gsl_vector_set(R,4,r4);
}
void calcTAU(gsl_matrix_view P,gsl_vector *T, double v, gsl_vector *TAU){
double To = gsl_vector_get(T,0);
double val;
int m;
for(m = 1; m<5; m++){
val = v*(gsl_vector_get(T,m)-To);
gsl_vector_set(TAU,m-1,val);
}
}
void constCoef(gsl_matrix_view P,gsl_vector *TAU, gsl_matrix *COEF, gsl_vector *D){
/*
Am = (2*Xm/TAUm) - (2*X1/TAU1)
bm = (2*Ym/TAUm) - (2*Y1/TAU1)
cm = (2*Zm/TAUm) - (2*Z1/TAU1)
dm = TAUm - TAU1 - (Xm^2 + Ym^2 +Zm^2)/TAUm + (X1^2 + Y1^2 +Z1^2)/TAU1
*/
double TAUo = gsl_vector_get(TAU,0);
double P1x = gsl_matrix_get(&P.matrix,1,0);
double P1y = gsl_matrix_get(&P.matrix,1,1);
double P1z = gsl_matrix_get(&P.matrix,1,2);
double subA = 2*P1x/TAUo;
double subB = 2*P1y/TAUo;
double subC = 2*P1z/TAUo;
double subD = (pow(P1x,2) + pow(P1y,2) + pow(P1z,2))/TAUo;
int m;
double Am, Bm, Cm, Dm, Px, Py, Pz, tmp;
for(m = 2; m<5; m++){
Px = gsl_matrix_get(&P.matrix,m,0);
Py = gsl_matrix_get(&P.matrix,m,1);
Pz = gsl_matrix_get(&P.matrix,m,2);
Am = (2*Px/gsl_vector_get(TAU,m-1)) - subA;
Bm = (2*Py/gsl_vector_get(TAU,m-1)) - subB;
Cm = (2*Pz/gsl_vector_get(TAU,m-1)) - subC;
tmp = (pow(Px,2) + pow(Py,2) + pow(Pz,2))/gsl_vector_get(TAU,m-1);
Dm = gsl_vector_get(TAU,m-1) - TAUo - tmp +subD;
gsl_matrix_set(COEF,m-2,0,Am);
gsl_matrix_set(COEF,m-2,1,Bm);
gsl_matrix_set(COEF,m-2,2,Cm);
gsl_vector_set(D,m-2,Dm);
}
}
void problem1(gsl_matrix_view P, gsl_vector_view E, double v, gsl_vector *T){
gsl_vector *R = gsl_vector_alloc(5);
double vInv = 1/v;
calcR(P,E,R);
printf("R = \n");
gsl_vector_fprintf(stdout,R,"%g");
//gsl_vector_fprintf(stdout,R,"%g");
*T = *R;
gsl_vector_scale(T,vInv);
}
void problem2(gsl_matrix_view P, gsl_vector * T, double v, gsl_vector *approxE){
gsl_vector *TAU = gsl_vector_alloc(4);
gsl_vector *D = gsl_vector_alloc(3);
gsl_matrix *COEF = gsl_matrix_alloc(3,3);
calcTAU(P,T,v,TAU);
//gsl_vector_fprintf(stdout,TAU,"%g");
constCoef(P,TAU,COEF,D);
printf("COEF = \n");
gsl_matrix_fprintf(stdout,COEF,"%g");
printf("D = \n");
gsl_vector_fprintf(stdout,D,"%g");
linSys(COEF, D, approxE, 3);
}
int main(){
time_t begin = clock();
printf("\n\nParameters\n--------------------\n");
double v = 1481;
double P_data [] = { 0, 0, 0,
.1, 0, .1,
0, 1, 0,
-.1, 0, 0,
0,-.1, 0 };
double E_data[] = { -4, 6, 5 };
gsl_vector_view E = gsl_vector_view_array(E_data, 3);
gsl_matrix_view P = gsl_matrix_view_array(P_data, 5, 3);
gsl_vector *T = gsl_vector_alloc(5);
gsl_vector *approxE = gsl_vector_alloc(3);
printf("v = %g (m/s)\n",v);
printf("P = \n");
gsl_matrix_fprintf(stdout,&P.matrix,"%g");
printf("E = \n");
gsl_vector_fprintf(stdout,&E.vector,"%g");
//gsl_matrix_fprintf(stdout, &P.matrix, "%g");
printf("\nProblem1: calc T\n--------------------\n");
problem1(P,E,v,T);
printf("T = \n");
gsl_vector_fprintf(stdout,T,"%g");
printf("\nProblem2: approximate location of E\n--------------------\n");
problem2(P,T,v,approxE);
printf("approxE = \n");
gsl_vector_fprintf(stdout,approxE,"%g");
time_t end = clock();
double time_spent = ((double)(end - begin)) / CLOCKS_PER_SEC;
printf("clocks %ld\n", CLOCKS_PER_SEC);
printf("\nbegin: %g\n end: %g\n",(double)begin,(double)end);
printf("\nComputation Time (sec): %g\n",time_spent);
return 0;
}
没有合适的资源?快使用搜索试试~ 我知道了~
资源推荐
资源详情
资源评论
收起资源包目录
TDOA声源定位算法 (471个子文件)
libgsl.so.0 7.82MB
libgsl.so.0.8.0 7.82MB
libgslcblas.so.0.0.0 962KB
libgslcblas.so.0 962KB
._libgsl.so.0 4KB
._libgslcblas.so.0 4KB
._libgslcblas.so.0.0.0 4KB
._libgsl.so.0.8.0 4KB
._c_code 4KB
._gsl 4KB
._include 4KB
._lib 4KB
._makefile 4KB
._pkgconfig 4KB
libgsl.a 13.08MB
libgslcblas.a 1.6MB
._libgsl.a 4KB
._libgslcblas.a 4KB
main.c 5KB
._main.c 4KB
._utilityFunctions.c 4KB
utilityFunctions.c 98B
.DS_Store 8KB
.DS_Store 6KB
.DS_Store 6KB
._.DS_Store 4KB
._.DS_Store 4KB
._.DS_Store 4KB
gsl_cblas.h 33KB
gsl_blas.h 21KB
gsl_linalg.h 18KB
gsl_sf_bessel.h 14KB
gsl_matrix_complex_long_double.h 13KB
gsl_matrix_long_double.h 12KB
gsl_matrix_complex_float.h 12KB
gsl_matrix_ushort.h 11KB
gsl_matrix_ulong.h 11KB
gsl_matrix_uchar.h 11KB
gsl_matrix_complex_double.h 11KB
gsl_matrix_float.h 11KB
gsl_matrix_short.h 11KB
gsl_matrix_uint.h 11KB
gsl_matrix_long.h 10KB
gsl_matrix_char.h 10KB
gsl_matrix_int.h 10KB
gsl_matrix_double.h 10KB
gsl_integration.h 9KB
gsl_vector_complex_long_double.h 9KB
gsl_sf_legendre.h 9KB
gsl_randist.h 8KB
gsl_vector_complex_float.h 8KB
gsl_vector_long_double.h 8KB
gsl_odeiv.h 8KB
gsl_sf_gamma.h 7KB
gsl_vector_complex_double.h 7KB
gsl_vector_ushort.h 7KB
gsl_vector_ulong.h 7KB
gsl_vector_uchar.h 7KB
gsl_vector_uint.h 7KB
gsl_vector_short.h 7KB
gsl_vector_float.h 7KB
gsl_vector_long.h 7KB
gsl_vector_char.h 7KB
gsl_const_mksa.h 7KB
gsl_statistics_long_double.h 7KB
gsl_const_mks.h 7KB
gsl_vector_int.h 7KB
gsl_const_cgsm.h 7KB
gsl_rng.h 7KB
gsl_const_cgs.h 6KB
gsl_multimin.h 6KB
gsl_vector_double.h 6KB
gsl_statistics_float.h 6KB
gsl_multiroots.h 6KB
gsl_statistics_double.h 6KB
gsl_complex_math.h 6KB
gsl_errno.h 6KB
gsl_cdf.h 6KB
gsl_interp.h 6KB
gsl_math.h 6KB
gsl_histogram2d.h 6KB
gsl_multifit_nlin.h 5KB
gsl_sum.h 5KB
gsl_fft_complex_float.h 5KB
gsl_fft_complex.h 5KB
gsl_statistics_ushort.h 5KB
gsl_statistics_uchar.h 4KB
gsl_statistics_ulong.h 4KB
gsl_sf_hyperg.h 4KB
gsl_statistics_uint.h 4KB
gsl_sf_coulomb.h 4KB
gsl_sf_exp.h 4KB
gsl_chebyshev.h 4KB
gsl_statistics_short.h 4KB
gsl_statistics_long.h 4KB
gsl_statistics_char.h 4KB
gsl_wavelet2d.h 4KB
gsl_sf_dilog.h 4KB
gsl_sf_coupling.h 4KB
gsl_statistics_int.h 4KB
共 471 条
- 1
- 2
- 3
- 4
- 5
资源评论
qq_35930900
- 粉丝: 1
- 资源: 8
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
最新资源
- 前端开发-什么是前端开发-关于前端开发的一些相关介绍
- Sora AI-关于文生视频的使用场景说明
- suno AI文生视频的相关教程和介绍使用
- 什么是后端开发-关于后端开发的一些小介绍分享
- Jurassic Pack Vol. II Dinosaurs 侏罗纪包卷恐龙二号Unity游戏模型资源unitypackage
- Jurassic Pack Vol. III Dinosaurs 侏罗纪包卷恐龙三号Unity游戏模型资源unitypackag
- Ultimate Seating Controller 终极座椅控制器Unity游戏开发插件资源unitypackage
- 什么是人工智能-关于人工智能的相关介绍说明
- Figma Converter for Unity适用Unity的Figma转换器Unity游戏开发插件unitypackage
- Creepy Animatronic Anims 令人毛骨悚然的电子动画Unity游戏动画插件资源unitypackage
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功