Skip to main content
added 28 characters in body
Source Link
GFauxPas
  • 5.1k
  • 1
  • 19
  • 31

I came from the programming world, i saw an exercise: "Calculate the average of a list of numbers in a functional way", then i saw an interesting answer after provide my solution.

So, lets say i have this list: $\{2, 4, 6, 8, 10\}$ I want to calculate the average, so that solution proceeded as next:

$$ avg = \frac{2 - \mathbf{0}}{1} + \frac{4 - \mathbf{2}}{2} + \frac{6 - \mathbf{3}}{3} + \frac{8 - \mathbf{4}}{4} + \frac{10 - \mathbf{5}}{5} $$$$ \text{avg} = \frac{2 - \mathbf{0}}{1} + \frac{4 - \mathbf{2}}{2} + \frac{6 - \mathbf{3}}{3} + \frac{8 - \mathbf{4}}{4} + \frac{10 - \mathbf{5}}{5} $$

So we can say, starting from $currentAverage = 0$$\text{currentAverage} = 0$ and starting $index = 1 \in \{1,2,3,4,5\}$$\text{index} = 1 \in \{1,2,3,4,5\}$, we can calculate the average as next: $$ \sum_{i=1}^n currentAverage + \frac{(n_i - currentAverage)}{index_i} $$$$ \sum_{i=1}^n \text{currentAverage} + \frac{(n_i - \text{currentAverage})}{\text{index}_i} $$

Where did this deduction come from? Thanks!

I came from the programming world, i saw an exercise: "Calculate the average of a list of numbers in a functional way", then i saw an interesting answer after provide my solution.

So, lets say i have this list: $\{2, 4, 6, 8, 10\}$ I want to calculate the average, so that solution proceeded as next:

$$ avg = \frac{2 - \mathbf{0}}{1} + \frac{4 - \mathbf{2}}{2} + \frac{6 - \mathbf{3}}{3} + \frac{8 - \mathbf{4}}{4} + \frac{10 - \mathbf{5}}{5} $$

So we can say, starting from $currentAverage = 0$ and starting $index = 1 \in \{1,2,3,4,5\}$, we can calculate the average as next: $$ \sum_{i=1}^n currentAverage + \frac{(n_i - currentAverage)}{index_i} $$

Where did this deduction come from? Thanks!

I came from the programming world, i saw an exercise: "Calculate the average of a list of numbers in a functional way", then i saw an interesting answer after provide my solution.

So, lets say i have this list: $\{2, 4, 6, 8, 10\}$ I want to calculate the average, so that solution proceeded as next:

$$ \text{avg} = \frac{2 - \mathbf{0}}{1} + \frac{4 - \mathbf{2}}{2} + \frac{6 - \mathbf{3}}{3} + \frac{8 - \mathbf{4}}{4} + \frac{10 - \mathbf{5}}{5} $$

So we can say, starting from $\text{currentAverage} = 0$ and starting $\text{index} = 1 \in \{1,2,3,4,5\}$, we can calculate the average as next: $$ \sum_{i=1}^n \text{currentAverage} + \frac{(n_i - \text{currentAverage})}{\text{index}_i} $$

Where did this deduction come from? Thanks!

Source Link

how to prove this "partial average"?

I came from the programming world, i saw an exercise: "Calculate the average of a list of numbers in a functional way", then i saw an interesting answer after provide my solution.

So, lets say i have this list: $\{2, 4, 6, 8, 10\}$ I want to calculate the average, so that solution proceeded as next:

$$ avg = \frac{2 - \mathbf{0}}{1} + \frac{4 - \mathbf{2}}{2} + \frac{6 - \mathbf{3}}{3} + \frac{8 - \mathbf{4}}{4} + \frac{10 - \mathbf{5}}{5} $$

So we can say, starting from $currentAverage = 0$ and starting $index = 1 \in \{1,2,3,4,5\}$, we can calculate the average as next: $$ \sum_{i=1}^n currentAverage + \frac{(n_i - currentAverage)}{index_i} $$

Where did this deduction come from? Thanks!