$y$ is a function of $n$ independent variables $x_1, \dots, x_n$ where $n$ is unknown. How do I calculate $\partial y/\partial x_k$ with Mathematica?
For example,
$$y=f(x_1,\dots,x_n)=\sum_{i=1}^n {a_i x_i}$$
Then
$$\frac{\partial y}{\partial x_k}=a_k \textrm{ , } k=1,2,\dots,m$$
In Mathematica
y = Sum[a[i] x[i], {i, 1, n}]
But D[y, x[k]] won't return a[k] as I didn't tell Mathematica what k is.
How should I modify my code?