1

I have a variating number of vectors which have a linear dependency. I'd like to find the linear combination of coefficients which brings their sum to 0. For example:

a*[1;1;1]+b[2;2;2]=0
a=2, b=-1

I could use iterators, but the number of vectors is changing and can be quite large.

Thanks

1 Answers1

0

Solution

You can use the following approach:

  1. arrange the base vectors in columns
  2. Use SVD to calculate a non trivial solution.

code

%defines input
v1 = [1;1;1];
v2 = [2;2;2];

%perform calculation
[U S V] = svd([v1,v2]);
x = V(:,end)

result

v1*x(1)+v2*x(2)

ans =
 0
 0
 0

x =
0.8944
-0.4472
ibezito
  • 5,782
  • 2
  • 22
  • 46
  • that is nice, but say I'd like to do it in galois field, svd doesn't work. Is there an alternative? –  Jul 09 '17 at 08:19
  • @OlegK If you want to do it in a Galois field that completely changes the question. You should definitely include that information in the question text – Luis Mendo Jul 09 '17 at 10:50