Performing matrix operations with complex numbers in C

穿精又带淫゛_ 提交于 2019-12-10 10:19:40

问题


I'm trying to perform computations involving matrix operations and complex math - sometimes together, in C. I'm very familiar with Matlab and I know these types of computations could be performed simply and efficiently. For example, two matrices of the same size, A and B, each having elements of complex values can be summed easily through the expression A+B. Are there any packages or techniques that can be recommended to employ programming these types of expressions in C or Objective C? I am aware of complex.h which allows for performing operations on complex numbers, but am unaware of how to perform operations on complex matrices, which is what I'm really after. Similarly, I'm aware of packages which allow for operations on matrices, but don't think they will be useful in working on complex matrices.


回答1:


You want to use BLAS for basic linear algebra operations, like summing or multiplying two matrices, and LAPACK for more computational intensive algorithms, like factoring matrices.

BLAS routines have funny names, that look like alphabet soup. This is because of old Fortran restrictions on the length of the function name. The first letter of the name indicates the data type the BLAS routine operates on. Since your interested in complex numbers you want to look at routines beginning in c (for complex single precision) or z (for zouble complex double precision). For example the BLAS routine to multiply complex matrices A and B is CGEMM or ZGEMM (here GEMM stands for general matrix matrix multiply.)

It looks like in Objective C, BLAS is available through the Accelerate framework. The naming convention is to prepend cblas_ to the original BLAS name. For example here is the documentation for cblas_zgemm.

Normally, vendors provided optimized versions of the BLAS for their platform. These routines can often be significantly faster than naive implementations of these matrix operations. Often the peak floating-point performance of a machine can be achieved, or nearly achieved, with these routines. In fact the LINPACK benchmark (LINPACK was the predecessor to LAPACK) uses these routines to benchmark and rank supercomputers.




回答2:


You are looking for BLAS or LAPACK. They are linear algebra libraries which you can download and install.



来源:https://stackoverflow.com/questions/7683080/performing-matrix-operations-with-complex-numbers-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!