How would you do a cumulative sum in a while loop

Viewed 28

I have a while loop that will perform the calculation to get f for each of the frequencies in my delta_omega variable. I want it to perform the calculation cumulatively, i.e. if the first run uses 1Hz, then for the second run 2Hz is next in the array but it will perform the calculation with 1+2=3Hz, and so on for the next one with 3+3=6Hz. In the end, I want to plot this cumulative sum of delta_omega against the value I obtain for f.

import numpy as np
import matplotlib.pyplot as plt  

delta_omega = np.linspace(-900*10**6, -100*10**6, m) #Hz - range of frequencies
i = 0

while i<len(delta_omega):
    delta = delta_omega[i] - (k*v_cap) + (mu_eff*B)/hbar
    p_ee = (s0*L/2) / (1 + s0 + (2*delta/L)**2) #population of the excited state
    R = L * p_ee # scattering rate
    F = hbar*k*(R) #scattering force on atoms
    a = F/m_Rb #acceleration assumed constant
    
    vf_slower = (v_cap**2 - (2*a*z0))**0.5 #velocity at the end of the slower
    t_d = 1/a * (v_cap - vf_slower) #time taken during slower
    
    
    #       -------- After slower --------
    da = 0.1 #(m) distance from end of slower to the middle of the MOT
    vf_MOT = (vf_slower**2 - (2*a*da))**0.5 #(m/s) - velocity of the particles at MOT center
    t_a = da/vf_MOT #(s) time taken after slower
    
    r0 = 0.01 #MOT capture radius
    vr_max = r0/(t_b+t_d+t_a) #maximum transveral velocity
    
    
    vz_max = (v_cap**2 + 2*a_max*z0)**0.5 #m/s - maximum axial velocity
    
    
    #       -------- Flux of atoms captured --------
    P = 10**(4.312-(4040/T)) #vapour pressure for liquid phase (use 4.857 for solid phase)
    A = 5*10**-4 #area of the oven aperture
    n = P/(k_b*T) #atomic number density
    
    f_oven = ((n*A)/4) * (2/(np.pi)**0.5) * ((2*k_b*T)/m_Rb)**0.5
    f = f_oven * (1 - np.exp(-vr_max**2/vp**2))*(1 - np.exp(-vz_max**2/vp**2))
    i+=1
    
plt.plot(delta_omega, f)
0 Answers
Related