In [4]:
using PyPlot
ts_length = 100
epsilon_values = randn(ts_length)
plot(epsilon_values, "blue")
Out[4]:
In [31]:
#collect(3:10)
# ここの処理は〜〜〜
#plot(collect(1:100), epsilon_values, "blue")
s = linspace(0, 1, 11)
Out[31]:
In [49]:
ts_length = 100
array = zeros(Int64, 2, 2, 2, 2)
#array[:, :, :] = 0
#array[1, 1, 1] = 21
array
Out[49]:
In [51]:
array = [10, "にゃん", false]
array
Out[51]:
In [66]:
array = Array{Any}(3)
array[3] = 20
array[2] = "aiueo"
array[1] = 10.2
array[3] = "aaaaa"
array
Out[66]:
In [72]:
array = ["2", 30, "🙅"]
typeof(array[3])
Out[72]:
In [73]:
array = [3, 2, "20", "aiueo", false]
length(array)
Out[73]:
In [74]:
array = [2 3; 2 1]
length(array)
Out[74]:
In [79]:
array = [3, 2, "20", "aiueo", false]
pop!(array)
array
Out[79]:
In [81]:
array = [3, 2, "20", "aiueo", false]
x = "added"
push!(array, x)
array
Out[81]:
In [90]:
array = ["aiueo", 3, false, 20.3]
for variable in array
println(variable)
end
In [99]:
array = ["aiueo", 3, false, 20.3]
for i in 1:3
println(i, ": ", array[i])
end
In [105]:
ts_length = 100
epsilon_values = Array(Float64, ts_length)
for i in 1:ts_length
epsilon_values[i] = randn()
end
epsilon_values
#plot(epsilon_values, "b-")
Out[105]:
In [107]:
words = ["foo", "bar"]
for word in words
println("Hello $(word)")
end
In [112]:
xs = [2pi, pi/2, pi/3]
for x in xs
println("Hello $(cos(x))")
end
In [119]:
s = 0
i = 1
while true
s += i
i += 1
end
print(s)
In [120]:
s = 0
i = 1
while true
s += i
i += 1
if i > 10
break
end
end
print(s)
In [121]:
function my_sum(from, to)
s = 0
for i = from:to
s += i
end
return s
end
Out[121]:
In [123]:
my_sum(2, 10)
Out[123]:
In [1]:
using Distributions
In [12]:
Normal(1, 2)
Out[12]:
In [13]:
function plot_histogram(distribution, n)
epsilon_values = rand(distribution, n) # n draws from distribution
plt[:hist](epsilon_values)
end
lp = Normal(5, 1)
plot_histogram(lp, 5000)
Out[13]:
In [15]:
rand(100)
Out[15]:
In [18]:
my_factorial(n) = reduce(*, collect(1:n))
Out[18]:
In [19]:
my_factorial(4)
Out[19]:
非整数に対応してみる
In [ ]:
In [20]:
my_binomial_rv(n, p) = sum(rand(n) .< p)
Out[20]:
In [24]:
for i=1:20
println(my_binomial_rv(10, 0.1))
end
In [89]:
function montecalro_pi(size)
sample = rand(size, 2)
inner = 0.0
for (s1, s2) in zip(sample[:, 1], sample[:, 2])
inner += s1^2 + s2^2 <= 1 ? 1 : 0
end
return inner * 4 / size
end
Out[89]:
In [92]:
print( montecalro_pi(1000000) )
In [38]:
function coin(n, x, p)
total = 2^n
sucess = 0
for i=x:n
sucess += factorial(n) / factorial(i) / factorial(n-i)
end
return sucess / total
end
Out[38]:
In [39]:
coin(10, 3, 0.5)
Out[39]:
In [ ]: