Effacer les filtres
Effacer les filtres

algorithm to find out combinations of known vectors for resultant vector

2 vues (au cours des 30 derniers jours)
Omega Wea
Omega Wea le 12 Jan 2018
Commenté : Guillaume le 17 Jan 2018
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 commentaires
Walter Roberson
Walter Roberson le 12 Jan 2018
Are the values complex integers or are they complex floating point that might have fractions?
Omega Wea
Omega Wea le 12 Jan 2018
Modifié(e) : Omega Wea le 12 Jan 2018
i think at this stage, just treat them as used/not used and complex integers for now.

Connectez-vous pour commenter.

Réponse acceptée

Guillaume
Guillaume le 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 commentaires
Omega Wea
Omega Wea le 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 le 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.

Connectez-vous pour commenter.

Plus de réponses (0)

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by