view general/numerical/pnorm.m @ 22:4f5015db91aa

Moved maxnormalise to unitmax
author samer
date Thu, 17 Jan 2013 14:23:21 +0000
parents 8476b3d9d295
children
line wrap: on
line source
function N=pnorm(p,A,D)
% pnorm - general vector norm wrt exponent p
%
% pnorm :: nonneg, [[D1]], I:natural -> [[D2]].
% pnorm :: nonneg, [[N D]] -> [[ 1 D]].
%
% where D2 = set(D1,I,1), ie the Ith dimension is
% collapsed. I defaults to 1. The p-norm is defined as 
%    pnorm(p,x,i) = sum(abs(x).^p,i).^(1/p)
%
% See also pdev for alternative which uses mean instead of sum

if nargin<2, D=1; end;

if p==2
	N=sqrt(sum(abs(A).^2,D));
else
	N=sum(abs(A).^p,D).^(1/p);
end