Professional Documents
Culture Documents
1 To estimate by hand, the computational cost, in flops, of calculating the Frobenius norm
of an nxn matrix, we have used the results yielded by the matlab, from n=10 to n=163840
A=magic(10);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(20);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(40);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(80);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(160);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(320);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(640);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(1280);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(2560);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(5120);
N2 = norm(A,"fro")
tic;N2;toc
A=magic(10240);
N2 = norm(A,"fro")
tic;N2;toc
As can be seen, the largest value obtained was for n=10 and then as the value of n
doubled, the Frobenius Norm decreased, then its value remained the same for the next
double of n and then increased and it stayed the same for the next double of n and so on.
2, 3
clear all
A=[2 3 4; 4 5 6], B=[ 4 5 6 7; 5 6 7 8; 2 3 4 5]
[m,p]=size(A);
[p,n]=size(B);
for i=1:m
for j=1:n
s=0;
for k=1:p
s=s+A(i,k)*B(k,j);
end
C(i,j)=s
pause(0.5)
end
end
C = A*B
C = mtimes(A,B)
C(i,j) = A(i,:)*B(:,j)
for i=1:10
for j=1:10
A(i,j)=i
for i=1:10
for j=1:10
B(i,j)=j
C(i,j) = A(i,:)*B(:,j)
end
end
end
end