Summing together values in while loop after two iterations

Viewed 22

I want to sum together the values of R_scat from both iterations of the while loop, and then add those products together too (i.e. add the values of R_i together) to give me one single value, but I am unsure how to do this. Here is the code:

# Libraries
import numpy as np
from scipy.integrate import odeint

# Tow counter propagating beams in x-axis
laser_x = np.linspace(0, 100, 100)
laser_negx= np.linspace(0, -100, 100)

# Constant parameters
m_Rb = 1.443*10**-25 #mass of rubidium 87
k_b = 1.38*10**-23
hbar = 1.05*10**-34
Rabi = 46.567*10**6 #Rabi frequency
L = 38.116*10**6 #spontaneous decay rate

# Changable paramaters
#delta_omega = -20*10**-6
#delta_omega = np.linspace(-20*10**6, 0, 15)
#delta_omega = np.array([-20*10**6, -15*10**6, -10*10**6, -5*10**6]) #difference in the laser frequency and the atomic resonance frequency
lmbda = 700*10**-9 #wavelength of laser light
k = (2*np.pi)/lmbda #wavevector of laser light
V = 1.25*10**-4 #volume of MOT space
length = 5*10**-2 #length of MOT
Bohr = 9.274*10**-24
B = 5*10**-4

# Maxwell Boltzmann distribution variables
T = 300
v = np.linspace(0, 10, 5)


# Number of particles emittied
T_oven = 300 #oven temperature
P = 10**(4.312-(4040/T_oven)) #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_oven) #atomic number density
I_oven = ((n*A)/4) * (2/(np.pi)**0.5) * ((2*k_b*T_oven)/m_Rb)**0.5
#print("The flux of atoms from the oven is", format(I_oven, '.1E'))

# Finding the rate of capture and population for the excited and ground states to find the scattering force
i = 0
delta_omega = np.array([-20*10**6, -10*10**6])
while i<len(delta_omega):
    delta = delta_omega[i] + (k*v)
    R_scat = L/2 * (Rabi**2/2)/(delta**2+(Rabi**2/2)+(L**2/4))
    R_i = np.sum(R_scat)
    print(R_scat)
    print(R_i)
    i = i+1

Here are the results I get from running this code:

[11184874.83348512 14217317.42150675  9999470.28332243  5605001.76872253
  3272710.81864173]
44279375.125678554
[13353256.50318438 12896933.7374322   7756401.89830628  4365821.90749169
  2646088.0800265 ]
41018502.126441054
1 Answers

What if you will create R_sum before while loop and make it an adder for R_i?

R_sum = 0
while i<len(delta_omega):
    delta = delta_omega[i] + (k*v)
    R_scat = L/2 * (Rabi**2/2)/(delta**2+(Rabi**2/2)+(L**2/4))
    R_i = np.sum(R_scat)

    R_sum += R_i

    print(R_scat)
    print(R_i)
    i = i+1
print(R_sum)  # sum of all values from both iterations
Related