# Sum elemets of an array

I am not sure this is something that is possible to implement in mathematica, but my question is the following.

I have a system three linear equation where the coefficients in front of each variable is a sum. The equations have the following expression (I am just reporting one of them)

Sum[y_i/(s_i)^2] - Kx *Sum[Sin[p_i]/(s_i)^2] -Ky *Sum[Cos[p_i]/(s_i)^2] -G *Sum[1/(s_i)^2]


The variable I need to find are Kx, Ky, G and I know all the y_i, p_i, s_i. I know how to obtain the numerical solution for the variable I am looking for, but I was wondering if it is possible also to find an analytical one. I was thinking to use

Array[y, 13]


but then i don't know how to do the sum of the different element.

Someone can help me?

• fyi you can not use underscores as parts of symbol names in mahtematica. – george2079 Jan 3 '18 at 19:48

You can do that, but I suggest you use Inactive[Sum] while solving the equations:

sumI = Inactivate[Sum];


You have only one equation, so only one unknown can be solved:

Solve[sumI[y[i]/(s[i])^2, {i, 1, n}] -
Kx*sumI[Sin[p[i]]/(s[i])^2, {i, 1, n}] -
Ky*sumI[Cos[p[i]]/(s[i])^2, {i, 1, n}] -
G*sumI[1/(s[i])^2, {i, 1, n}] == 0, Ky]


$\left\{\left\{\text{Ky}\to \frac{-G \sum _{i=1}^n \frac{1}{s(i)^2}-\text{Kx} \sum _{i=1}^n \frac{\sin (p(i))}{s(i)^2}+\sum _{i=1}^n \frac{y(i)}{s(i)^2}}{\sum _{i=1}^n \frac{\cos (p(i))}{s(i)^2}}\right\}\right\}$

After replacing n by a number you can add // Activate at the end to compute the sums.

If I understand your question right, you have 3 equations (one of them you posted) to calculate the 3 unknowns {Kx,Ky,G}?

If so, let's call the list of three equations eqn:

matrix=D[eqn,{{Kx,Ky,G}}];
rs=eqn /. {Kx->0,Ky->0,G->0};


the analytical solution of your problem(if matrix is regular) is

sol=Inverse[matrix].rS

• Yeah, exactly. But the problem is that I am not sure on how to write the equations since "i" is the index of the element -not a parameter-, and I have to sum over that index – rob Jan 3 '18 at 18:24
• Sum[expression[i],{i,1,n}] – Ulrich Neumann Jan 3 '18 at 18:29
• for example:  Sum[q^i, {i, 0, n}] (* (-1 + q^(1 + n))/(-1 + q) *) – Ulrich Neumann Jan 3 '18 at 18:47