No BSD License  

Highlights from
Vector norm

4.0

4.0 | 1 rating Rate this file 18 Downloads (last 30 days) File Size: 1.96 KB File ID: #10708

Vector norm

by

 

11 Apr 2006 (Updated )

Returns the vector norm for a specified dimension (e.g. row/col) of a matrix

| Watch this File

File Information
Description

% VNORM - Return the vector norm along specified dimension of A
%
% VNORM(A) returns the 2-norm along the first non-singleton
% dimension of A
% VNORM(A,dim) return the 2-norm along the dimension 'dim'
% VNORM(A,dim,normtype) returns the norm specified by normtype
% along the dimension 'dim'
% VNORM(A,[],normtype) returns the norm specified by normtype along
% the first non-singleton dimension of A
%
% normtype may be one of {inf,-inf,positive integer}.
% For a given vector, v, these norms are defined as
% inf: max(abs(v))
% -inf: min(abs(v))
% p (where p is a positive integer): sum(abs(v).^p)^(1/p)
%
% Examples:
% A = [8 1 6; 3 5 7; 4 -9 2];
%
% %Columnwise 2-norm (Euclidean norm)
% vnorm(A,1) = [9.4340 10.3441 9.4340];
% vnorm(A,[],2) % Same as above (since first non-singleton dimensions
% % is columnwise and default norm is 2-norm.
% vnorm(A,[],[])% Again, same as above
%
% % Row-wise maximum of absolute values
% vnorm(A,2,inf) = [8 7 9]';
%
% % Columnwise minimum of absolute values
% vnorm(A,[],-inf) = [3 1 2];
%
% % Error: Use the inf type and not the string 'inf'
% vnorm(A,[],'inf') % Wrong
% vnorm(A,[],inf) % Correct

Acknowledgements

This file inspired Seis Lab 3.01, Normalize N D Vectors In Single Matrix Or N Component Matrices, Export Figure To 3 D Interactive Pdf, and Array Tool Set.

MATLAB release MATLAB 7.1.0 (R14SP3)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (1)
13 Apr 2006 John D'Errico

Minor points - the 1-norm should also be a special case for speed. I'd also suggest some cleanup on the help, i.e., some users might not otherwise know that the infinity norm will select out the maximum element, or what -inf does. On the other hand, whenever I see a matlab idiom for something I've done many times in the past, I recognize value in it. Well done.

Contact us