-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathExercise01.py
59 lines (32 loc) · 866 Bytes
/
Exercise01.py
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
# coding: utf-8
# Exercise 01
# Q1: distribution P(x,y)
# In[12]:
import numpy
import matplotlib
import math
get_ipython().magic('matplotlib inline')
from matplotlib import pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
R = numpy.arange(-4,4+1e-9,0.1)
x,y = numpy.meshgrid(R,R)
# Define the probability function (discrete)
# In[11]:
z = sum(sum(math.e**(-0.5*(x**2+y**2))))
F = 1/z*math.e**(-0.5*(x**2+y**2))
fig = plt.figure(figsize=(10,6))
ax = plt.axes(projection='3d')
ax.scatter(X,Y,F,s=1,alpha=0.5)
# Q2: conditional distribution
# In[15]:
z = sum(sum(math.e**(-0.5*(x**2+y**2))))
F = 1/z*math.e**(-0.5*(x**2+y**2))
Fcon = F*((x**2+y**2)**0.5>=1)
Fcon1 = Fcon/Fcon.sum()
fig = plt.figure(figsize=(10,6))
ax = plt.axes(projection='3d')
ax.scatter(X,Y,Fcon1,s=1,alpha=0.5)
# Q3: Marginal distribution
# In[ ]:
# In[ ]:
# In[ ]: