Suppose I have a bunch of vectors or matrices $v,v_1,v_2,\ldots, v_n$, living in an $N$ dimensional linear space. How to check (using mathematica) if $v$ is positively dependent on the set $\{v_1,v_2,\ldots,v_n\}$ ($v$ lives in the "convex cone" or "positive cone" spanned by $\{v_1,\ldots,v_n\}$)? That is, does there exists non-negative real numbers $c_1,c_2,\ldots c_n\geq 0$ such that $$v=\sum^n_{i=1}c_i v_i.$$ Also, if such nonnegative coefficients exists (possibly not unique), how to find them (just one possible solution is OK)?
1 Answer
You can find one possible solution with FindInstance
.
For example, operating in $N$=m
dimensions (as N
is a reserved keyword in Mathematica) and using n
vectors,
m = 3;
n = 4;
V = RandomVariate[NormalDistribution[], {n, m}] (* the vectors v_i *)
(* {{0.512956, -2.44836, 1.64427},
{0.893093, -1.62577, -0.0144412},
{1.2746, 0.678006, -1.75192},
{0.844172, 0.8864, 0.615265}} *)
v = RandomVariate[NormalDistribution[], m] (* the target vector v *)
(* {0.771292, -1.06991, 0.578498} *)
cc = Array[c, n]; (* the unknowns *)
FindInstance[Join[Thread[cc.V == v], Thread[cc >= 0]], cc]
(* {{c[1] -> 0.570869, c[2] -> 0., c[3] -> 0.264421, c[4] -> 0.167536}} *)
cc /. First[%] (* extract the coefficients *)
(* {0.570869, 0., 0.264421, 0.167536} *)
If FindInstance
returns an empty list {}
then there is no solution.
Reduce[]
. Actually, now that I think about it, it seems this could be recast as an LP problem; you'd just have to check that the appropriate minimum value is zero. $\endgroup$