7

If I have two expressions with sums in them, like this:

$$\begin{align*} b&=\frac{\sum_{i} (x_i - \bar{x})(y_i -\bar{y})}{\sum_{i}(x_i -\bar{x})^2}\\ r&=\frac{\sum_{i} (x_i - \bar{x})(y_i -\bar{y})}{\sqrt{\sum_{i}(x_i -\bar{x})^2\sum_{i}(y_i -\bar{y})^2}} \end{align*}$$

and I wanted to produce a simplified expression of $\frac{b}{r}$, how would I do it? The problem is the sums. It seems Mathematica doesn't like the unspecified, unevaluated sums.

Edit: I was expecting to end up with something like this:

$$\sqrt{\frac{\sum_{i}(y_i -\bar{y})^2}{\sum_{i}(x_i -\bar{x})^2}}$$

I've been playing around with Expand, Simplify, FullSimplify. There may just be a way to apply it that I'm missing.

J. M.'s missing motivation
  • 124,525
  • 11
  • 401
  • 574
Mr Alpha
  • 3,156
  • 2
  • 24
  • 33

2 Answers2

8

The absence of a terminal $n$ in the sums suggests you are looking for a combination of symbolic reduction and typography. Let's separate the two, then, by using symbols for the sums, performing the reduction, and then replacing the symbols by whatever we like:

MMA screen shot

whuber
  • 20,544
  • 2
  • 59
  • 111
5

Here is a completely symbolic manipulation:

ClearAll[x, y, xMean, yMean, n];

varianceX = Sum[(x[i] - xMean)^2, {i, n}]

$\sum _i^n (x(i)-\text{xMean})^2$

varianceY = Sum[(y[i] - yMean)^2, {i, n}]

$\sum _i^n (y(i)-\text{yMean})^2$

coVariance = Sum[(x[i] - xMean) (y[i] - yMean), {i, n}]

$\sum _i^n (x(i)-\text{xMean}) (y(i)-\text{yMean})$

b = coVariance/varianceX;

r = coVariance/Sqrt[varianceX varianceY];

b/r /. {Sqrt[a_ b_] :> Sqrt[a] Sqrt[b]}

$\frac{\sqrt{\sum _i^n (y(i)-\text{yMean})^2}}{\sqrt{\sum _i^n(x(i)-\text{xMean})^2}}$

All I had to do in order to help Mathematica get to the simplified result is to state the rule Sqrt[a_ b_] :> Sqrt[a] Sqrt[b].

Jens
  • 97,245
  • 7
  • 213
  • 499