lsqr solving augmented linear equation

I would like to use lsqr to solve the augmented equations (A; alpha*I)*f = (g;0) for f, where A is an 256*256 matrix, I is 256*256 identity matrix and g is a 256*256 matrix. Since lsqr only allows the input to be column vectors, I would like to write a function afun to pass in. The code of my function afun is:
function z=afun(x,type,alpha)
.....A....(here I generated the matrix A)
a = [A;alpha*eye(256)];
b = a *x;
bb = a' *x;
if strcmp(type,'notransp')
z = b(:);
elseif strcmp(type,'tansp')
z = bb(:);
end
Then I plugged in my function afun to lsqr:
alpha = 0.1;
D = [g;zeros(size(g,1))];
lsqr(@(x,type)afun(x,type,alpha),D(:));
I got a warning that To RESHAPE the number of elements must not change. I think that is something wrong for my afun, especially the if..elseif..part, can someone help me to modify this error? Thanks so much.

Réponses (0)

Catégories

En savoir plus sur Sparse Matrices dans Centre d'aide et File Exchange

Question posée :

le 18 Fév 2016

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by