%mathpiper,def="PNorm"

// p-norm, reduces to euclidean norm when p = 2
Function("PNorm",{v,p})
[
	Local(result,i);
	Check(p>=1, "Argument", "PNorm: p must be >= 1");

	result:=0;
	For(i:=1,i<=Length(v),i++)[
		result:=result+Abs(v[i])^p;
	];

	// make it look nicer when p = 2
	If(p=2,Sqrt(result),(result)^(1/p) );
];

%/mathpiper




%mathpiper_docs,name="PNorm",categories="User Functions;Linear Algebra"
*CMD PNorm --- todo:?
*CALL
	PNorm(v,p)

*PARMS
{v} -- ?
{p} -- ?

*DESC
?

*E.G.
todo
%/mathpiper_docs