我有一段代码用于考试,他们希望我为了达到更好的成绩而做的是在没有第二个“为“的声明。Matlab - 为矩阵的每一行减去一个向量而不用语句
的代码是:
piv = 1:n; %// piv: position vector
for k = 1:n-1 %// for each column :
if ((max(abs(A(piv(k:n),k)))) > eps(normA)) %// if pivot is non zero
[~, I] = max(A(piv(k:n),k)); %// find the max index
I = I + (k-1);
piv([k,I]) = piv([I,k]); %// swap pivot elements
A(piv(k+1:n),k) = A(piv(k+1:n),k)/A(piv(k),k); %// calculate the multipliers and save them in the column
for j = k+1:n
A(piv(j),k+1:n) = A(piv(j),k+1:n) - (A(piv(k),k+1:n)*A(piv(j),k)); %// multiply for multipliers and subtract them by the row
end
end
end
这是高斯因式分解方法,但不要紧,这件事是我需要有没有第二个为e和j变量中相同的结果。
'Z = X - 那些(尺寸(X,1),1)* y' – user3528438
他们想要实现的Householder变换或吉文根据使用情况 – percusse