# Solve for an element of a vector

I would like to solve for an element of a vector. Suppose $w \in \mathbb{R}^n$ and I want to find a solution to the following

$\sum_{i=1}^n w_i = c$

where $c$ is some constant and only one $w_k$ is unknown (for some $k \in [1,n]$). (i.e. $w_k = c - \sum_{i\neq k} w_i$).

I'm not sure how to work with vectors in Mathematica. What I have tried so far is:

Solve[Sum[w[i], {i, 1, n}] == c, w[k]]


The output is:

{}


I know I'm not handling the vector w properly. I've looked around and I can't seem to find a proper way to define w as a vector. Do I need to define k and n to have a value, or can they be constants? I've tried using Array[w,n] but n needs to have a value for this to work.

• your result can be expressed as : c - Sum[ Boole[i != k] w[i] , {i, n}] . There isnt a built in way to directly get there though AFAIK. Commented Dec 6, 2016 at 22:26

I don't know if this is exactly what you expect but try

 Table[Subscript[w, i], {i, 1, 10}]
Solve[Total[Table[Subscript[w, i], {i, 1, 10}]] == c, Subscript[w, 4]]


In what you normaly write you implicitely postulate that $k \in \{1, 10\}$. I think such a theoretical formula is beyond the capacity of any computer algebra system.

• That is quite close, you have n=10 and k=4. I would like to not specify what n and k are. (which would require the closed form of the sum, i think). Commented Dec 6, 2016 at 20:22

I'm not sure if I understand it correctly, but following 112606, you can do something like this

k = 5;
n = 10;
Solve[Total[Array[w, n]] == c, w[k]]

(* {{w[5] -> c - w[1] - w[2] - w[3] - w[4] - w[6] - w[7] - w[8] - w[9] - w[10]}} *)