<s>[INST] Computing $\sum_{k = 1}^{n} \dfrac{k}{2^k} $ in different ways I am trying to compute the following sum \begin{align} S = \sum_{k = 1}^{n} \dfrac{k}{2^k} \end{align}
I have computed this sum and found that
$$ \bbox[5px,border:2px solid red]
{
S = 2 - \dfrac{n+2}{2^{n}} 
}
$$
For prooving this let's rewrite the sum in the following way:
\begin{align} S = \dfrac{1}{2} + \dfrac{1 + 1}{2^2} + \dfrac{1+1+1}{2^3} + \ldots + \dfrac{1+ \ldots+1}{2^n} = \bbox[5px,border:2px solid yellow]
 {\dfrac{1}{2} + \dfrac{1}{2^2} + \ldots + \dfrac{1}{2^n}} + \bbox[5px,border:2px solid yellow]
{ \dfrac{1}{2^2} + \dfrac{1}{2^3} + \ldots+\dfrac{1}{2^n}} + \ldots + \bbox[5px,border:2px solid yellow]{
\sum_{j = k}^{n}\dfrac{1}{2^j}} + \ldots +\bbox[5px,border:2px solid yellow]{
 \dfrac{1}{2^n}} = \sum_{j = 1}^{n}\left( \dfrac{1}{2^{k-1}} - \dfrac{1}{2^n}  \right) =  2 - \dfrac{1}{2^{n-1}} - \dfrac{n}{2^n}  =2 - \dfrac{n+2}{2^{n}} \end{align}
This computations are rather awfull and i made them just to find the answer, and i am looking for another interesting ways how to compute this sum (especcialy not elementary, using calculus, or number theory, or theory of functions of complex variable, or something else), any ways will be very appriciated!
 [/INST] Here is a generating function approach. We use the coefficient of operator $[z^n]$ to denote the coefficient of $z^n$ of a series.

We obtain
\begin{align*}
\color{blue}{\sum_{k=1}^n}\color{blue}{\frac{k}{2^k}}
&=[z^n]\sum_{q=0}^{\infty}\left(\sum_{k=0}^q\frac{k}{2^k}\right)z^q\tag{1}\\
&=[z^n]\frac{1}{1-z}\,\sum_{q=0}^\infty \frac{q}{2^ q}z^q\tag{2}\\
&=[z^n]\frac{z}{1-z}\,\frac{d}{dz}\sum_{q=0}^\infty \left(\frac{z}{2}\right)^q\\
&=[z^{n-1}]\frac{1}{1-z}\,\frac{d}{dz}\left(\frac{1}{1-\frac{z}{2}}\right)\tag{3}\\
&=\frac{1}{2}[z^{n-1}]\frac{1}{1-z}\,\frac{1}{\left(1-\frac{z}{2}\right)^2}\\
&=[z^{n-1}]\left(\frac{2}{1-z}-\frac{1}{1-\frac{z}{2}}-\frac{1}{2\left(1-\frac{z}{2}\right)^2}\right)\tag{4}\\
&=[z^{n-1}]\left(2\sum_{j=0}^\infty z^j-\sum_{j=0}^\infty \left(\frac{z}{2}\right)^j\right.\\
&\qquad\qquad\qquad\left.-\frac{1}{2}\sum_{j=0}^\infty(j+1)\left(\frac{z}{2}\right)^j\right)\\
&=2-\frac{1}{2^{n-1}}-\frac{n}{2^n}\tag{5}\\
&\,\,\color{blue}{=2-\frac{n+2}{2^n}}
\end{align*}
in accordance with OPs result.

Comment:

*

*In (1) we write the sum as coefficient of $z^n$ of a generating function.


*In (2) we use that multiplication with $\frac{1}{1-z}$ transforms a coefficient $a_q$ to the sum of the first $q$ coefficients: $\sum_{k=0}^q a_k$.


*In (3) we apply the rule $[z^p]z^qA(z)=[z^{p-q}]A(z)$ and use the differential operator $\frac{d}{dz}$.


*In (4) we make a partial fraction expansion to ease the following series expansion.


*In (5) we select the coefficient of $z^{n-1}$.

Btw. I think OPs approach is smart. Using sigma notation it can be written as
\begin{align*}
\color{blue}{\sum_{k=1}^n}\color{blue}{\frac{k}{2^k}}
&=\sum_{k=1}^n\frac{1}{2^k}\sum_{j=1}^k1\\
&=\sum_{j=1}^n\sum_{k=j}^n\frac{1}{2^k}\\
&=\sum_{j=1}^n\left(\frac{1-\frac{1}{2^{n+1}}}{1-\frac{1}{2}}-\frac{1-\frac{1}{2^j}}{1-\frac{1}{2}}\right)\\
&=\sum_{j=1}^n\left(\frac{1}{2^{j-1}}-\frac{1}{2^n}\right)\\
&=\frac{1-\frac{1}{2^n}}{1-\frac{1}{2}}-\frac{n}{2^n}\\
&\,\,\color{blue}{=2-\frac{n+2}{2^n}}
\end{align*}

</s>