Info
この質問は閉じられています。 編集または回答するには再度開いてください。
Vector with elements, reconstructable after addition...
2 ビュー (過去 30 日間)
古いコメントを表示
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
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!