矩阵乘法
Am×n⋅Bn×p=∑jA(:,j)B(j,:)
>> rng('default');
>> A = randi(3, 2, 3); B = randi(3, 3, 2);
>> A*B
ans =
11 16
12 15
>> C = zeros(size(A, 1), size(B, 2));
>> for j = 1:size(A, 2),
C = C + A(:, j) * B(j, :);
end
>> C
C =
11 16
12 15
矩阵的迹(trace)
矩阵的迹等于其对角元素之和;
function t = trace(A)
if ~ismatrix(A) || size(A,1)~=size(A,2)
error(message('MATLAB:trace:square'));
end
t = full(sum(diag(A)));
基本性质:
∥A∥2F=tr(A′×A)=tr(A×A′)
>> A = magic(3);
>> norm(A, 'fro')^2
ans =
285.0000
>> trace(A'*A)
ans =
285
>> trace(A*A')
ans =
285
- 矩阵的 F 范数是全体元素平方和,
- A′×A :其对角线元素分别为列的平方和,
- A×A′ :其对角线元素分别为行的平方和再相加。
- 本质上都等于: ∑∑A.2