Programming libraries for C linear algebra

In summary, CLAPACK can be used to solve equations of the form Ax = b, where A is singular, but the routine dgesv_() doesn't detect it. However, it can't solve the equation Ax = b where A is singular.
  • #1
odiakkoh
8
0
Hi,

Can anyone recommend a freely available library in C or C++ that is able to calculate eigenvalues and eigenvectors of generalized eigenvalue problems. e.g. of the type:

Au = LBu

where A and B are matrices, L is the eigenvalue, and u is the eigenvector.

N.B. the GNU Scientific library was my first thought, but it can only do standard eigenvalue problems, not those of the generalized type.
 
Physics news on Phys.org
  • #2
blas doesn't have eigenvalue stuff?. BUt you can try CLAPACK and maybe look at lidia. you can tyr to find some at netlib.org.

Or you can try numerical recipes code(usually for teaching purposes but still usable).
www.nr.com.
 
  • #3
CLAPACK does the job

Thanks a lot! - CLAPACK does the job.

For anyone else interested in doing matrix-type algebra in C here's some useful CLAPACK links:

CLAPACK can be downloaded from here: http://www.netlib.org/clapack/
Documentation can be found here: http://www.netlib.org/lapack/lug/index.html

Explanations for function parameters are found in the code.


It's a bit fiddly to install, and link to the libraries (all three of them) bundled in the package. The interface will feel quite archaic to anyone accustomed to the niceities of object orientated languages (such as myself). But it does do the job.

Oh, and one last hint for anyone trying to use this: take note of the documentation explaining how matrices are stored in memory: particularly in what order array elements correspond to matrix elements. I didn't bother; made an assumption; got it wrong (damn! I had a 50:50 chance!), and spent a few hours wondering why things weren't working quite right!
 
  • #4
Hey, guys, I installed CLAPACK on my Mac without much trouble. However it failes on solving this simple equation Ax = b, where A is singular, yet the routine dgesv_() didn't detect it. Can you test the case on you machine? Here is the input.

Matrix:
-10.0 -5.0
6.0 3.0

Vector:
0 0.000000
1 1.000000

info = 0

Solution from CLAPACK:
0 1125899906842624.000000
1 -2251799813685248.000000
 

FAQ: Programming libraries for C linear algebra

What is a programming library for C linear algebra?

A programming library for C linear algebra is a collection of pre-written code that provides functions and algorithms for performing operations related to linear algebra, such as matrix multiplication, vector operations, and solving systems of linear equations. These libraries are often used by programmers to save time and effort in writing their own code for these common operations.

Which programming libraries are commonly used for C linear algebra?

Some commonly used programming libraries for C linear algebra include BLAS (Basic Linear Algebra Subprograms), LAPACK (Linear Algebra Package), and GSL (GNU Scientific Library). Each of these libraries offers a wide range of functions for performing linear algebra operations efficiently and accurately.

Are there any advantages to using a programming library for C linear algebra?

Yes, there are several advantages to using a programming library for C linear algebra. Firstly, these libraries are often highly optimized and efficient, making them faster than writing your own code. Additionally, they have been extensively tested and are generally more accurate than code written by an individual programmer. Finally, using a programming library can save you time and effort, as you do not need to write and debug code for common linear algebra operations.

Can programming libraries for C linear algebra be used for other programming languages?

Yes, many programming libraries for C linear algebra have been ported to other programming languages, such as Python, Java, and MATLAB. This allows programmers to use the same functions and algorithms in their preferred language, without having to learn a new library. However, some libraries may have slight differences in syntax or functionality when used in different languages.

Are there any limitations to using programming libraries for C linear algebra?

While programming libraries for C linear algebra offer many benefits, there are a few limitations to consider. Firstly, some libraries may only be compatible with certain operating systems or hardware, so it is important to check compatibility before use. Additionally, some libraries may have licensing restrictions or require payment for commercial use. Finally, using a programming library may limit your ability to customize or optimize certain operations, as you are relying on pre-written code.

Back
Top