- " Afun(x,'notransp') accepts a vector x and returns the product A*x."
- " Afun(x,'transp') accepts a vector x and returns the product A'*x."
Error while passing function to matlab's svds function
2 次查看(过去 30 天)
显示 更早的评论
I am getting following error when I run my code. Can somebody please tell me what am I doing wrong here and how to fix it? I have a function that does the matrix vector multiplication and I want to pass it as a handle to the svd function to calculate the singular values of the matrix.
Error using @(x)ifft(bsxfun(@times,fft(x),m))
Too many input arguments.
Error in svds>LanczosBD (line 631)
u = Afun(v,f1);
Error in svds (line 166)
[U,S,V,flag] = LanczosBD(Afun,m,n,f1,f2,k,v,InnerOpts,randStr);
Code:
L= 2^18;
T = 500; % Number of spikes 40
x = zeros(L,1);
q = randperm(L);
x(q(1:T)) = 2*sign(randn(T,1));
m = rand(L,1);
h = @(x) ifft(bsxfun(@times,fft(x),m)); % Function handle
y = h(x);
s = svds(h,[L L],6,'largest');
0 个评论
采纳的回答
Stephen23
2018-9-12
编辑:Stephen23
2018-9-12
" s = svds(Afun,n,...) specifies a function handle Afun instead of a matrix. The second input n gives the size of matrix A used in Afun."
You will notice that in the help page, the input Afun is a link. When you click on that link it scrolls down the page to the section that specifies how the function must be defined. There it states:
"The function Afun must satisfy these conditions:"
Your function does not support either of those two conditions (in fact your function does not support any second argument at all, thus the error message). You will need to write your function to accept a second input argument and return appropriate values, as per the documentation.
3 个评论
Stephen23
2018-9-12
编辑:Stephen23
2018-9-12
I suspect that you meant to do this:
s = svds(@(x,tflag) afun(x,tflag,m), [L,L], 10);
^^^^^^^ only two input arguments, as per the documentation.
The anonymous function should only have two input arguments, not three as you had it defined. The variable m is taken from the workspace when the anonymous function is defined.
更多回答(0 个)
另请参阅
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!