Borrar filtros
Borrar filtros

Info

La pregunta está cerrada. Vuélvala a abrir para editarla o responderla.

Vector with elements, reconstructable after addition...

1 visualización (últimos 30 días)
Anon
Anon el 16 de Ag. de 2013
Cerrada: MATLAB Answer Bot el 20 de Ag. de 2021
Hi,
ok, you will notice that I am not very proficient in mathematics, so please excuse my lack of terminology in asking this question.
I want to write a function that takes a positive integer n and that outputs a vector with n elements. The elements in this vector should be reconstructable if only the sum of specific elements in this vector is known. Let me give an example:
function v = fun(n)
v = 2.^(1:n);
end
e.g., for n = 5 v = [2 4 8 16 32]
Now if I had the number a = 20 I can be sure that this number is an addition of v(ix) where ix = [2 4]. If a = 14, ix = [1 2 3]. I have no proof for this, but I guess that this will work out for larger n, too. However, there are two reasons why I run into trouble with this. First, if n is getting too large, I'll probably get a floating point issue. Second, I have no idea how to efficiently code a function that would return ix.
Any ideas, hints, etc. are very much appreciated. Please feel free to alter the question title.
  1 comentario
Jan
Jan el 16 de Ag. de 2013
Editada: Jan el 16 de Ag. de 2013
In your example you are actually looking for a binary representation of a. Maybe check dec2bin. This gives a string having a 1 at the positions you are looking for.
i.e.
dec2bin( 20 ) = '10100'
and therefore 20 = 1*2.^4 + 0 * 2.^3 + 1 * 2.^2 + 0 * 2.^1 + 0 * 2.^0
Maybe this gets you started?

Respuestas (0)

La pregunta está cerrada.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by