In: Computer Science
From optics, when light passes from one medium to another, it
bends according to Snell’s law of refraction, until it reaches the
critical angle, as defined by the ratio of the incident index of
refraction to the outgoing index of refraction. Let light incident
along the normal to the refracting surface be defined as having an
angle of 0. Write a program that calculates the sine of the
outgoing angle and plot it versus the sine of the incident angle
for the following cases:
a. air incident on water
b. air incident on benzene
c. air incident on lead glass
d. air incident on diamond
Use a step size in incident angle of 0.02 radians up to the
critical angle (note the critical angle will be different each in
each case). Write the program to take the incident index of
refraction and outgoing index of refraction as keyboard input. Also
write the Snell’s law calculation as a function that is called
within a loop. Then plot each one on the same plot
please answer using Jupyter notebook in python 3
Dear Student,
The refractive index of given elements is as follows:
I cannot upload the jupyter notebook, hence I am attaching the code in each cell as a single .py file. Please find the attached code below:
# note that every empty line space indicates the code in one cell
# including all the necessary libraries
import matplotlib.pyplot as plt
import numpy as np
# definming the Refractive indices of the materials
water = 1.333
benzene = 1.5
lead_glass = 1.7
diamond = 2.42
# taking input of the angle of incidence (in radians)
i = float(input("Enter the angle of incidence: "))
# to plot for water
x_w = np.arange(i,np.arcsin(1/water),0.02) # start,stop,step
y_w = []
for k in range(len(x_w)):
ref = np.sin(x_w[k])/water
y_w.append(ref)
# to plot for benzene
x_b = np.arange(i,np.arcsin(1/benzene),0.02) # start,stop,step
y_b = []
for k in range(len(x_b)):
ref = np.sin(x_b[k])/benzene
y_b.append(ref)
# to plot for lead glass
x_lg = np.arange(i,np.arcsin(1/lead_glass),0.02) # start,stop,step
y_lg = []
for k in range(len(x_lg)):
ref = np.sin(x_lg[k])/lead_glass
y_lg.append(ref)
# to plot for diamond
x_d = np.arange(i,np.arcsin(1/diamond),0.02) # start,stop,step
y_d = []
for k in range(len(x_d)):
ref = np.sin(x_d[k])/diamond
y_d.append(ref)
plt.plot(x_w, y_w, label = "Water")
plt.plot(x_b, y_b, label = "Benzene")
plt.plot(x_lg, y_lg, label = "Lead Glass")
plt.plot(x_d, y_d, label = "Diamond")
plt.xlabel('Angle of refraction')
# Set the y axis label of the current axis.
plt.ylabel('Angle of incidence')
# Set a title of the current axes.
plt.title('Refractive indices')
# show a legend on the plot
plt.legend()
# Display a figure.
plt.show()
Output: (for i = 0.4)
Thank you, please upvote!