0
$\begingroup$

Suppose I have a vectors in $\mathbb{R}^{6}$. For example, take the vector $v = k(-2,2,4,6,2,2)$. I would like to find some $k$ with the constraint that the last two components are necessarily non-negative and that every component in the vector is a minimal integer. For example, in this case, I would take $k = \frac{1}{2}$. Is there a way to implement such a minimization procedure in mathematica given an arbitrary six-component vector?

In particular, suppose I have now $n$ such vectors with $n \lt 6$. Is there a way to find the linear combination of such vectors with minimal integer entries and with the same constraint that the last two components are non-negative?

I've thought about trying to use Reduce or Solve, but I was wondering if there's some faster way to implement this.

Thanks!

$\endgroup$

1 Answer 1

2
$\begingroup$

Not sure about what you want, but perhaps:

f[v_] := v Sign[v[[-1]]]/GCD @@ v 

v0 = {-2, 2, 4, 6, 2, 2};
f@v0
(*  {-1, 1, 2, 3, 1, 1} *)
$\endgroup$
1
  • $\begingroup$ @user238194 Have you tried to generalize it? $\endgroup$ Nov 20, 2015 at 15:43

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.