Didon
Didon

Reputation: 393

Singular Value Decomposition (SVD) in C

I am doing the five point essential matrix estimation in C where I need to implement SVD. I found an opensource implementation in c http://www.public.iastate.edu/~dicook/JSS/paper/code/svd.c that works on mxn matrices where m>n. The problem is that the matrix that I want to decompose is a (5x9) matrix and therefore n>m. I need the right orthogonal transformation matrix v where svd(A)=udv' To ensure (m>n) I tried to do svd(transpose(A))=u2*d2*v2 I found that u=v2, but v is different from u2 and I need v. How to implement SVD in C successfully for an 5x9 matrix?

Upvotes: 1

Views: 2632

Answers (1)

chutsu
chutsu

Reputation: 14123

Late to the party, but for future reference one can obtain a SVD implementation in C from the book "Numerical Recipes in C by William H. Press et al", in Chapter 2.6, Page 67, SVD Algorithm. To quote the book

Here is the algorithm for constructing the singular value decomposition of any matrix.

So I'm assuming the matrix to be decomposed can be square, m < n or n < m

Warning: When googling SVD implementations in C check what assumptions are made w.r.t the input matrix. Some assume the matrix is square, some do not, etc...

Alternatively, you can use the SVD in LAPACK. Stephen Canon provided a code example on another SO question on how to use dgesdd to perform SVD. (link here)

Upvotes: 1

Related Questions