comparison matrixcomp/dual.m @ 0:8f23314345f4 draft

Create local repository for matrix toolboxes. Step #0 done.
author Antonio Pino Robles <data.script93@gmail.com>
date Wed, 06 May 2015 14:56:53 +0200
parents
children
comparison
equal deleted inserted replaced
-1:000000000000 0:8f23314345f4
1 function y = dual(x, p)
2 %DUAL Dual vector with respect to Holder p-norm.
3 % Y = DUAL(X, p), where 1 <= p <= inf, is a vector of unit q-norm
4 % that is dual to X with respect to the p-norm, that is,
5 % norm(Y, q) = 1 where 1/p + 1/q = 1 and there is
6 % equality in the Holder inequality: X'*Y = norm(X, p)*norm(Y, q).
7 % Special case: DUAL(X), where X >= 1 is a scalar, returns Y such
8 % that 1/X + 1/Y = 1.
9
10 % Called by PNORM.
11
12 warns = warning;
13 warning('off')
14
15 if nargin == 1
16 if length(x) == 1
17 y = 1/(1-1/x);
18 return
19 else
20 error('Second argument missing.')
21 end
22 end
23
24 q = 1/(1-1/p);
25
26 if norm(x,inf) == 0, y = x; return, end
27
28 if p == 1
29
30 y = sign(x) + (x == 0); % y(i) = +1 or -1 (if x(i) real).
31
32 elseif p == inf
33
34 [xmax, k] = max(abs(x));
35 f = find(abs(x)==xmax); k = f(1);
36 y = zeros(size(x));
37 y(k) = sign(x(k)); % y is a multiple of unit vector e_k.
38
39 else % 1 < p < inf. Dual is unique in this case.
40
41 x = x/norm(x,inf); % This scaling helps to avoid under/over-flow.
42 y = abs(x).^(p-1) .* ( sign(x) + (x==0) );
43 y = y / norm(y,q); % Normalize to unit q-norm.
44
45 end
46 warning(warns)