forked from uafgeotools/capuaf
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathomegapdf.m
More file actions
112 lines (93 loc) · 3.15 KB
/
omegapdf.m
File metadata and controls
112 lines (93 loc) · 3.15 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
function [p,t,pcum] = omegapdf(x,bfigure)
%OMEGAPDF probability density function for random moment tensors
%
% INPUT
% x option A: an integer number of points for discretization OR
% option B: an input vector of points at which to evaluate the PDF
% INPUT IS IN RADIANS, NOT DEGREES
%
% OUTPUT
% p PDF discretized based on input choice
% t discretization of omega (IN RADIANS)
% pcum CDF discretized based on input choice
%
% See also plot_omega.m, kaganpdf.m, omegadcpdf.m, run_unformMT.m
%
% EXAMPLES (see longer example below):
% x = linspace(0,pi,181); p = omegapdf(x,true);
% [p,t] = omegapdf(10,true);
% [p,~,pcum] = omegapdf(x); figure; plot(x,pcum);
%
if nargin==1, bfigure=false; end
% key points on curve
t0 = 0;
t3 = pi;
% evaluate the PDF at the bin centers
if length(x)==1
n = round(x);
dt = t3/n;
t = [dt/2 : dt : t3-dt/2]; % centers of bins
tx1 = t - dt/2; % left edge of bin
tx2 = t + dt/2; % right edge of bin
else
t = x;
n = length(t);
dt = t(2)-t(1);
tx1 = [];
tx2 = [];
end
p = omegafun(t);
pcum = omegafuncum(t);
if length(x)==1
% numerically integrate the PDF for each bin
pint = zeros(n,1);
xtol = 1e-12;
for ii=1:n
pint(ii) = integral(@(x) omegafun(x), tx1(ii), tx2(ii),'AbsTol',xtol,'RelTol',xtol);
end
% integration check
disp(sprintf('integration check using %i bars: %.14f',n,sum(p)*dt));
disp(sprintf('integration check using matlab: %.14f',sum(pint)));
p = pint/dt;
end
% % cumulative density function
% cint = cumsum(pint); % pint will be very accurate
% %cint = zeros(n,1);
% %for ii=1:n
% % cint(ii) = integral(fun, t0, tx2(ii),'AbsTol',xtol,'RelTol',xtol);
% %end
if bfigure
tsmooth = linspace(t0,t3,400);
psmooth = omegafun(tsmooth);
%pt1 = 4/pi;
%pt2 = 4/pi*(-8/3 + sqrt(8));
figure; nr=2; nc=1; ymax = 1.5;
subplot(nr,nc,1); hold on;
plot(tsmooth,psmooth,'b');
plot(t,p,'r.--');
%plot([t1 t1],[0 pt1],'k--',[t2 t2],[0 pt2],'k--');
%plot([t0 t1 t2 t3],[0 pt1 pt2 0],'bo','markersize',14,'markerfacecolor','r','linewidth',1);
axis equal; axis([0 t3 0 ymax]);
xlabel('t, radians');
ylabel('p_{\omega}(t)');
title(sprintf('PDF for random moment tensors (n = %i)',n));
subplot(nr,nc,2); hold on;
bar(t,p,1,'c');
plot(t,p,'r.');
plot(tsmooth,psmooth,'b');
%plot([t1 t1],[0 pt1],'k--',[t2 t2],[0 pt2],'k--');
%plot([0 t1 t2 t3],[0 pt1 pt2 0],'bo','markersize',14,'markerfacecolor','r','linewidth',1);
axis equal; axis([t0 t3 0 ymax]);
xlabel('t, radians');
ylabel('p_{\omega}(t)');
title(sprintf('PDF for random moment tensors (n = %i)',n));
end
%--------------------------------------------------------------------------
function p = omegafun(t)
K = 3*pi/8; % integral of sin^4(x)
p = sin(t).^4 / K;
%--------------------------------------------------------------------------
function pcum = omegafuncum(t)
% The cumulative distribution is the integral of the probability density sin(t).^4 / K
pcum = (12*t - 8*sin(2*t) + sin(4*t)) / (12*pi);
%==========================================================================