create a matrix of 3 vectors that all have norm 1 in matlab

To create a matrix of 3 vectors that all have norm 1 in Matlab, we can use the random function to generate random vectors and then normalize them using the norm function. Here is an example code:

main.m
% Set the dimension of the vectors
n = 3;

% Generate 3 random vectors
v1 = rand(n,1);
v2 = rand(n,1);
v3 = rand(n,1);

% Normalize the vectors
v1 = v1 / norm(v1);
v2 = v2 / norm(v2);
v3 = v3 / norm(v3);

% Combine the vectors into a matrix
M = [v1, v2, v3];

% Display the matrix and its norms
disp('Matrix M =');
disp(M);
disp('Norms of the vectors in M:');
disp(norm(v1));
disp(norm(v2));
disp(norm(v3));
408 chars
24 lines

In this code, we first define the dimension of the vectors (n=3). Then we use the rand function to create three random vectors of size nx1 (v1, v2, and v3). We then normalize each vector using the norm function and store them back in their original variables. Finally, we combine the vectors into a matrix M and display the matrix along with the norms of its vectors.

gistlibby LogSnag