Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using PyPlot
- function simulation(N::Int64)
- E1 = zeros(Float64,N)
- Eq1 = zeros(Float64,N)
- V1 = zeros(Float64,N)
- D1 = zeros(Float64,N)
- E2 = zeros(Float64,N)
- Eq2 = zeros(Float64,N)
- V2 = zeros(Float64,N)
- D2 = zeros(Float64,N)
- for n = 1:N
- for step = 1:5
- coin = rand(1:2)
- tmpE = 0.0
- # coin == 1 | tails
- # coin == 2 | heads
- if coin == 1
- E1[n] += 11.0
- tmpE = 11.0
- else
- E1[n] -= 110.0
- tmpE = -110.0
- end
- Eq1[n] = tmpE^2
- end
- V1[n] = Eq1[n] - (E1[n])^2
- D1[n] = sqrt(V1[n])
- for step = 1:1100
- coin = rand(1:2)
- tmpE2 = 0.0
- # coin == 1 | tails
- # coin == 2 | heads
- if coin == 1
- E2[n] -= 0.5
- tmpE = -0.5
- else
- E2[n] += 0.05
- tmpE = 0.05
- end
- Eq2[n] = tmpE^2
- end
- V2[n] = Eq2[n] - E2[n]^2
- D2[n] = sqrt(V2[n])
- end
- printDiagram(E1, D1, 0)
- printDiagram(E2, D2, 1)
- end
- function printDiagram(E::Array, D::Array, case::Int64)
- D1 = zeros(Float64,N)
- D2 = zeros(Float64,N)
- for i = 1:length(D)
- D1[i] = D[i] + 3
- D2[i] = D[i] - 3
- end
- msg = ""
- if case == 0
- msg = " game number 1"
- elseif case == 1
- msg = " game number 2"
- end
- x = 1:N
- fig, ax = subplots()
- suptitle("Zad1")
- #ax[:plot](x, E, linewidth=2, alpha=0.6, label="Average value of$msg")
- #ax[:plot](x, V, linewidth=2, alpha=0.6, label="Variation of$msg")
- ax[:plot](x, D1, linewidth=2, alpha=0.6, label="(+)Deviation of$msg")
- ax[:plot](x, D2, linewidth=2, alpha=0.6, label="(-)Deviation of$msg")
- ax[:legend]()
- fileName = string("lab4_$msg.png")
- savefig(fileName, dpi=72)
- end
- println("START")
- N = 100000
- simulation(N)
- println("END")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement