view general/numerical/pdev.m @ 4:e44f49929e56

Adding reorganised general toolbox, now in several subdirectories.
author samer
date Sat, 12 Jan 2013 19:21:22 +0000
parents
children 8476b3d9d295
line wrap: on
line source
function N=pdev(p,A,D)
% pdev - p-deviation, generalisation of stddev for exponents other than 2
%
% pdev :: nonneg, [[D1]], I:natural -> [[D2]].
% pdev :: nonneg, [[N D]] -> [[ 1 D]].
%
% where D2 = set(D1,I,1), ie the Ith dimension is
% collapsed. I defaults to 1. The p-deviation is defined as 
%    pdev(p,x,i) = mean(abs(x).^p,i).^(1/p)
%
% See also pnorm.

if nargin<2, D=1; end;

% Should these be sum or mean?
if p==2
	N=sqrt(mean(abs(A).^2,D));
else
	N=mean(abs(A).^p,D).^(1/p);
end