Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
Download

📚 The CoCalc Library - books, templates and other resources

132932 views
License: OTHER
1
% Thanks to Jake for the template
2
% http://tex.stackexchange.com/a/31715/5645
3
% and the help here
4
% http://tex.stackexchange.com/a/198793/5645
5
\documentclass{standalone}
6
7
\usepackage{pgfplots}
8
\pgfplotsset{compat=1.10}
9
10
\begin{document}
11
12
\pgfplotsset{
13
colormap={whitered}{color(0cm)=(white); color(1cm)=(orange!75!red)},
14
colormap={whiteblue}{color(0cm)=(white); color(1cm)=(blue)},
15
}
16
17
\begin{tikzpicture}[
18
declare function={mu11=60;},
19
declare function={mu12=20;},
20
declare function={sigma11=5;},
21
declare function={sigma12=5;},
22
declare function={mu21=70;},
23
declare function={mu22=40;},
24
declare function={sigma21=5;},
25
declare function={sigma22=5;},
26
declare function={rho=0.8;},
27
declare function={normal(\m,\s)=1/(2*\s*sqrt(pi))*exp(-(x-\m)^2/(2*\s^2));},
28
declare function={bivar(\ma,\sa,\mb,\sb,\rho)=
29
1/(2*pi*\sa*\sb*\rho) * exp(-((x-\ma)^2/\sa^2 + (y-\mb)^2/\sb^2 - (2*\rho*(x-\ma)*(y-\mb))/(\sa*\sb)))/(2*(1-\rho*\rho));}]
30
\begin{axis}[
31
width=15cm,
32
view={-15}{70},
33
enlargelimits=false,
34
grid=major,
35
domain=40:90,
36
y domain=0:60,
37
samples=60,
38
xlabel=$x_1$,
39
ylabel=$x_2$,
40
zlabel={$P$}
41
]
42
\addplot3 [
43
surf,
44
colormap={bluewhitered}{color(0cm)=(blue); color(0.5cm)=(white); color(1cm)=(orange!75!red)},
45
point meta={
46
(
47
bivar(mu11,sigma11,mu12,sigma12,rho)>
48
bivar(mu21,sigma21,mu22,sigma22,rho)?
49
bivar(mu11,sigma11,mu12,sigma12,rho):
50
-bivar(mu21,sigma21,mu22,sigma22,rho)
51
)
52
}
53
] {
54
max(
55
bivar(mu11,sigma11,mu12,sigma12,rho),
56
bivar(mu21,sigma21,mu22,sigma22,rho)
57
)};
58
59
\draw [black!50] (axis cs:-1,0,0) -- (axis cs:4,0,0);
60
\draw [black!50] (axis cs:0,-1,0) -- (axis cs:0,4,0);
61
62
\node at (axis cs:-1,1,0.18) [pin=165:$P(x_1)$] {};
63
\node at (axis cs:1.5,4,0.32) [pin=-15:$P(x_2)$] {};
64
\end{axis}
65
\end{tikzpicture}
66
\end{document}
67