% Clear the command window
clc
% Define a (column) vector x
x=[1;2; -3;-2]
% Calculate the 2-norm of x
norm(x)
% Calculate the 2-norm of x again
norm(x,2)
% Calculate the 1-norm of x
norm(x,1)
% Calculate the infinity-norm of x
norm(x,'inf')
% Get help on the matlab command "norm"
help norm
% Generate a 5x10 random matrix where each entry is drawn independently
% from the standard Gaussian (i.e., normal) distribution
% To learn more, type "help randn" in the command window
A=randn(5,10)
% Compute the Hilbert-Schmidt norm, or equivalently the Frobenius norm, of
% A
norm(A,'fro')
% Now compute the Frobenius norm directly using its definition
su=0;
for i=1:5; for j=1:10; su=su+abs(A(i,j))^2; end; end
sqrt(su)
% "vectorize the 5x10 matrix A. Avec is a 50x1 vector obtained by putting
% the columns of A one on top of the other
Avec=A(:)
% Calculate the 2-norm of Avec and observe that it is equal to the
% Frobenius norm of $A$
norm(Avec)
% Create a 2x2 matrix with random (normal distributed) entries as above
A=randn(2,2)
% Calculate the operator norm of A
norm(A)
%%% Below, we will generate vectors on the unit circle in R^2 by using the
%%% standard parametrization of the unit circle: x1=cos(t), x2=sin(t), 0 <=
%%% t <= 2*pi
% First generate a row vector t consisting of entries t(1)=0,
% t(j+1)=t(j)+0.01 for all j<= J where (2*pi-0.01)