apply your code to find the 2-norm of vectors and check the orthogonality of two vectors. in matlab

To find the 2-norm of a vector in MATLAB, you can use the norm function with a second argument of 2:

main.m
v = [1, 2, 3];
v_norm = norm(v, 2);
disp(v_norm); % Output: 3.7417
67 chars
4 lines

To check the orthogonality of two vectors in MATLAB, you can take their dot product and check if it is zero (within some tolerance):

main.m
v1 = [1, 0, 0];
v2 = [0, 0, 1];
dot_product = dot(v1, v2);
tolerance = 1e-10; % set a tolerance
if abs(dot_product) < tolerance
    disp('The two vectors are orthogonal');
else
    disp('The two vectors are not orthogonal');
end
229 chars
10 lines

gistlibby LogSnag