Language Overview
using Plots
x = collect(1:10)
y = [xx+randn() for xx in x]
plot(x,y,seriestype=:scatter)
- two Monte Carlo method examples and the usage of
@time marco
using Statistics
@time begin
data = Float64[];
for _ in 1:10^6
group = Float64[];
for _ in 1:5*10^2
push!(group, rand())
end
push!(data, mean(group))
end
println("98% of the means lie in the estimamted range:",
(quantile(data,0.01)), (quantile(data,0.99))
)
end
using Statistics
@time begin
data = [mean(rand(5*10^2)) for _ in 1:10^6]
println("98% of the means lie in the estimamted range:",
(quantile(data,0.01)), (quantile(data,0.99))
)
end
- the example of variable scope
data = [1,2,3]
s = 0
β,γ = 2,1
for i in 1:length(data)
print(i," ")
global s
s += β*data[i]
data[i] *= -1
end
println("\nSum of data in extrnal scope: ", s)
function sumData(β)
s = 0
for i in 1:length(data)
s += data[i] + γ
end
return s
end
println("Sum of data in a function: ", sumData(β/2))
@show s