use of svds with function handles
Show older comments
I want to do singular value decomposition of a matrix A, which is very big but simply structured. Specifically, it is a rank-2 matrix plus a diagonal matrix. I just need the first few singular values. So I want to call "svds", and I do not want to construct A explicitly as a matrix, as that is too costy in memory. The idea is to write a function to perform the multiplication x---> A*x
This is the nested function for the multiplication:
function y = fun_A_times_x(x)
y = sum(phi2.*x)*kphi1 + sum(phi1.*x)*kphi2...
+ sum(kphi1.*x)*phi2 + sum(kphi2.*x)*phi1...
+ diagonal.*x - E*sum(phi1.*x)*phi2 - E* sum(phi2.*x)*phi1;
end
How should I write the svds part?
myfun = @fun_A_times_x ;
[UU,SS,VV] = svds(@(x) myfun, [dim dim], 2);
This does not work.
I still do not understand the mechanism of the function handle. Can anyone help me out? My matlab is R2017a.
Accepted Answer
More Answers (1)
Christine Tobler
on 5 Nov 2021
2 votes
The svds function needs to be able to apply both A*x and A'*x, so your function handle should accept a second input which is either 'transp' or 'notransp' and then compute either A*x or A'*x accordingly.
Categories
Find more on Linear Algebra 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!