forked from milleratotago/Cupid
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Difference.m
58 lines (47 loc) · 1.76 KB
/
Difference.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
classdef Difference < dTransDuo
% Difference(BasisRV1,BasisRV2) creates a random variable that is
% the difference between two independent basis random variables,
% BasisRV1-BasisRV2
methods
function obj=Difference(Basis1,Basis2)
obj=obj@dTransDuo('Difference',Basis1,Basis2);
end
function FNXY = FofDuo(obj,X,Y)
FNXY = X - Y;
end
function X = ReverseFofDuo(obj,FNXY,Y)
X = FNXY + Y;
end
function [] = SetBoundsContin(obj)
obj.LowerBound = obj.BasisRV1.LowerBound - obj.BasisRV2.UpperBound;
obj.UpperBound = obj.BasisRV1.UpperBound - obj.BasisRV2.LowerBound;
end
function thispdf=PDF(obj,X)
if obj.DistType=='d'
thispdf = PDF@dDiscrete(obj,X);
return;
end
[thispdf, InBounds, Done] = MaybeSplinePDF(obj,X);
if Done
return;
end
for iel=1:numel(X)
if InBounds(iel)
thispdf(iel)=integral(@(x) obj.BasisRV1.PDF(obj.ReverseFofDuo(X(iel),x)).*obj.BasisRV2.PDF(x),obj.BasisRV2.LowerBound,obj.BasisRV2.UpperBound);
end
end
end
function thisval=Mean(obj)
if ~obj.Initialized
error(UninitializedError(obj));
end
thisval = obj.BasisRV1.Mean - obj.BasisRV2.Mean;
end
function thisval=Variance(obj)
if ~obj.Initialized
error(UninitializedError(obj));
end
thisval = obj.BasisRV1.Variance + obj.BasisRV2.Variance;
end
end % methods
end % class Difference