- " 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 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
christina
el 12 de Sept. de 2018
Comentada: christina
el 12 de Sept. de 2018
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 comentarios
Respuesta aceptada
Stephen23
el 12 de Sept. de 2018
Editada: Stephen23
el 12 de Sept. de 2018
" 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 comentarios
Stephen23
el 12 de Sept. de 2018
Editada: Stephen23
el 12 de Sept. de 2018
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.
Más respuestas (0)
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!