开发者

Performing matrix operations with complex numbers in C

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 val开发者_运维技巧ues 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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