我想用lsqr来最小化FT^-1(Ax-B)。 A是一个巨大的稀疏矩阵和我使用3-矢量它定义:在lsqr中使用函数句柄MATLAB
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.
我计算斧使用我试图通过在LSQR的功能句柄用户定义嵌套函数APROD。但是,它会返回错误消息:输入参数太多。
这是我的代码:
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);
我不知道我做错了什么,这是我第一次与功能手柄,我读关于它的其他问题,但我没有设法解决我的问题。感谢您的帮助!
你有'APROD'和'PROVA'在相同的文件? 'APROD'中没有定义'mode'。 'atol'和'itnlim'没有在'PROVA'中定义。有很多这样的错误。你可以给一个[MCVE]吗? (最小和可执行的部分在这里至关重要,因为你的矩阵是_“巨大的_” –