Clear Filters
Clear Filters

algorithm to find out combinations of known vectors for resultant vector

2 views (last 30 days)
Hi, i have a lists of vector (actually in complex number) like v1 = [1, 2] v2 = [2, 3] v3 = [1, 1] v4 = [5, 10] ... and i am looking at the resultant vector, says, [8 , 13] any idea what straight forward algorithm I should use to find out the combinations of vectors which can result in [8, 13] in this case?
i understand there will be many possible combinations that i would limit them by scores beforehand.
  7 Comments
Walter Roberson
Walter Roberson on 12 Jan 2018
Are the values complex integers or are they complex floating point that might have fractions?
Omega Wea
Omega Wea on 12 Jan 2018
Edited: Omega Wea on 12 Jan 2018
i think at this stage, just treat them as used/not used and complex integers for now.

Sign in to comment.

Accepted Answer

Guillaume
Guillaume on 12 Jan 2018
Assuming used/not used, this is fairly easy when the size of the set is reasonably small (~ 20 elements max) as you can just try all combinations:
values = [1 + 2i;
2 + 3i;
1 + 1i;
5 + 10i;
1 + 0i;
3 + 3i]; %demo data
target = 8 + 13i;
combs = dec2bin(0:2^numel(values)-1).' - '0';
ishit = sum(values .* combs) == target;
validcombs = logical(combs(:, ishit)) %each column is a valid combination of vector. true says to use that vector
If you'd rather have a list of indices:
validcombs = cellfun(@find, num2cell(validcombs, 1), 'UniformOutput', false)
  7 Comments
Omega Wea
Omega Wea on 17 Jan 2018
great thanks. what would u suggest if the set if large instead? i think the data might grow in future. is it only the process time be longer? or matlab cannot handle more than that?
Guillaume
Guillaume on 17 Jan 2018
The number of combinations is 2^(size of set). Above some size calculating them all will take too much memory/time.
If the set is too big, then you'll have to use a cleverer approach, possibly something out of the optimisation toolbox, with which I'm completely unfamiliar.

Sign in to comment.

More Answers (0)

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!