Re: Little(?) problem: What is the formula ???

• To: mathgroup at smc.vnet.net
• Subject: [mg21948] Re: [mg21911] Little(?) problem: What is the formula ???
• From: "David Park" <djmp at earthlink.net>
• Date: Sat, 5 Feb 2000 00:49:21 -0500 (EST)
• Sender: owner-wri-mathgroup at wolfram.com

```
>Hello All !
>
>I have two "series" of data :
>The first serie are "normal values"
>The seccond serie represents a percentage(Value) of an amount(Nominator)
>
>Serie 1)
>Value  Nominator
>100  1
>150  1
>125  1
>
>
>Serie 2)
>Value  Nominator
>10  100
>12  200
>15  300
>
>The Problem:
>--------------------------------------------------------------------------
>I want to find a GENERAL formula to calculate the SUM of these series,
>So a formula which gives the following results
>
>Serie 1)   365
>Serie 2)   13,1
>
>
>Explanation results:
>Serie 1) 100+150+125 = 375
>
>serie 2)   10% of 100 = 10
>  12% of 200 = 24
>  15% of 300 = 45
>So total amount = 600 and the fraction=79 so that is 13.1%
>
>
>
>What is the general formula  (using value and nominator) ?????????
>
>
>Thank you very much !!!
>

I am assuming that you are rather new to Mathematica and want to know how to do this
using Mathematica methods. So I will do the steps in some detail. Let's take the
first sum first. We would represent the series in Mathematica this way:

series1 = {{100, 1}, {150, 1}, {125, 1}}
{{100, 1}, {150, 1}, {125, 1}}

I will assume that the 1's are weighting factors and may be something other than 1.
(This will help us in evaluating the second series.) So the first thing we want to do
is multiply the items in each inner List. We can do that by changing the List to a
Times by using the Apply statement and mapping it onto each of the inner Lists.

Apply[Times, #] & /@ series1
{100, 150, 125}

Then to convert this List into a sum we Apply Plus to the above output.

Plus @@ {100, 150, 125}
375

Here we set up a single expression which will work for any series of the series1
type.

Plus @@ (Apply[Times, #] & /@ series1)
375

If you are new to Mathematica you will want to study Map (also sometimes denoted by
/@ ), Apply (also sometimes denoted by @@ ) and also pure functions in Help.

Now for your second type of series.

series2 = {{10, 100}, {12, 200}, {15, 300}};

The numerator of your expression is just going to be what is produced by your first
type of sum. We could divide by 100 to get 79, but since you want percent we would
just have to multiply by 100 when we finished.

Plus @@ (Apply[Times, #] & /@ series1)
7900

For the denominator we just want the sum of the second elements in each list. The
easiest method to do this is probably just to sum the lists, by Applying Plus

Plus @@ series2
{37, 600}

and then taking the last part.

Last[{37, 600}]
600

So now we can combine the numerator and denominator, and since we want a real number
and not a fraction, use N on the result.

N[Plus @@ (Apply[Times, #] & /@ series2)/Last[Plus @@ series2]]
13.1667

Finally, if you are going to do many of these sums you can define functions to
evaluate them.

sumtype1[series_] := Plus @@ (Apply[Times, #] & /@ series)
sumtype2[series_] := N[sumtype1[series]/Last[Plus @@ series]]

sumtype1[series1]
375

sumtype2[series2]
13.1667

David Park