The notion of mathematical expectation is closely related to the idea of a weighted mean, used
extensively in the handling of numerical data. Consider the arithmetic average x¯x¯
of the following ten numbers: 1, 2, 2, 2, 4, 5, 5, 8, 8, 8, which is given by
x
¯
=
1
10
(
1
+
2
+
2
+
2
+
4
+
5
+
5
+
8
+
8
+
8
)
x
¯
=
1
10
(
1
+
2
+
2
+
2
+
4
+
5
+
5
+
8
+
8
+
8
)
(1)Examination of the ten numbers to be added shows that five distinct values are included. One of
the ten, or the fraction 1/10 of them, has the value 1, three of the ten, or the fraction 3/10 of them,
have the value 2, 1/10 has the value 4, 2/10 have the value 5, and 3/10 have the value 8. Thus, we
could write
x
¯
=
(
0
.
1
·
1
+
0
.
3
·
2
+
0
.
1
·
4
+
0
.
2
·
5
+
0
.
3
·
8
)
x
¯
=
(
0
.
1
·
1
+
0
.
3
·
2
+
0
.
1
·
4
+
0
.
2
·
5
+
0
.
3
·
8
)
(2)The pattern in this last expression can be stated in words: Multiply each possible value by the fraction of the numbers having that value and then sum these
products. The fractions are often referred to as the relative frequencies. A sum of this
sort is known as a weighted average.
In general, suppose there are n numbers {x1,x2,⋯xn}{x1,x2,⋯xn} to be averaged, with
m≤nm≤n distinct values
{t1,t2,⋯,tm}{t1,t2,⋯,tm}. Suppose f_{1} have value t_{1},
f_{2} have value t2,⋯,fmt2,⋯,fm have value t_{m}. The f_{i} must add to n. If we
set pi=fi/npi=fi/n, then the fraction p_{i} is called the relative frequency of those numbers in the
set which have the value ti,1≤i≤mti,1≤i≤m. The average x¯x¯ of the n numbers
may be written
x
¯
=
1
n
∑
i
=
1
n
x
i
=
∑
j
=
1
m
t
j
p
j
x
¯
=
1
n
∑
i
=
1
n
x
i
=
∑
j
=
1
m
t
j
p
j
(3)In probability theory, we have a similar averaging process in which the relative frequencies of
the various possible values of are replaced by the probabilities that those values are observed on
any trial.
Definition. For a simple random variable X with values {t1,t2,⋯,tn}{t1,t2,⋯,tn}
and corresponding probabilities pi=P(X=ti)pi=P(X=ti), the mathematical expectation, designated
E[X]E[X], is the probability weighted average of the values taken on by X. In symbols
E
[
X
]
=
∑
i
=
1
n
t
i
P
(
X
=
t
i
)
=
∑
i
=
1
n
t
i
p
i
E
[
X
]
=
∑
i
=
1
n
t
i
P
(
X
=
t
i
)
=
∑
i
=
1
n
t
i
p
i
(4)Note that the expectation is determined by the distribution. Two quite different random
variables may have the same distribution, hence the same expectation.
Traditionally, this average has been called the mean, or the mean value, of
the random variable X.
 Since X=aIE=0IEc+aIEX=aIE=0IEc+aIE, we have E[aIE]=aP(E)E[aIE]=aP(E).
 For X a constant c, X=cIΩX=cIΩ, so that E[c]=cP(Ω)=cE[c]=cP(Ω)=c.
 If X=∑i=1ntiIAiX=∑i=1ntiIAi then aX=∑i=1natiIAiaX=∑i=1natiIAi,
