0
$\begingroup$

In general for a natural number N and any vector of size 1*(2N+1)2^{N+1}, I need

a[-1, -2] = v[[1]], a[-1, -1] = v[[2]], a[-1, 0] = v[[3]], 
a[-1, 1] = v[[4]], a[0, -2] = v[[5]], a[0, -1] = v[[6]], 
a[0, 0] = v[[7]], a[0, 1] = v[[8]], a[1,-2] = v[[9]], 
a[1, -1] = v[[10]], a[1, 0] = v[[11]], a[1, 1] = v[[12]].....
a[-N,2^(N)-1]=(2N+1)2^{N}-1.

As an example and for N=1, let v = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12} (or any vector of size 1*12); Now how to assign the values as follows

a[-1, -2] = v[[1]]=1, a[-1, -1] = v[[2]]=2, a[-1, 0] = v[[3]]=3, 
a[-1, 1] = v[[4]]=4, a[0, -2] = v[[5]]=5, a[0, -1] = v[[6]]=6, 
a[0, 0] = v[[7]]=7, a[0, 1] = v[[8]]=8, a[1,-2] = v[[9]]=9, 
a[1, -1] = v[[10]]=10, a[1, 0] = v[[11]]=11, a[1, 1] = v[[12]]=12
$\endgroup$
4
  • 1
    $\begingroup$ k = 0; Do[ a[i, j] = v[[++k]] , {i, -1, 1} , {j, -2, 1}]; ?? $\endgroup$
    – george2079
    Jun 8, 2017 at 18:21
  • $\begingroup$ alternately compute your sum as a dot product: Dot[Flatten[Table[Sin[2^j x - k], {j, -1, 1}, {k, -2, 1}], 1], v] $\endgroup$
    – george2079
    Jun 8, 2017 at 18:36
  • $\begingroup$ @george2079 thank you so much. Your first code works perfectly. Appreciated! $\endgroup$
    – Mutaz
    Jun 9, 2017 at 9:35
  • $\begingroup$ I don't know what is mean the up-voted I did. What I meant is that I really appreciated @george2079 suggested code. I hope someone can provide me with the guidelines and policy on how to use the website as I am new to it. $\endgroup$
    – Mutaz
    Jun 9, 2017 at 13:52

1 Answer 1

0
$\begingroup$
k = 0; 
Do[ a[i, j] = v[[++k]] , {i, -1, 1} , {j, -2, 1}]; 

Thank you George2079 I voted to your answer as it solved the issue I had!

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.