How to do SVD without specific function svd()?
3 views (last 30 days)
Show older comments
I want to implement singular value decomposition for image without using the function svd().
0 Comments
Answers (1)
John D'Errico
on 5 Jan 2019
So, is this homework? (The most common reason for disallowing built-in code.) If so, I won't help you.
Regardless, the simple answer if to just look online. I'm sure you can find the relationship between eig and the corresponding sets of singular vectors. Not that hard to write, if you are willing to use eig, and you don't really care about the small singular values for a possibly nearly singular matrix. But if you won't use svd, then eig seems a dis-allowed option too.
Are you willing to call outside tools? For example, surely you can find C or Fortan code for the svd. Compile that for use in MATLAB. But then what would be the purpose? You will have just wasted some moderate effort on replacing already compiled code.
Or, you could probably start with a Python implementation, then since you can get to Python from MATLAB, use that. But why bother?
So IF you are asking how to implement the svd without eig OR svd as an option, from scratch? Then you need to learn to swim in the deep end of the pool. That means you will want to learn about how to implement tools like Householder rotations. (Not hard.) As I recall, you can use Householder to bi-diagonalize the matrix. Then you can do further rotations to diagonalize it. (It has been a long time since I implemeted an svd.)
A quick glance online finds this:
I also recall the Linpack and Lapack manuals had fairly clear explanations of what you need to do, since that is what I used long ago to write my own implementation (back in the days when the SVD was not actually easily found in all languages.)
Or, you can look at things like this:
To be honest, you don't really want to write the code yourself, unless you sufficiently understand linear algebra. And in that case, you should have known or been able to find eveything I just wrote yourself.
0 Comments
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!