I got a question about nested while loops.
I want to run a calculation of a distribution for multiple values. Here mu
and kappa
.
import numpy as np
import matplotlib.pyplot as pl
import scipy.special as sps
mu = 1/9 # circular mean phase
mu_steps = 2/9
mu_end = 1
kappa = np.pi/8 # circular dispersion
kappa_steps = np.pi/8
kappa_end = np.pi/2
observations = 50
while mu <= mu_end:
while kappa <= kappa_end:
s = np.random.vonmises(mu, kappa, observations)
count, bins, ignored = pl.hist(s, observations, normed=True)
x = np.arange(-np.pi, np.pi, 2*np.pi/observations)
y = -np.exp(kappa*np.cos(x-mu))/(2*np.pi*sps.jn(0,kappa))
pl.plot(x, y/max(y), linewidth=2, color='r')
pl.show(False)
pl.draw()
kappa = kappa + kappa_steps
mu = mu + mu_steps
So I got the function running, but it doesn't stop. I know it would be an easy solution, but I don't see the tree for the forest anymore.
Can you see what the problem is here?
mu_steps == 0
; The variantmu
will always be<= mu_end
.