1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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. $\endgroup$ – george2079 Dec 6 '16 at 22:26
1
$\begingroup$

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.

$\endgroup$
  • $\begingroup$ 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). $\endgroup$ – McAngus Dec 6 '16 at 20:22
0
$\begingroup$

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]}} *)
$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.