Distribution algorithm from rectangle to sine

47 Views Asked by At

I am trying to distribute a constant value along a vector according to sine distribution. I would like to obtain something like this

given S = 16        ## constant value, sum of the vector elements
given length = 7    ## length of the vector

result = [1 2 3 4 3 2 1]
1

There are 1 best solutions below

5
On BEST ANSWER

Consider $\;s_L(k):= \sin\left(\left(k-\frac 12\right)\frac{\pi}L\right)$
then you probably want something like :

$\displaystyle\left(\frac {S\;\cdot s_L(k)}{\sum_{i=1}^L s_L(i)}\right)_{\; k=1\cdots L}$

Example : for $\,L=7\,$ and $\,S=16\,$ we get : $ [0.79225, 2.2198, 3.2078, 3.5603, 3.2078, 2.2198, 0.79225]$

Which is your result if rounded to the nearest integer.