4
$\begingroup$

I am trying to get Mathematica to solve the following equality in terms of $w_i$

$\displaystyle \frac{\sum_{i = 1}^{n} x_i }{\sum_{i = 1}^{n} y_i} = \frac{\sum_{i = 1}^{n} ( (\frac{x_i}{y_i}) w_i ) }{n} $

(Background: https://math.stackexchange.com/questions/137332/relationship-between-ratios-and-averages-of-ratios)

But it's telling me "This system cannot be solved with the methods available to Solve."

Now, I'm guessing this is because I haven't given Mathematica enough information about my assumptions (specifically, that $w_i$ is expressible as a function of $x_i$ and $y_i$, or something similar)

What am I doing wrong here, and how would I go about using Mathematica to solve equalities like these?

Solve[Sum[Subscript[x, i], 
     {i, 1, n}]/
    Sum[Subscript[y, i], 
     {i, 1, n}] == 
   Sum[(Subscript[x, i]/
       Subscript[y, i])*
      Subscript[w, i], 
     {i, 1, n}]/n, 
  Subscript[w, i]]

PS.) I realize my title stinks... I blame myself for not even knowing enough about what my problem is to give this question a cogent title. If someone could Edit the question and give it a real title and/or suggest one, I'd be appreciative.

$\endgroup$
3
  • $\begingroup$ Your notation is extremely general, and the system won't understand it. If you decide on how many variables and equations you'll have exactly, then it can solve it. Also, it sees w_i as a single symbol, and it doesn't know that it's related to w_1, w_2, .... $\endgroup$
    – Szabolcs
    May 31, 2012 at 19:12
  • $\begingroup$ @Szabolcs I understand what you're saying - but that doesn't tell me how to fix the problem. Could you tell me how you'd go about getting Mathematica to do what I'm trying to get it to do? $\endgroup$
    – Steve
    May 31, 2012 at 19:17
  • $\begingroup$ I don't believe that there is any way to get it to solve such a system without you choosing a value for n first. I know my comment is not an answer, that's why I wrote it as a comment. $\endgroup$
    – Szabolcs
    May 31, 2012 at 19:27

1 Answer 1

7
$\begingroup$

Mathematica can only handle this if you give an explicit value to n.

If I understand correctly, what you want is: for what values of $w_i$ in terms of $y_i$ is the equations going to be satisfied for any $x_i$.

You need to use SolveAlways, not Solve, for this.

Example:

eqn = Sum[Subscript[x, i], {i, 1, n}]/
    Sum[Subscript[y, i], {i, 1, n}] == 
   Sum[(Subscript[x, i]/Subscript[y, i])*Subscript[w, i], {i, 1, n}]/
    n;

num = 3; (* let's solve for n==3 *)

SolveAlways[eqn /. n -> num, Table[Subscript[x, i], {i, num}]]

The output is

$$ \left\{\left\{y_1\to 0,w_1\to 0\right\},\left\{y_1\to 0,y_2\to 0\right\},\left\{y_1\to 0,y_3\to 0\right\},\left\{y_1\to -y_2,y_3\to 0\right\},\left\{y_1\to -y_3,y_2\to 0\right\},\left\{y_2\to 0,w_2\to 0\right\},\left\{y_2\to 0,y_3\to 0\right\},\left\{y_2\to -y_3,y_1\to 0\right\},\left\{y_3\to 0,w_3\to 0\right\},\left\{w_1\to \frac{3 y_1}{y_1+y_2+y_3},w_2\to \frac{3 y_2}{y_1+y_2+y_3},w_3\to \frac{3 y_3}{y_1+y_2+y_3}\right\}\right\} $$

You'll see that only the last solution is different from 0.

$\endgroup$
3
  • 1
    $\begingroup$ Thanks so much for this! This is almost what I want - and, my brain can convert the result you show into the more generic w_i = n * y_i / Sum[y_i, {i, 0, n}] solution - but I'm surprised that Mathematica can get as far as you've shown me, but not make the result more general. Is this, definitively, as far as Mathematica is capable of taking the solution? $\endgroup$
    – Steve
    Jun 1, 2012 at 0:49
  • $\begingroup$ @Steve Unless I'm mistaken, Mathematica is not able to do symbolic manipulations on general sums (sums that go up to a symbolic value). I'd love to be proven wrong though. $\endgroup$
    – Szabolcs
    Jun 1, 2012 at 8:57
  • $\begingroup$ Great information... much appreciated. Thanks again for your time! $\endgroup$
    – Steve
    Jun 1, 2012 at 17:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

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