필터 지우기
필터 지우기

Info

이 질문은 마감되었습니다. 편집하거나 답변을 올리려면 질문을 다시 여십시오.

Vector with elements, reconstructable after addition...

조회 수: 1 (최근 30일)
Anon
Anon 2013년 8월 16일
마감: MATLAB Answer Bot 2021년 8월 20일
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
Jan
Jan 2013년 8월 16일
편집: Jan 2013년 8월 16일
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?

답변 (0개)

이 질문은 마감되었습니다.

태그

Community Treasure Hunt

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

Start Hunting!

Translated by