You are on page 1of 11

8/27/23, 9:44 PM Q.M LAB 3.

ipynb - Colaboratory

from urllib import request


import pandas as pd
import numpy as np
import matplotlib.pyplot as plt

import pandas as pd

# Constants
epsilon_o = 1 # Free space permitivity (F/m)
N_A = 6.02214076e23 # Avogadro's number

# Function to calculate K
def calculate_K(epsilon_o, M, rho, N_A):
K = (3 * epsilon_o * M) / (rho * N_A)
return K

# Function to calculate Polarisability αₚ


def calculate_polarisability(K, n):
alpha_p = (K * (n**2 - 1)) / (n**2 + 2)
return alpha_p

# Lists of data
liquids = ["Water", "Benzene", "Ethanol"]
temperatures = [20]
wavelengths = [589, 532, 652, 632]
refractive_indices = [
[1.333, 1.33, 1.475, 1.429], # Refractive index values for Water at T=20°C and each wavelength
[1.56, 1.441, 1.727, 1.673], # Refractive index values for Benzene at T=20°C and each wavelength
[1.36, 1.358, 1.505, 1.46] # Refractive index values for Ethanol at T=20°C and each wavelength
]

# Lists to store results


results = []

# Loop over liquids


for liquid, density, molar_mass, n_values in zip(liquids, [1, 0.8747, 0.789], [18.01528, 78.11184, 46.06844], refractive_indices):
liquid_results = []
for temp in temperatures:
temp_results = []
for wave, n in zip(wavelengths, n_values):
temperature = temp # Keep temperature in Celsius
wavelength = wave * 1e-9 # Convert to meters

K = calculate_K(epsilon_o, molar_mass, density, N_A)

alpha_p = calculate_polarisability(K, n)
temp_results.append((wavelength, n, K, alpha_p))
liquid_results.append(temp_results)
results.append(liquid_results)

# Create separate DataFrames for each liquid and temperature


dfs = []
for liquid_idx, liquid in enumerate(liquids):
for temp_idx, temp in enumerate(temperatures):
df_data = results[liquid_idx][temp_idx]
df = pd.DataFrame(df_data, columns=['Wavelength (nm)', 'Refractive Index', 'K Value', 'Polarisability αₚ'])
df['Li id'] li id
https://colab.research.google.com/drive/1_D7GnD1b9OI60c9h3CVhfgV7IHAcVL7H#scrollTo=RiSpIBU3r1G7&printMode=true 1/3
8/27/23, 9:44 PM Q.M LAB 3.ipynb - Colaboratory
df['Liquid'] = liquid
dfs.append(df)

# Displaying the separate DataFrames


for df in dfs:
print(f"Table showing Polarisability Refractive Index of {df['Liquid'][0]} at T=20°C:\n" )
print(df)
print("\n")

Table showing Polarisability Refractive Index of Water at T=20°C:

Wavelength (nm) Refractive Index K Value Polarisability αₚ Liquid


0 5.890000e-07 1.333 8.974523e-23 1.846019e-23 Water
1 5.320000e-07 1.330 8.974523e-23 1.830908e-23 Water
2 6.520000e-07 1.475 8.974523e-23 2.526729e-23 Water
3 6.320000e-07 1.429 8.974523e-23 2.313638e-23 Water

Table showing Polarisability Refractive Index of Benzene at T=20°C:

Wavelength (nm) Refractive Index K Value Polarisability αₚ Liquid


0 5.890000e-07 1.560 4.448649e-22 1.438466e-22 Benzene
1 5.320000e-07 1.441 4.448649e-22 1.174760e-22 Benzene
2 6.520000e-07 1.727 4.448649e-22 1.770100e-22 Benzene
3 6.320000e-07 1.673 4.448649e-22 1.667623e-22 Benzene

Table showing Polarisability Refractive Index of Ethanol at T=20°C:

Wavelength (nm) Refractive Index K Value Polarisability αₚ Liquid


0 5.890000e-07 1.360 2.908686e-22 6.419419e-23 Ethanol
1 5.320000e-07 1.358 2.908686e-22 6.387366e-23 Ethanol
2 6.520000e-07 1.505 2.908686e-22 8.627290e-23 Ethanol
3 6.320000e-07 1.460 2.908686e-22 7.966573e-23 Ethanol

https://colab.research.google.com/drive/1_D7GnD1b9OI60c9h3CVhfgV7IHAcVL7H#scrollTo=RiSpIBU3r1G7&printMode=true 2/3
8/27/23, 9:44 PM Q.M LAB 3.ipynb - Colaboratory

check 0s completed at 9:38 PM

https://colab.research.google.com/drive/1_D7GnD1b9OI60c9h3CVhfgV7IHAcVL7H#scrollTo=RiSpIBU3r1G7&printMode=true 3/3

You might also like