0

I am trying to plot the phase shift of perpendicular and parallel waves with variable angle of incidence, 0 to 180 degrees. The waves are travelling from index of refraction of 1.33 to medium with index of refraction of 1.5.

i used the following eqaution: Theory with equations <-- page 18

i used the following code:

def Phase(theta):

    n=1.5/1.33

    Shift=np.sqrt(np.sin(theta*np.pi/180)**2-n**2)
    Shift=Shift/np.cos(theta*np.pi/180)
    Shift=2*np.degrees(np.arctan(Shift))

    return Shift

print(Phase(x))

x=np.linspace(0,180,30)  

The problem is that i get [ nan nan nan nan nan nan nan nan nan nan] as return.

kevin
  • 141
  • 3
  • 15

2 Answers2

1

If your code is as shown, you are using x before assignment.

Try this:

def Phase(theta):

    n=1.5/1.33

    Shift=np.sqrt(np.sin(theta*np.pi/180)**2-n**2)
    Shift=Shift/np.cos(theta*np.pi/180)
    Shift=2*np.degrees(np.arctan(Shift))

    return Shift

x=np.linspace(0,180,30) 
print(Phase(x))
Peter Szabo
  • 1,056
  • 2
  • 14
  • 30
0

You are using the equation for total internal reflection (TIR), which is valid for theta > theta_critical. You will need to limit your input angles to this range. In addition, these equations require n < 1 with n defined as the ratio of the transmitted medium to the incident medium. For TIR, you are going from the higher index to the lower index, so n = n_2/n_1 = 1.33/1.5. Finally, incident angles are defined relative to the surface normal, so they should be in the range of 0 <= theta <= 90°.

Craig
  • 4,605
  • 1
  • 18
  • 28
  • I think i formulated the title incorrectly. The plot for TIR is something that i want to plot also but first i want to plot for incoming traveling from medium with refractive index n=1.33 to another medium with refractive index n=1.5 .... i get a Nan value as return even with 1/4 pi as input – kevin Dec 31 '17 at 18:01
  • These equations aren't valid for the low index to high index case. The phase shift for that case is either 0° or 180° as explained on page 16 of the slide deck you reference. You can handle that with a conditional statement. – Craig Dec 31 '17 at 18:06
  • my mistake, i just read the slide. haha, The phase shift is 0° for angles of incidence below when the reflection coefficients are positive, negative reflection coefficients result into 180° phase shift. i used the same code and printed angle of incidence to 40 degrees but still got `[ nan nan nan nan nan nan nan nan nan nan]` – kevin Dec 31 '17 at 18:44