In [1]:
using PyPlot
In [2]:
function generate_data(n)
epsilon_values=Array(Float64,n)
for i=1:n
epsilon_values[i] = randn()
end
return epsilon_values
end
ts_length = 100
data = generate_data(ts_length)
plot(data, "b-")
Out[2]:
In [3]:
ts_length = 100
data = randn(ts_length)
plot(data, "b-")
Out[3]:
In [4]:
Pkg.add("Distributions")
In [5]:
Pkg.update()
In [8]:
using PyPlot
using Distributions
function plot_histogram(distribution, n)
epsilon_values = rand(distribution, n) # n draws from distribution
plt[:hist](epsilon_values)
end
lp = Laplace()
plot_histogram(lp, 500)
Out[8]:
In [7]:
rand(3)
Out[7]:
In [9]:
factorial(6)
Out[9]:
In [11]:
function factorial2(n)
k=1
for i in 1:n
k=k*i
end
return k
end
factorial2(6)
Out[11]:
In [14]:
function binomial_rv(n, p)
count = 0
U = rand(n)
for i in 1:n
if U[i] < p
count = count + 1 # Or count += 1
end
end
return count
end
for j in 1:20
b = binomial_rv(15, 0.8)
print("$b, ")
end
In [16]:
n=100000
count=0
for i in 1:n
u,v=rand(2)
d=sqrt((u-0.5)^2+(v-0.5)^2)
if d<0.5
count+=1
end
end
area_estimate=count/n
print(area_estimate*4)
In [ ]: