我想使用lsqr最小化FT ^ -1(Ax-B)。 A是一个巨大的稀疏矩阵,我使用3个向量定义它:
RA(L) is the Lth nonzero of A, counting across row 1, then across row 2, and so on;
JA(L) is the column in which the Lth nonzero of A lies;
NA(I) is the number of nonzero coefficients in the Ith row of A.
我使用用户定义的嵌套函数APROD计算了Ax,我试图将其作为lsqr中的函数句柄传递。但是,它会返回一条错误消息:输入参数太多。
这是我的代码:
function x = PROVA
%RA, NA, JA, m are defined here;
mode=1;
x=lsqr(@APROD,B,atol,itnlim);
end
function result=APROD(x1)
%if mode=1 computes y=y+Ax
%if mode=2 computes x=x+A_(transpose)y
%A is stored in RA,JA,NA by rows
L2=0;
if mode==1
result=zeros(m,1);
for c=1:m
sum=0;
L1=L2+1;
L2=L2+NA(c);
for L=L1:L2
J=JA(L);
sum=sum+RA(L)*x1(J);
end
result(c)=result(c)+sum;
end
end
if mode==2
result=zeros(n,1);
for c=1:m
Yc=y(c);
L1=L2+1;
L2=L2+NA(c);
for L=L1:L2
J=JA(L);
result(J)=result(J)+RA(L)*Yc;
end
end
end
end
这是错误消息:
Error using iterapp (line 59)
user supplied function ==> APROD failed with the following error:
Too many input arguments.
Error in lsqr (line 190)
v = iterapp('mtimes',afun,atype,afcnstr,u,varargin{:},'transp');
Error in PROVA (line 97)
x=lsqr(@APROD,B,atol,itnlim);
我不知道自己做错了什么,这是我第一次使用功能处理,我读了其他有关它的问题,但我没有设法解决我的问题。谢谢你的帮助!