function norm in matlab

The norm function in Matlab is used to compute the Euclidean norm (magnitude) of a vector or the matrix norm.

For a vector v, the Euclidean norm is calculated using:

ā€‹ norm(v) = sqrt(sum(abs(v).^2))

For a matrix A, the matrix norm is calculated as:

ā€‹ norm(A) = sqrt(max(eig(A'*A)))

The code snippet below shows how to use the norm function to calculate the Euclidean norm of a vector 'v' and the matrix norm of a matrix 'A':

main.m
% defining the vector v
v = [1, 2, 3];

% calculating Euclidean norm of vector v
norm_v = norm(v);

% defining the matrix A
A = [1, 2, 3; 4, 5, 6; 7, 8, 9];

% calculating matrix norm of matrix A
norm_A = norm(A);
214 chars
12 lines

In this example, norm_v will have value 3.7417, while norm_A will have value 16.8481.

related categories

gistlibby LogSnag