so that
E
[
a
X
]
=
∑
i
=
1
n
a
t
i
P
(
A
i
)
=
a
∑
i
=
1
n
t
i
P
(
A
i
)
=
a
E
[
X
]
E
[
a
X
]
=
∑
i
=
1
n
a
t
i
P
(
A
i
)
=
a
∑
i
=
1
n
t
i
P
(
A
i
)
=
a
E
[
X
]
(5)
Mechanical interpretation
In order to aid in visualizing an essentially abstract
system, we have employed the notion of probability as mass. The distribution induced by
a real random variable on the line is visualized as a unit of probability mass actually
distributed along the line. We utilize the mass distribution to give an important and
helpful mechanical interpretation of the expectation or mean value. In Example 6 in "Mathematical Expectation: General Random Variables",
we give an alternate interpretation in terms of meansquare estimation.
Suppose the random variable X has values {ti:1≤i≤n}{ti:1≤i≤n}, with P(X=ti)=piP(X=ti)=pi. This produces a probability mass distribution, as shown in Figure 1, with point mass concentration
in the amount of p_{i} at the point t_{i}. The expectation is
∑
i
t
i
p
i
∑
i
t
i
p
i
(6)Now titi is the distance of point mass p_{i} from the origin, with p_{i} to the left of the
origin iff t_{i} is negative. Mechanically, the sum of the products tipitipi is the moment
of the probability mass distribution about the origin on the real line. From physical theory, this
moment is known to be the same as the product of the total mass times the number which locates
the center of mass. Since the total mass is one, the mean value is the
location of the center of mass. If the real line is viewed as a stiff, weightless
rod with point mass p_{i} attached at each value t_{i} of X, then the mean value μ_{X} is the
point of balance. Often there are symmetries in the distribution which make it possible to
determine the expectation without detailed calculation.
Let X be the number of spots which turn up on a throw of a simple sixsided die. We
suppose each number is equally likely. Thus the values are the integers one through six,
and each probability is 1/6. By definition
E
[
X
]
=
1
6
·
1
+
1
6
·
2
+
1
6
·
3
+
1
6
·
4
+
1
6
·
5
+
1
6
·
6
=
1
6
(
1
+
2
+
3
+
4
+
5
+
6
)
=
7
2
E
[
X
]
=
1
6
·
1
+
1
6
·
2
+
1
6
·
3
+
1
6
·
4
+
1
6
·
5
+
1
6
·
6
=
1
6
(
1
+
2
+
3
+
4
+
5
+
6
)
=
7
2
(7)Although the calculation is very simple in this case, it is really not necessary.
The probability distribution places equal mass at each of the integer values one through
six. The center of mass is at the midpoint.
A child is told she may have one of four toys. The prices are $2.50. $3.00, $2.00, and
$3.50, respectively. She choses one, with respective probabilities 0.2, 0.3, 0.2, and 0.3 of choosing the first,
second, third or fourth. What is the expected cost of her selection?
E
[
X
]
=
2
.
00
·
0
.
2
+
2
.
50
·
0
.
2
+
3
.
00
·
0
.
3
+
3
.
50
·
0
.
3
=
2
.
85
E
[
X
]
=
2
.
00
·
0
.
2
+
2
.
50
·
0
.
2
+
3
.
00
·
0
.
3
+
3
.
50
·
0
.
3
=
2
.
85
(8)For a simple random variable, the mathematical expectation is
determined as the dot product of the value matrix with the probability matrix. This is easily
calculated using MATLAB.
X = [2 2.5 3 3.5]; % Matrix of values (ordered)
PX = 0.1*[2 2 3 3]; % Matrix of probabilities
EX = dot(X,PX) % The usual MATLAB operation
EX = 2.8500
Ex = sum(X.*PX) % An alternate calculation
Ex = 2.8500
ex = X*PX' % Another alternate
ex = 2.8500
Expectation and primitive form
The definition and treatment above assumes X is in canonical form, in which case
X
=
∑
i
=
1
n
t
i
I
A
i
,
where
A
i
=
{
X
=
t
i
}
,
implies
E
[
X
]
=
∑
i
=
1
n
t
i
P
(
A
i
)
X
=
∑
i
=
1
n
t
i
I
A
i
,
where
A
i
=
{
X
=
t
i
}
,
implies
E
[
X
]
=
∑
i
=
1
n
t
i
P
(
A
i
)
(9)We wish to ease this restriction to canonical form.
Suppose simple random variable X is in a primitive form
X
=
∑
j
=
1
m
c
j
I
C
j
,
where
{
C
j
:
1
≤
j
≤
m
}
is
a
partition
X
=
∑
j
=
1
m
c
j
I
C
j
,
where
{
C
j
:
1
≤
j
≤
m
}
is
a
partition
(10)We show that
E
[
X
]
=
∑
j
=
1
m
c
j
P
(
C
j
)
E
[
X
]
=
∑
j
=
1
m
c
j
P
(
C
j
)
(11)Before a formal verification, we begin with an example which exhibits the essential pattern.
Establishing the general case is simply a matter of appropriate use of notation.
X
=
I
C
1
+
2
I
C
2
+
I
C
3
+
3
I
C
4
+
2
I
C
5
+
2
I
C
6
,
with
{
C
1
,
C
2
,
C
3
,
C
4
,
C
5
.
C
6
}
a
partition
X
=
I
C
1
+
2
I
C
2
+
I
C
3
+
3
I
C
4
+
2
I
C
5
+
2
I
C
6
,
with
{
C
1
,
C
2
,
C
3
,
C
4
,
C
5
.
C
6
}
a
partition
(12)Inspection shows the distinct possible values of X to be 1, 2, or 3. Also,
A
1
=
{
X
=
1
}
=
C
1
⋁
C
3
,
A
2
=
{
X
=
2
}
=
C
2
⋁
C
5
⋁
C
6
and
A
3
=
{
X
=
3
}
=
C
4
A
1
=
{
X
=
1
}
=
C
1
⋁
C
3
,
A
2
=
{
X
=
2
}
=
C
2
⋁
C
5
⋁
C
6
and
A
3
=
{
X
=
3
}
=
C
4
(13)so that
P
(
A
1
)
=
P
(
C
1
)
+
P
(
C
3
)
,
P
(
A
2
)
=
P
(
C
2
)
+
P
(
C
5
)
+
P
(
C
6
)
,
and
P
(
A
3
)
=
P
(
C
4
)
P
(
A
1
)
=
P
(
C
1
)
+
P
(
C
3
)
,
P
(
A
2
)
=
P
(
C
2
)
+
P
(
C
5
)
+
P
(
C
6
)
,
and
P
(
A
3
)
=
P
(
C
4
)
(14)Now
E
[
X
]
=
P
(
A
1
)
+
2
P
(
A
2
)
+
3
P
(
A
3
)
=
P
(
C
1
)
+
P
(
C
3
)
+
2
[
P
(
C
2
)
+
P
(
C
5
)
+
P
(
C
6
)
]
+
3
P
(
C
4
)
E
[
X
]
=
P
(
A
1
)
+
2
P
(
A
2
)
+
3
P
(
A
3
)
=
P
(
C
1
)
+
P
(
C
3
)
+
2
[
P
(
C
2
)
+
P
(
C
5
)
+
P
(
C
6
)
]
+
3
P
(
C
4
)
(15)
=
P
(
C
1
)
+
2
P
(
C
2
)
+
P
(
C
3
)
+
3
P
(
C
4
)
+
2
P
(
C
5
)
+
2
P
(
C
6
)
=
P
(
C
1
)
+
2
P
(
C
2
)
+
P
(
C
3
)
+
3
P
(
C
4
)
+
2
P
(
C
5
)
+
2
P
(
C
6
)
(16)To establish the general pattern, consider X=∑j=1mcjICjX=∑j=1mcjICj.
We identify the distinct set of values contained
in the set {cj:1≤j≤m}{cj:1≤j≤m}. Suppose these are t1<t2<⋯<tnt1<t2<⋯<tn.
For any value t_{i} in the range, identify the index set J_{i} of those j such
that cj=ticj=ti. Then the terms
∑
J
i
c
j
I
C
j
=
t
i
∑
J
i
I
C
j
=
t
i
I
A
i
,
where
A
i
=
⋁
j
∈
J
i
C
j
∑
J
i
c
j
I
C
j
=
t
i
∑
J
i
I
C
j
=
t
i
I
A
i
,
where
A
i
=
⋁
j
∈
J
i
C
j
(17)By the additivity of probability
P
(
A
i
)
=
P
(
X
=
t
i
)
=
∑
j
∈
J
i
P
(
C
j
)
P
(
A
i
)
=
P
(
X
=
t
i
)
=
∑
j
∈
J
i
P
(
C
j
)
(18)Since for each j∈Jij∈Ji we have cj=ticj=ti, we have
E
[
X
]
=
∑
i
=
1
n
t
i
P
(
A
i
)
=
∑
i
=
1
n
t
i
∑
j
∈
J
i
P
(
C
j
)
=
∑
i
=
1
n
∑
j
∈
J
i
c
j
P
(
C
j
)
=
∑
j
=
1
m
c
j
P
(
C
j
)
E
[
X
]
=
∑
i
=
1
n
t
i
P
(
A
i
)
=
∑
i
=
1
n
t
i
∑
j
∈
J
i
P
(
C
j
)
=
∑
i
=
1
n
∑
j
∈
J
i
c
j
P
(
C
j
)
=
∑
j
=
1
m
c
j
P
(
C
j
)
(19)— □□
Thus, the defining expression for expectation thus holds for X in a primitive form.
An alternate approach to obtaining the expectation from a primitive form is to use the csort
operation to determine the distribution of X from the coefficients and probabilities of
the primitive form.
Suppose X in a primitive form is
X
=
I
C
1
+
2
I
C
2
+
I
C
3
+
3
I
C
4
+
2
I
C
5
+
2
I
C
6
+
I
C
7
+
3
I
C
8
+
2
I
C
9
+
I
C
10
X
=
I
C
1
+
2
I
C
2
+
I
C
3
+
3
I
C
4
+
2
I
C
5
+
2
I
C
6
+
I
C
7
+
3
I
C
8
+
2
I
C
9
+
I
C
10
(20)with respective probabilities
P
(
C
i
)
=
0
.
08
,
0
.
11
,
0
.
06
,
0
.
13
,
0
.
05
,
0
.
08
,
0
.
12
,
0
.
07
,
0
.
14
,
0
.
16
P
(
C
i
)
=
0
.
08
,
0
.
11
,
0
.
06
,
0
.
13
,
0
.
05
,
0
.
08
,
0
.
12
,
0
.
07
,
0
.
14
,
0
.
16
(21)c = [1 2 1 3 2 2 1 3 2 1]; % Matrix of coefficients
pc = 0.01*[8 11 6 13 5 8 12 7 14 16]; % Matrix of probabilities
EX = c*pc'
EX = 1.7800 % Direct solution
[X,PX] = csort(c,pc); % Determination of dbn for X
disp([X;PX]')
1.0000 0.4200
2.0000 0.3800
3.0000 0.2000
Ex = X*PX' % E[X] from distribution
Ex = 1.7800
Linearity
The result on primitive forms may be used to establish the linearity of mathematical
expectation for simple random variables. Because of its fundamental importance, we work through
the verification in some detail.
Suppose X=∑i=1ntiIAiX=∑i=1ntiIAi and Y=∑j=1mujIBjY=∑j=1mujIBj (both in canonical form). Since
∑
i
=
1
n
I
A
i
=
∑
j
=
1
m
I
B
j
=
1
∑
i
=
1
n
I
A
i
=
∑
j
=
1
m
I
B
j
=
1
(22)we have
X
+
Y
=
∑
i
=
1
n
t
i
I
A
i
∑
j
=
1
m
I
B
j
+
∑
j
=
1
m
u
j
I
B
j
∑
i
=
1
n
I
A
i
=
∑
i
=
1
n
∑
j
=
1
m
(
t
i
+
u
j
)
I
A
i
I
B
j
X
+
Y
=
∑
i
=
1
n
t
i
I
A
i
∑
j
=
1
m
I
B
j
+
∑
j
=
1
m
u
j
I
B
j
∑
i
=
1
n
I
A
i
=
∑
i
=
1
n
∑
j
=
1
m
(
t
i
+
u
j
)
I
A
i
I
B
j
(23)Note that IAiIBj=IAiBjIAiIBj=IAiBj and AiBj={X=ti,Y=uj}AiBj={X=ti,Y=uj}. The
class of these sets for all possible pairs (i,j)(i,j) forms a partition. Thus, the last
summation expresses Z=X+YZ=X+Y in a primitive form. Because of the result on primitive forms, above, we have
E
[
X
+
Y
]
=
∑
i
=
1
n
∑
j
=
1
m
(
t
i
+
u
j
)
P
(
A
i
B
j
)
=
∑
i
=
1
n
∑
j
=
1
m
t
i
P
(
A
i
B
j
)
+
∑
i
=
1
n
∑
j
=
1
m
u
j
P
(
A
i
B
j
)
E
[
X
+
Y
]
=
∑
i
=
1
n
∑
j
=
1
m
(
t
i
+
u
j
)
P
(
A
i
B
j
)
=
∑
i
=
1
n
∑
j
=
1
m
t
i
P
(
A
i
B
j
)
+
∑
i
=
1
n
∑
j
=
1
m
u
j
P
(
A
i
B
j
)
(24)
=
∑
i
=
1
n
t
i
∑
j
=
1
m
P
(
A
i
B
j
)
+
∑
j
=
1
m
u
j
∑
i
=
1
n
P
(
A
i
B
j
)
=
∑
i
=
1
n
t
i
∑
j
=
1
m
P
(
A
i
B
j
)
+
∑
j
=
1
m
u
j
∑
i
=
1
n
P
(
A
i
B
j
)
(25)We note that for each i and for each j
P
(
A
i
)
=
∑
j
=
1
m
P
(
A
i
B
j
)
and
P
(
B
j
)
=
∑
i
=
1
n
P
(
A
i
B
j
)
P
(
A
i
)
=
∑
j
=
1
m
P
(
A
i
B
j
)
and
P
(
B
j
)
=
∑
i
=
1
n
P
(
A
i
B
j
)
(26)Hence, we may write
E
[
X
+
Y
]
=
∑
i
=
1
n
t
i
P
(
A
i
)
+
∑
j
=
1
m
u
j
P
(
B
j
)
=
E
[
X
]
+
E
[
Y
]
E
[
X
+
Y
]
=
∑
i
=
1
n
t
i
P
(
A
i
)
+
∑
j
=
1
m
u
j
P
(
B
j
)
=
E
[
X
]
+
E
[
Y
]
(27)Now aXaX and bYbY are simple if X and Y are, so that with the aid of Example 1 we have
E
[
a
X
+
b
Y
]
=
E
[
a
X
]
+
E
[
b
Y
]
=
a
E
[
X
]
+
b
E
[
Y
]
E
[
a
X
+
b
Y
]
=
E
[
a
X
]
+
E
[
b
Y
]
=
a
E
[
X
]
+
b
E
[
Y
]
(28)If X,Y,ZX,Y,Z are simple, then so are aX+bYaX+bY, and cZcZ. It follows that
E
[
a
X
+
b
Y
+
c
Z
]
=
E
[
a
X
+
b
Y
]
+
c
E
[
Z
]
=
a
E
[
X
]
+
b
E
[
Y
]
+
c
E
[
Z
]
E
[
a
X
+
b
Y
+
c
Z
]
=
E
[
a
X
+
b
Y
]
+
c
E
[
Z
]
=
a
E
[
X
]
+
b
E
[
Y
]
+
c
E
[
Z
]
(29)By an inductive argument, this pattern may be extended to a linear combination of
any finite number of simple random variables. Thus we may assert
Linearity. The expectation of a linear combination of a finite number of simple random variables
is that linear combination of the expectations of the individual random variables.
— □□
Expectation of a simple random variable in affine form
As a direct consequence of linearity, whenever simple random variable X is in affine form, then
E
[
X
]
=
E
c
0
+
∑
i
=
1
n
c
i
I
E
i
=
c
0
+
∑
i
=
1
n
c
i
P
(
E
i
)
E
[
X
]
=
E
c
0
+
∑
i
=
1
n
c
i
I
E
i
=
c
0
+
∑
i
=
1
n
c
i
P
(
E
i
)
(30)Thus, the defining expression holds for any affine combination of indicator functions, whether in canonical form or not.
This random variable appears as the number of successes in
n Bernoulli trials with probability p of success on each component trial. It is
naturally expressed in affine form
X
=
∑
i
=
1
n
I
E
i
so
that
E
[
X
]
=
∑
i
=
1
n
p
=
n
p
X
=
∑
i
=
1
n
I
E
i
so
that
E
[
X
]
=
∑
i
=
1
n
p
=
n
p
(31)Alternately, in canonical form
X
=
∑
k
=
0
n
k
I
A
k
n
,
with
p
k
=
P
(
A
k
n
)
=
P
(
X
=
k
)
=
C
(
n
,
k
)
p
k
q
n

k
,
q
=
1

p
X
=
∑
k
=
0
n
k
I
A
k
n
,
with
p
k
=
P
(
A
k
n
)
=
P
(
X
=
k
)
=
C
(
n
,
k
)
p
k
q
n

k
,
q
=
1

p
(32)so that
E
[
X
]
=
∑
k
=
0
n
k
C
(
n
,
k
)
p
k
q
n

k
,
q
=
1

p
E
[
X
]
=
∑
k
=
0
n
k
C
(
n
,
k
)
p
k
q
n

k
,
q
=
1

p
(33)Some algebraic tricks may be used to show that the second form sums to npnp, but there is
no need of that. The computation for the affine form is much simpler.
A bettor places three bets at $2.00 each. The first bet pays $10.00 with probability 0.15,
the second pays $8.00 with probability 0.20, and the third pays $20.00 with probability 0.10.
What is the expected gain?
SOLUTION
The net gain may be expressed
X
=
10
I
A
+
8
I
B
+
20
I
C

6
,
with
P
(
A
)
=
0
.
15
,
P
(
B
)
=
0
.
20
,
P
(
C
)
=
0
.
10
X
=
10
I
A
+
8
I
B
+
20
I
C

6
,
with
P
(
A
)
=
0
.
15
,
P
(
B
)
=
0
.
20
,
P
(
C
)
=
0
.
10
(34)Then
E
[
X
]
=
10
·
0
.
15
+
8
·
0
.
20
+
20
·
0
.
10

6
=

0
.
90
E
[
X
]
=
10
·
0
.
15
+
8
·
0
.
20
+
20
·
0
.
10

6
=

0
.
90
(35)These calculations may be done in MATLAB as follows:
c = [10 8 20 6];
p = [0.15 0.20 0.10 1.00]; % Constant a = aI_(Omega), with P(Omega) = 1
E = c*p'
E = 0.9000
Functions of simple random variables
If X is in a primitive form (including canonical form) and g is a real function defined
on the range of X, then
Z
=
g
(
X
)
=
∑
j
=
1
m
g
(
c
j
)
I
C
j
a
primitive
form
Z
=
g
(
X
)
=
∑
j
=
1
m
g
(
c
j
)
I
C
j
a
primitive
form
(36)so that
E
[
Z
]
=
E
[
g
(
X
)
]
=
∑
j
=
1
m
g
(
c
j
)
P
(
C
j
)
E
[
Z
]
=
E
[
g
(
X
)
]
=
∑
j
=
1
m
g
(
c
j
)
P
(
C
j
)
(37)Alternately, we may use csort to determine the distribution for Z and work with that
distribution.
Caution. If X is in affine form (but not a primitive form)
X
=
c
0
+
∑
j
=
1
m
c
j
I
E
j
then
g
(
X
)
≠
g
(
c
0
)
+
∑
j
=
1
m
g
(
c
j
)
I
E
j
X
=
c
0
+
∑
j
=
1
m
c
j
I
E
j
then
g
(
X
)
≠
g
(
c
0
)
+
∑
j
=
1
m
g
(
c
j
)
I
E
j
(38)so that
E
[
g
(
X
)
]
≠
g
(
c
0
)
+
∑
j
=
1
m
g
(
c
j
)
P
(
E
j
)
E
[
g
(
X
)
]
≠
g
(
c
0
)
+
∑
j
=
1
m
g
(
c
j
)
P
(
E
j
)
(39)Suppose X in a primitive form is
X
=

3
I
C
1

I
C
2
+
2
I
C
3

3
I
C
4
+
4
I
C
5

I
C
6
+
I
C
7
+
2
I
C
8
+
3
I
C
9
+
2
I
C
10
X
=

3
I
C
1

I
C
2
+
2
I
C
3

3
I
C
4
+
4
I
C
5

I
C
6
+
I
C
7
+
2
I
C
8
+
3
I
C
9
+
2
I
C
10
(40)with probabilities P(Ci)=0.08,0.11,0.06,0.13,0.05,0.08,0.12,0.07,0.14,0.16P(Ci)=0.08,0.11,0.06,0.13,0.05,0.08,0.12,0.07,0.14,0.16.
Let g(t)=t2+2tg(t)=t2+2t. Determine E[g(X)]E[g(X)].
c = [3 1 2 3 4 1 1 2 3 2]; % Original coefficients
pc = 0.01*[8 11 6 13 5 8 12 7 14 16]; % Probabilities for C_j
G = c.^2 + 2*c % g(c_j)
G = 3 1 8 3 24 1 3 8 15 8
EG = G*pc' % Direct computation
EG = 6.4200
[Z,PZ] = csort(G,pc); % Distribution for Z = g(X)
disp([Z;PZ]') % Optional display
1.0000 0.1900
3.0000 0.3300
8.0000 0.2900
15.0000 0.1400
24.0000 0.0500
EZ = Z*PZ' % E[Z] from distribution for Z
EZ = 6.4200
A similar approach can be made to a function of a pair of simple random variables,
provided the joint distribution is available. Suppose X=∑i=1ntiIAiX=∑i=1ntiIAi
and Y=∑j=1mujIBjY=∑j=1mujIBj (both in canonical form). Then
Z
=
g
(
X
,
Y
)
=
∑
i
=
1
n
∑
j
=
1
m
g
(
t
i
,
u
j
)
I
A
i
B
j
Z
=
g
(
X
,
Y
)
=
∑
i
=
1
n
∑
j
=
1
m
g
(
t
i
,
u
j
)
I
A
i
B
j
(41)The AiBjAiBj form a partition, so Z is in a primitive form. We have the same two
alternative possibilities: (1) direct calculation from values of g(ti,uj)g(ti,uj) and
corresponding probabilities P(AiBj)=P(X=ti,Y=uj)P(AiBj)=P(X=ti,Y=uj), or (2) use of csort to
obtain the distribution for Z.
We use the joint distribution in file jdemo1.m and let g(t,u)=t2+2tu3ug(t,u)=t2+2tu3u.
To set up for calculations, we use jcalc.
% file jdemo1.m
X = [2.37 1.93 0.47 0.11 0 0.57 1.22 2.15 2.97 3.74];
Y = [3.06 1.44 1.21 0.07 0.88 1.77 2.01 2.84];
P = 0.0001*[ 53 8 167 170 184 18 67 122 18 12;
11 13 143 221 241 153 87 125 122 185;
165 129 226 185 89 215 40 77 93 187;
165 163 205 64 60 66 118 239 67 201;
227 2 128 12 238 106 218 120 222 30;
93 93 22 179 175 186 221 65 129 4;
126 16 159 80 183 116 15 22 113 167;
198 101 101 154 158 58 220 230 228 211];
jdemo1 % Call for data
jcalc % Set up
Enter JOINT PROBABILITIES (as on the plane) P
Enter row matrix of VALUES of X X
Enter row matrix of VALUES of Y Y
Use array operations on matrices X, Y, PX, PY, t, u, and P
G = t.^2 + 2*t.*u  3*u; % Calculation of matrix of [g(t_i, u_j)]
EG = total(G.*P) % Direct calculation of expectation
EG = 3.2529
[Z,PZ] = csort(G,P); % Determination of distribution for Z
EZ = Z*PZ' % E[Z] from distribution
EZ = 3.2529