14

VS2010 调用 GSL 数学算法库的流程

 3 years ago
source link: https://blog.popkx.com/method-of-vs2010-calling-gsl-math-library/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

VS2010 调用 GSL 数学算法库的流程

发表于 2018-07-23 21:07:06   |   已被 访问: 390 次   |   分类于:   C语言   |   暂无评论

GSL(GNU Scientific Library)是一个 C 写成的用于科学计算的库,有超过1000个函数,该库提供了关于数学计算的很多方面,Matlab的大部分函数几乎都能借助它实现,可以在数值计算中省却很多事情。本节介绍如何在 visual studio 2010 环境部署 gsl 环境。

下载 windows 下的 GSL 代码


下载WinGsl,然后解压,注意路径尽量没有空格或者中文。

打开VS工程,按照下图添加库路径和头文件路径


执行以下测试代码:



\#include <stdio.h> #include <gsl/gsl_linalg.h> #pragma comment(lib, "libgsl.a") #pragma comment(lib, "libgslcblas.a") //////////////////////////////////////////////////////////// // Solve Ax = b with LU and cholesky int main(int argc, char **argv) { printf("=========== tst2 ===========\n"); double a_data[] = { 2,1,1,3,2, 1,2,2,1,1, 1,2,9,1,5, 3,1,1,7,1, 2,1,5,1,8 }; double b_data[] = { -2,4,3,-5,1 }; gsl_vector *x = gsl_vector_alloc (5); gsl_permutation * p = gsl_permutation_alloc (5); gsl_matrix_view m = gsl_matrix_view_array(a_data, 5, 5); gsl_vector_view b = gsl_vector_view_array(b_data, 5); int s; gsl_linalg_LU_decomp (&m.matrix, p, &s); gsl_linalg_LU_solve (&m.matrix, p, &b.vector, x); printf ("x = \n"); gsl_vector_fprintf(stdout, x, "%g"); double a2_data[] = { 2,1,1,3,2, 1,2,2,1,1, 1,2,9,1,5, 3,1,1,7,1, 2,1,5,1,8 }; double b2_data[] = { -2,4,3,-5,1 }; gsl_matrix_view m2 = gsl_matrix_view_array(a2_data, 5, 5); gsl_vector_view b2 = gsl_vector_view_array(b2_data, 5); gsl_linalg_cholesky_decomp(&m2.matrix); gsl_linalg_cholesky_solve(&m2.matrix, &b2.vector, x); printf ("x = \n"); gsl_vector_fprintf(stdout, x, "%g"); gsl_permutation_free (p); gsl_vector_free(x); return 0; }

输出如下:

阅读更多:   C语言


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK