在有限元等参单元计算中,大量用到Jacobi矩阵的求逆。
这里给出一个使用lapack库函数求2x2矩阵逆的例子:
/********************************************************** File: test_lapack.c Author: Liang Zheng E-mail: [email protected] Date: 2014-6-19 **********************************************************/ #include <stdio.h> #include <stdlib.h> #include <lapacke.h> int main() { float a[2][2]float xx[]={23.0,54.0,67.0,2.0}; lapack_int info; int n=2; lapack_int lda=2; lapack_int ipiv[2]={2,2}; int i,j; info=LAPACKE_sgetrf(LAPACK_ROW_MAJOR,n,n,a,lda,ipiv); printf("info = %d\n",info); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("a= %f\n",a[i][j]); for(i=0;i<2;i++) printf("ipiv = %d\n",ipiv[i]); info=LAPACKE_sgetri(LAPACK_ROW_MAJOR,n,a,lda,ipiv); printf("info = %d\n",info); for(i=0;i<2;i++) for(j=0;j<2;j++) printf("a= %f\n",a[i][j]); return 1; }
lapack笔记:矩阵求逆
时间: 2024-10-23 04:50:21