0% found this document useful (0 votes)
20 views60 pages

Python Optics: A Comprehensive Guide

The document titled 'Python Optics' provides an overview of using Python for optics-related programming, covering installation, basic programming concepts, and specific applications in optics such as refraction, lens equations, and diffraction. It includes detailed tutorials on Python syntax, data types, operators, and plotting with libraries like matplotlib. The publication was authored by Vasudevan Lakshminarayanan and Ritambhar Burman and was published in October 2015.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
20 views60 pages

Python Optics: A Comprehensive Guide

The document titled 'Python Optics' provides an overview of using Python for optics-related programming, covering installation, basic programming concepts, and specific applications in optics such as refraction, lens equations, and diffraction. It includes detailed tutorials on Python syntax, data types, operators, and plotting with libraries like matplotlib. The publication was authored by Vasudevan Lakshminarayanan and Ritambhar Burman and was published in October 2015.
Copyright
© All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd

See discussions, stats, and author profiles for this publication at: [Link]

net/publication/283121394

Python Optics

Research · October 2015


DOI: 10.13140/RG.2.1.2940.2325

CITATIONS READS
3 11,309

2 authors:

Vasudevan Lakshminarayanan Ritambhar Burman


University of Waterloo University of Miami
594 PUBLICATIONS 6,136 CITATIONS 30 PUBLICATIONS 519 CITATIONS

SEE PROFILE SEE PROFILE

All content following this page was uploaded by Vasudevan Lakshminarayanan on 24 October 2015.

The user has requested enhancement of the downloaded file.


OPTICS TUTORIALS WITH PYTHON
Page |2

INDEX Page
PART  1:  PYTHON  
! OVERVIEW OF PYTHON
1.1 WHAT IS PYTHON 5
1.2 WHY PYTHON 5
1.3 INSTALLING PYTHON 5
1.4 FOR PLOTTING IN PYTHON 5
1.5 CODE COMPATIBILITY PROBLEMS IN PYTHON 6
! RUNNING A PROGRAM IN PYTHON
2.1 TO RUN A PROGRAM IN PYTHON 7
2.2 BASIC PROGRAM 7
2.3 COMMENTS IN PYTHON 7
2.4 IDENTIFIERS IN PYTHON 8
2.5 INDENTATION IN PYTHON 9

2.6 TYPES OF INPUT IN PYTHON 9


2.7 BASIC OPERATION IN PYTHON 10
2.8 COMPARISON OF OPERATORS IN PYTHON 12
2.9 PYTHON LOGICAL OPERATORS 13

2.10 LOOP OPERATION IN PYTHON 13


2.11 LOOP CONTROL STATEMENTS IN PYTHON 15
! PYTHON NUMBERS
3.1 INTRODUCTION 17

3.2 BASIC MATHEMATICAL FUNCTION IN PYTHON 17


3.3 TRIGONOMETRIC FUNCTIONS IN PYTHON 17
! PLOTTING IN PYTHON
4.1 BASIC PLOTTING IN PYTHON 19

4.2 MULTIPLE PLOTTING IN PYTHON 21

 
 
 
 
 
 
 
Page |3

INDEX Page
PART  2:  INTRODUCTION  OF  PYTHON  IN  OPTICS  
! REFRACTION
5.1 SNELL’S LAW 25
5.2 CRITICAL ANGLE AND TOTAL INTERNAL REFLECTION 29
! LENS AND MIRRORS
6.1 SIGN CONVENTION IN OPTICS 31
6.2 POWER OF A LENS 31
6.3 THIN LENS EQUATION 35
! POLARIZATION OF LIGHT
7.1 BREWSTER’S ANGLE 38
7.2 MALUS’ LAW 39
7.3 RAYLEIGH SCATTERING 41
! DIFFRACTION OF LIGHT

8.1 SINGLE SLIT DIFFRACTION 46


8.2 YOUNG’S DOUBLE SLIT DIFFRACTION EXPERIMENT 47
8.3 DIFFRACTION GRATING 52
8.4 DIFFRACTION FROM CIRCULAR APERTURE 55

8.5 RAYLEIGH CRITERION 57


Page |4

PART  1:  Brief  Introduction  to  Python  


Language  
Page |5

Chapter 1: Overview of Python


1.1 What is Python
Python is a widely used general-purpose high level programming language, designed by Guido van
Rossum in 1991.
1.2 Why Python
Python has several advantages over other programming languages. They are:
i. Code readability
ii. Easy syntax
iii. English like keywords
iv. Concise programs
v. Automatic Memory languages
vi. Free and open source software
1.3 Installing Python
To install Python, there are two recent stable versions of Python, Python 3.4.1 and Python 2.7.8. However
some codes of Python of 2.x need to be modified to be executed in Python 3.x. Due to slightly worse
library support, and default version of Python being 2.x in Mac and Linux distributions, it is
recommended to use Python 2.7.8.
i. [Link] is the official site of Python.
ii. Check the CPU processor, 32 bit or 64 bit and the operating system, Linux or Mac or
Windows.
iii. Go to [Link] for the download site.
iv. For 32 bit OS,
a. Install Python 2.7.8 Windows Installer for Windows OS.
b. Install Python 2.7.8 Mac OS X 32-bit i386/PPC Installer for Mac OS.
v. For 64 bit OS,
a. Install Python 2.7.8 Windows X86-64 Installer for Windows OS.
b. Install Python 2.7.8 Mac OS X 64-bit/32-bit x86-64/i386 Installer for Mac OS.
c. For Linux, Python is available by default.
1.4 For Plotting in Python
To plot in Python, John D. Hunter developed a python 2D plotting library for publication quality figure
called matplotlib. The official page of matplotlib is [Link]
Installing matplotlib:
i. Go to [Link] the official download page of matplotlib library.
Page |6

ii. For 32 bit OS,


a. Install [Link] for Mac OS.
b. Install [Link] for Windows OS.
iii. For 64 bit OS,
a. Install [Link] for Windows OS.
b. Install [Link] for Mac OS.
1.5 Code compatibility problems in Python
Since its appearance in 1991, Python has seen several changes in coding over its versions. Some might
face problems in running the codes of one Python version in other Python versions. So to get rid of this
problem,
i. Go to [Link] and click [Link] (md5).
ii. Extract the Zip folder
iii. Copy the contents to the default location of Python 2.7.68 in the computer.
Page |7

Chapter 2: Running a Program in Python


2.1 To run a program in Python
i. Open a new script in Python, write the code and save the script.
ii. Under Run tab, click on Run Module.
iii. If there is no error, the program will automatically run. If there is an error, it shows a
potential site of error. Recheck the error site and run the program again.

2.2 Basic Program


" Program 1:
>>>
print “Hello World!”
>>>
o Output:
>>>
Hello World!
>>>
o Explanation:
print is used to print the statement that follows the print command.
Remember that the syntax varies from version to version. This syntax is valid for version 2.7.8.
Also print ‘Hello World!’ will print the same output. The starting and end delimiter must be the same.
The delimiters can be further understood by the following example.
" Program 2:
>>>
print “The baby’s face is cute.”
print ‘The baby”s face is cute.’
>>>
o Output:
>>>
The baby’s face is cute.
The baby”s face is cute.
>>>
2.3 Comments in Python
It is always a good practice to include comments in every step of coding to make the code easily
accessible. In Python, comments are given by a # sign.
Page |8

" Program 3:
>>>
#Program to print Hello World!
print “Hello World!”
>>>
o Output:
>>>
Hello World!
>>>
! Note: Comments can also be included after the statement.
" Alternate of Program 3:
>>>
print “Hello World!” #Program to print Hello World
>>>
o Output:
>>>
Hello World!
>>>
2.4 Identifiers in Python
In Python, identifiers are used to define variables, function, class or module. For the time being, let us
stick to variables.
" Program 4:
>>>
a=2
A=3
Aa=a+A
print Aa
>>>
o Output:
>>>
5
>>>
o Explanation:
‘=’ is an assignment operator that assigns 2 to the variable a, 3 to the variable A. Aa is assigned the
summation of A and a. Identifiers are case-sensitive. Note that Aa, A and a are different variables and
Page |9

hence different identifiers. Usually the name of the identifiers can be anything except a few reserved
words like ‘and’, ‘or’ , ‘break’ etc, which describe some inbuilt function or operation and are described
later on in the text.
2.5 Indentation in Python
Python uses whitespace indentation to delimit blocks. An increase in indentation comes after certain
statements, while a decrease in indentation signifies the end of the current block.
" Program 5:

>>>
for j in sequence:
statement 1
statement 2
>>>
o Explanation:
Statement 1 belongs to the for loop due to the whitespace indentation, while statement 2 is not a part of
the for loop. The functioning of the for loop will be discussed in detail later.
2.6 Types of input in Python
There are two types of input in Python:
a. input() uses raw_input to read a string of data, and then attempts to evaluate it as if it were a Python
program, and then returns the value that results.
b. raw_input() asks the user for a string of data and returns the string. It might also be used to give some
prompts.
The main difference is that input() expects a syntactically correct python statement where raw_input()
does not. Raw_input does not exist in Python 3.x.
" Program 6:
>>>
A=input(‘Enter a number: ’)
B=raw_input(‘Enter your name: ’)
C=raw_input(‘Enter a number: ’)
print A
print B
print C
>>>
o Output:
>>>
Enter a number:
<User input> (say 54)
Enter your name:
P a g e | 10

<User input> (say ABC)


Enter a number:
<User input> (say 56)
54
ABC
56
>>>
o Explanation:
input() treats the user input as an integer in this respect, but raw_input() converts it into string.
>>> input(‘Enter a name: ’)
<user input> (say XYZ) will be erroneous as it cannot evaluate a character string as input is equivalent to
eval(raw_input()).
2.7 Basic operation in Python
Operators in python are fairly easy to write like +, –, /, *, ** and %. Their operation is given by the
following program involving two operands a and b.
" Program 7:
>>>
a=4
b=2
print (a+b)
print (a-b)
print (a*b)
print (a/b)
print (a%b)
print (a**b)
>>>
o Output:
>>>
6
2
8
2
0
16
>>>
P a g e | 11

o Explanation:
+ implies summation of the operands. – implies a subtraction and * implies a multiplication. % implies
the remainder present when the left operand is divided by the right operand. By left and right operand, it
means the operands present to the left and right of the operator respectively. ** performs the exponential
power of the operands. / gives the quotient when the right operand is divided by the left operand. The
following problem looks into the details of / more closely.
" Problem 8:
>>> print(2/3)
print(2/3.0)
print(2.0/3)
print(2.0/3.0)
print(4.0/2)
>>>
o Output:
>>>
0
0.666666666667
0.666666666667
0.666666666667
2.0
>>>
o Explanation:
If the operands are integers i.e. of int format, the operator cannot change the format; it can simply
calculate the results in the same format. Hence 0.666666666667 is printed as 0 in the first case. However
if either of the operands are floating point number, then the result is always in floating point. So there is
error in the first case when 2/3 gives 0. So 2 + 3.0 will be 5.0(floating point) and not 5(an integer).
Another method of rectifying this problem is mentioning at the beginning of the script:
from __future__ import division
" Problem 9:
>>>
from __future__ import division
print(4/2)
print(5/3)
>>>
o Output:
>>>
2.0
P a g e | 12

1.666666666667
>>>
o Explanation:
The internal difference is that without that import, / is mapped to the __div_ () method, also called the
classic division, while with it, __truediv__() is used which is also called the real division. __truediv__()
converts the operands in floating point formats and so results in floating point numbers.
2.8 Comparison of operators in Python
In Python, the operands can be compared by == , != , < , > , <> , <= and >= . The following problem
illustrates the function of the operands:
" Problem 10:
>>>
print 2==3
print 2!=3
print 2<3
print 3>2
print 3<>4
print 4<=3
print 4>=5
>>>
o Output:
>>>
False
True
True
True
True
False
False
>>>
o Explanation:
== is different from =. = is an assignment operator that helps in assigning a value to a variable. == helps
in comparing the equality of two operands. The comparison of two operators results in Boolean results,
i.e. either True or False. != helps in comparing the inequality of the two operands. < , > , <> , <= and >=
checks the validity of whether the left operands is less than, greater than, greater or less than, less than
equal to and greater than equal to the right operand.
In addition to the above operands, there are a few other operands that help in reducing the size of the
codes like += , -= , *= , /= , %= and **= .
P a g e | 13

Let a and b be two operands.


>>> a=a+b
>>> a+=b
The above statements are same, but the second statement requires less memory allocation than the first
statement. Here new a is assigned the summation of a and b. It is always advisable to write the code that
requires as less memory as possible and requires as less computation time as possible.
Similarly,
>>> a=a-b
>>> a-=b
2.9 Python Logical Operators
Another useful way of writing logical operations is the use of operators like and, or and not. And operator
gives True when both the conditions of and are true, else False. Or gives True when either of the
conditions are True. Not operator acts as the Boolean Not operator and checks the invalidity of the
statement following the Not operator.
" Problem 11:
print (4==4) and (5==4)
print (4==4) or (5==4)
print not (4==4)
o Output:
False
True
False
o Explanation:
== is the equality detector between the two operands. 4==4 is True. But 5==4 is False. So and statement
will show True when all the statements, linked with and, are true. Or statement will show True when
either of the statements, linked with or, is true. Not statement detects that 4 is indeed equal to 4. Since not
is the inequality detector, it will show False to the above valid statement. In other words, if the statement
is True, not will reverse the verdict and show False; if the statement is False, not will reverse the verdict
and show True.
2.10 Loop operation in Python
The two basic loop operations in Python are while and for. While statement repeats a statement while a
given condition is true. For statement executes a sequence of statement multiple times and controls the
loop variable until the ending criteria is met. The following two problems 12 and 13 illustrate the while
and for loop operation.
" Problem 12:
>>>
a=1
while (a<4):
print a
P a g e | 14

a+=1
>>>
o Output:
>>>
1
2
3
>>>
o Explanation:
In the first line, the variable a is assigned the value 1. Then the group of statements are executed inside
the while loop is executed. The white line indentation shows that the next two lines are within the while
loop.
o Step by step details of Problem 12:
Step I: a=1. So (a<4) is True. So the while loop is executed. The print statement prints 1. The value of a is
now increased to 2. The program counter is now goes to the beginning of the while loop.
Step II: a=2. So (a<4) is True. So the while loop is executed. The print statement prints 2. The value of a
is now increased to 3. The program counter is now goes to the beginning of the while loop.
Step III: a=3. So (a<4) is True. So the while loop is executed. The print statement prints 3. The value of a
is now increased to 4. The program counter is now goes to the beginning of the while loop.
Step IV: a=4. So (a<4) is False. So the while loop is not executed. The program counter is now goes to
the end of the while loop.
" Program 13:
>>>
for i in range(1,4):
print i
print i
>>>
o Output:
>>>
1
2
3
3
>>>
o Explanation:
range(1,4) is an array of integers from 1 to 3. The structure of the for loop is as followed:
>>>
P a g e | 15

for i in sequence:
statement(s)
>>>
If the sequence block contains an expression list, the expressions are evaluated first. Then the first term of
the sequence is assigned to i and the statement(s) block is evaluated. Then the next term of the sequence is
evaluated and assigned to i and the process continues till all the elements in sequence are exhausted. Note
that the colon at the end of the for loop is important syntactically.
The white space indentation means that the statements are included in the for loop until and unless there is
a decrease in the indentation.
So problem 13 can be simplified as followed:
>>>
for i in sequence:
Statement 1
Statement 2
>>>
So, Statement 1 is included in the for loop due to the indentation. Print statement is used here to print the
value of the variable i. Statement 2 does not have the white space indentation and so it is not a part of the
for loop. Then statement 2 falls outside the for loop.
o Step by step analysis of problem 13:
Step I: range(1,4) is evaluated as an array { 1, 2, 3}.
Step II: i is fixed to the first element of the array { 1, 2, 3} i.e. 1. The print statement prints 1. The
program counter goes to the beginning of the for loop.
Step III: i is fixed to the second element of the array { 1, 2, 3} i.e. 2. The print statement prints 2. The
program counter goes to the beginning of the for loop.
Step IV: i is fixed to the third element of the array { 1, 2, 3} i.e. 3. The print statement prints 3. The
program counter goes to the beginning of the for loop.
Step V: There are no more elements in the array { 1, 2 , 3}. So the for loop statement is not executed
anymore. The program counter then goes to the statement following the for loop. The print statement
prints the value of i, which is fixed at 3.
Hence we see the output of program 13 as 1, 2, 3 and 3.
In addition to the basic loop structures, nested loop helps in complex loop structures involving one or
more loops inside a single loop.
2.11 Loop control statements in Python
There are some control statements that can assist the programmer in writing the loop like break, pass and
continue.
Break statement will terminate the statement and the program will start the execution from the statement
immediately following the immediate loop structure.
Continue statement allows the program to skip the remainder of the body and start the execution from the
beginning of the loop structure after checking the ending criteria of the loop.
P a g e | 16

Pass statement appears merely as a function that does not have any function. So the program continues the
execution as normal.
" Program 14:
>>>
for i in range(1,5):
if i>3:
break
print i
if i+3>4:
continue
print i
print i
>>>
o Output:
>>>
1
1
2
3
4
>>>
o Explanation:
range(1,5) is an array containing elements { 1, 2, 3, 4}.
o Step by step analysis of program 14:
Step I: i is fixed to value 1. 1>3 condition is false. So the break statement is not executed. The print
statement prints 1. Pass statement passes the execution of the program to the next statement. The next if
loop is evaluated as false since the condition 4>4 is false. The continue statement is not executed. The
print statement prints 1.
Step II: i is fixed to value 2. 2>3 condition is false. So the break statement is not executed. The print
statement prints 2. The next if loop is evaluated as true since the condition 5>4 is indeed true. The
continue statement passes the execution of the program to the beginning of the program without executing
the print statement.
Step III: i is fixed to value 3. 3>3 condition is false. So the break statement is not executed. The print
statement prints 3. The next if loop is evaluated as true since the condition 6>4 is indeed true. The
continue statement passes the execution of the program to the beginning of the program without executing
the print statement.
P a g e | 17

Step IV: i is fixed to value 4. 4>3 condition being true, the break statement is executed and the loop
breaks. The program execution is passed on to the next statement of print. The print statement prints the
value 4.

Chapter 3: Python Numbers


3.1 Introduction
There are four basic formats of numbers in Python: int, long, float and complex.
int(x), long(x), float(x) and complex(x) are the basic syntax of representing a number in integer, long,
float or complex formats with zero as the imaginary part respectively. complex(x,y) is the basic syntax of
converting x+yj where x and y are numbers and j is the imaginary square root of -1. Integer format
includes all positive and negative numbers having no decimal points. Long or long integer formats
include all numbers that have unlimited size and are usually denoted by a number followed by L. So,
323.43423439L is a long integer. Floating point numbers are numbers, both positive and negative, having
a decimal point, and may also contain an exponential term, usually denoted by e. For example, 3.546e-02
indicates 0.03546, while -3.25e+02 indicates -325.
3.2 Basic mathematical function in Python
There are some basic mathematical function, that assist in writing the program. In order to use the inbuilt
functions, Python has to import necessary files from a particular library called math. For importing the
files from the library, type the following at the beginning of the program:
>>>
import math
>>>
To use each and every function under this library file, “math.” has to be added before each function. For
example, in order to use log(x), the function to be used is [Link](x).
The most common functions are listed below:
a. log(x) : Calculates the natural logarithmic value of x.
b. abs(x) : Calculates the absolute value of x.
c. ceil(x): Calculates the integer greater than or equal to x.
d. floor(x) : Calculates the integer less than or equal to x.
e. round(x) : Calculates the nearest integer value of x.
f. exp(x) : Calculates the exponential value of x i.e. ex.
g. max(x1, x2, ...) : Calculates the largest value among its arguments x1, x2, ... .
h. min(x1, x2, ...) : Calculates the least value among its arguments x1, x2, ... .
3.3 Trigonometric functions in Python
There are some trigonometric functions inbuilt in Python. But they deal with radians. So degrees need to
be converted to radians wherever applicable. The most common functions are listed below:
a. cos(x) : It calculates the cosine of an angle x in radian.
P a g e | 18

b. sin(x) : It calculates the sine of an angle x in radian.


c. tan(x) : It calculates the tangent of an angle x in radian.
d. acos(x) : It calculates the arc cosine of an angle x in radian.
e. asin(x) : It calculates the arc sine of an angle x in radian.
f. atan(x) : It calculates the arc tangent of an angle x in radian.
g. degrees(x) : It converts x radians into degrees.
h. radians(x) : It converts x degrees into radians.
! Note: The following example will illustrate a common error that a user often makes in Python:
" Program 15:
import math
print [Link]([Link](90))
print [Link](90/180*[Link])
o Output:
6.123233995736766e-17
1.0
o Explanation:
Now for the first case, the reason behind the value of cos(900) being close to 0, but not exactly 0 is due to
representation error. According to IEEE double precision format, every number is denoted by binary
numbers containing 53 bits. The method of evaluation of [Link] is the evaluation of an infinite series.
Due to its limitation, Python shows the result after evaluating a finite number of terms and tries to
represent it in 53 bits. Hence the value is close to 0, but not exactly 0.
900 can be converted to radians by the inbuilt [Link] function of Python. Also, 900 can be converted
to radians by multiplying it with [Link]/180. When used, both the cosine values are expected to be equal.
But here, both the results are different. Cos(900) should be equal to 0. But it is found that the first result is
close to 0, while the other one is actually cos(00). It is because 90/180 is treated as 0 by Python instead of
0.5 in the second case. So the second case gives a value equal to cos(00) as expected. It can be rectified by
the following ways:
a) import math
[Link](90.0/180*[Link])
b) >>>
import math
[Link](90/180.0*[Link])
>>>
c) >>>
import math
[Link](90.0/180.0*[Link])
>>>
P a g e | 19

d) >>>
from __future__ import division
import math
[Link](90/180*[Link])
>>>

Chapter 4: Plotting in Python


4.1 Basic Plotting in Python
Python calls Matplotlib for plotting in Python. There are various inbuilt functions that can make the
plotting interface more user-friendly. [Link] is a collection of command style functions that
can make matplotlib plot like Matlab. To use functions of [Link], the first thing to do is write
the import statement.
>>>
import [Link] as plt
>>>
Here plt keeps track of the current figure and plotting area, and the plotting functions are directed to the
current axes.
Note: plt is used as a sample name. It is not necessary to write plt, but any other name can be used.
The function used for plotting is plot(). Problem 16 will give an introduction to some basic plotting
functions.
" Problem 16:
>>>
import [Link] as plt
[Link]([1,2,3,4,5,6,7,8,9,10],[1,4,9,16,25,36,49,64,81,100])
[Link]( 'X AXIS' , fontsize=20 , fontweight = 'bold', family='fantasy')
[Link]( 'Y AXIS' , fontsize=25 , fontweight = 'black', fontstyle='italic')
[Link]( 'Sample Python Plotting' )
[Link]()
>>>
o Output:
>>>
P a g e | 20

>>>
o Explanation:
The first array of arguments in plot is the set of points in the x-axis, and the second set of arguments in
plot is the set of points in the y-axis.
xlabel() and ylabel() are respectively used for naming the x-axis and y-axis respectively.
Fontsize is used to set the fontsize of the text and is generally represented as a number.
Fontweight is used for setting the weights of the character in the text, and can be set as one of the
following: ‘light’, ‘normal’, ‘regular’, ‘book’, ‘medium’, ‘roman’, ‘semibold’, ‘demibold’, ‘demi’, ‘bold’,
‘heavy’, ‘extra bold’, ‘black’.
Family is generally the writing family of the text and can be set as one of the following defaults: ‘serif’,
‘sans-serif’, ‘cursive’, ‘fantasy’, or ‘monospace’.
Style is generally the representation style of the text and can be one of the following defaults: ‘normal’,
‘italic’ or ‘oblique’.
Suptitle() is used to name the title of the figure.
Finally show() is used to view the plot.
" Problem 17:
>>>
import [Link] as plt
[Link]([1,2,3,4,5,6,7,8,9,10],[1,4,9,16,25,36,49,64,81,100], ‘ro’)
[Link]([1,2,3,4,5,6,7,8,9,10],[1,4,9,16,25,36,49,64,81,100])
[Link]( 'X AXIS' , fontsize=20 , fontweight = 'bold', family='fantasy')
[Link]( 'Y AXIS' , fontsize=25 , fontweight = 'black', fontstyle='italic')
[Link]( 'Sample Python Plotting' )
[Link]()
>>>
o Output:

>>>
P a g e | 21

o Explanation:
Problem 17 differs from problem 16 in the sense that it plots the discrete points in addition to the
continuous plot. Also the colour of the points is red. The main difference lies in the addition of an extra
line in the code. ‘ro’ at the end of the line indicates that the spots are red or ‘r’ in colour and the marker is
‘o’ or circles. If ‘r’ is not mentioned, the default color is ‘b’ or blue.
Some popular markers are “.” or point, “v” or down triangle, “^” or up-triangle,, “<” or left triangle, “>”
or right triangle, “1” or tri-down, “2” or tri-up, “3” or tri-left, “4” or tri-right, “8” or octagon, “s” or
square, “p” or pentagon, “*” or star, “+” or plus, “x” or x and “D” or diamond. There are many other not
so popular markers apart from these too.
The common colors popularly used in Python plotting are “b” or blue, “g” or green, “r” or red, “c” or
cyan, “m” or magenta, “y” or yellow, “k” or black and “w” or white.
So to plot with green colored “+” markers, the code to be used is ‘g+’.
! Note: In Problem 17, if third line was deleted, the output will be discrete points marked by red circles,
as followed:

4.2 Multiple Plotting in Python


Sometimes it is required to plot multiple times in a single figure or share x-axis or y-axis for drawing
multiple plots. Problem 18 shows how to draw multiple times on a single axis, while problem 19 shows
the introduction of subplots.
" Problem 18:
>>>
import [Link] as plt
[Link]([1,2,3,4,5,6,7,8,9,10],[1,4,9,16,25,36,49,64,81,100], ‘ro’)
[Link]([1,2,3,4,5,6,7,8,9,10],[-1,-4,-9,-16,-25,-36,-49,-64,-81,-100],’g^’)
[Link]( 'X AXIS' , fontsize=20 , fontweight = 'bold', family='fantasy')
[Link]( 'Y AXIS' , fontsize=25 , fontweight = 'black', fontstyle='italic')
[Link]( 'Sample Python Plotting' )
P a g e | 22

[Link]()
>>>
o Output:
>>>

>>>
o Explanation:
We can plot as many plots sharing the same axis by using separate lines like 2nd and 3rd lines of problem
18. We can also distinguish the plots from each other by using separate markers like red circles and green
upper triangles.
! Note: Problem 17 also has two plots, one of them being discrete and the other is continuous.
" Program 19:
>>>
import [Link] as ply
fig=[Link]()
Ax1=fig.add_subplot(211)
Ax1.set_xlabel('x axis')
Ax1.set_ylabel('y axis')
Ax1.set_title('Figure 1')
[Link]([1,2,3,4,5,6,7,8,9,10],[1,4,9,16,25,36,49,64,81,100],'ro')
Ax2=fig.add_subplot(212)
Ax2.set_xlabel('X AXIS')
Ax2.set_ylabel('Y AXIS')
Ax2.set_title('Figure 2')
P a g e | 23

[Link]([1,2,3,4,5,6,7,8,9,10],[-1,-4,-9,-16,-25,-36,-49,-64,-81,-100],'g^')
[Link]( 'Sample Python Plotting' )
[Link]()
>>>
o Output
>>>

>>>
o Explanation:
fig holds the keeps track of the figure. Within the main plot, add_subplot(2,1,x) shows that we are making
two subplots. The argument of add_subplot(a, b, x) indicate that the plot is divided into a rows and b
columns and x indicates the x-th subplot among the a*b subplots. Ax1 holds the handle of the 1st subplot
within the plot i.e. the subplot pertaining to the location (1, 1) in the plot. Ax2 holds the handle of 2nd sub
plot within the plot i.e. the subplot pertaining to the location (2, 1) in the plot. set_xlabel() and
set_ylabel() are used the name the x and y axes respectively. For example, Ax1.set_xlabel() is used to
name the x-axis of the subplot held by Ax1. We can also use fontweight, style and family to modify the
text. Set_title() is used to add title to the individual subplots. Plot() will plot the dataset in the subplot
assigned to do so. Finally show() is used to view the plots.
! Note: Ax1 and Ax2 are names used here. Any other variable name can be used here. ply in Problem
19 still holds the track of the entire plot. suptitle() is still used to name the entire plot.
P a g e | 24

PART  2:  PYTHON  IN  OPTICS  


P a g e | 25

CHAPTER 5: Refraction of Light


5.1 Snell’s Law
Refraction is the bending of the path of a light wave as it passes across the boundary separating two
media. Refraction is caused by the change in speed experienced by a wave when it changes medium.
Refraction of light is governed by the famous Snell-Descartes Law (or in short Snell’s Law) formulated
by Willebrord Snellius, which describe the relation between angle of incidence and angle of refraction,
when light is allowed to fall on the interface having different refractive index.
Snell's law states that the ratio of the sine of the angle of incidence to the sine of the angle of refraction is
equivalent to the ratio of phase velocity in the first medium to the phase velocity in the second medium,
or equivalent to the reciprocal of the ratio of the indices of refraction.
!"#!! !! !!
= = … (1)
!"#!! !! !!

Where 𝜃! is the angle of incidence in the first medium, 𝜃! is the angle of refraction in the second medium,
all angles measured from the normal of the boundary, 𝑣! and 𝑣! are respectively the velocities in the two
media, and 𝑛! and 𝑛! are the refractive index of the first and second medium respectively.
" Assignment 1:
>>>
from __future__ import division

import math

print "1. refracive index of first medium \n2. angle of incidence \[Link] index of second medium
\n4. angle of refraction \n"
casenumber=input('enter the number of the choice you want to find out: ')

if (casenumber>4) or (casenumber<1):
print "Enter the number of the choice correctly."
exit

if casenumber==1:
n2=input('enter the refractive index of second medium: ');
theta1=input('enter the angle of incidence: ');
theta2=input('enter the angle of refraction: ');
n1=[Link](theta2*[Link]/180)/[Link](theta1*[Link]/180)*n2;
print "The refractive index of first medium is %f." %n1

elif casenumber==2:
n1=input('enter the refractive index of first medium: ');
n2=input('enter the refractive index of second medium: ');
theta2=input('enter the angle of refraction: ');
if ((n2*[Link](theta2*[Link]/180)/n1)>1) or ((n2*[Link](theta2*[Link]/180)/n1)<-1):
print "There will be no refraction for the given input."
exit
P a g e | 26

theta1=([Link](n2*[Link](theta2*[Link]/180)/n1))*180/[Link]
print "The angle of incidence is %f degrees." %theta1

elif casenumber==3:
n1=input('enter the refractive index of first medium: ');
theta1=input('enter the angle of incidence: ');
theta2=input('enter the angle of refraction: ');
n2=[Link](theta1*[Link]/180)/[Link](theta2*[Link]/180)*n1
print "The refractive index of second medium is %f." %n2

elif casenumber==4:
n1=input('enter the refractive index of first medium: ');
n2=input('enter the refractive index of second medium: ');
theta1=input('enter the angle of incidence: ');
if ((n1*[Link](theta1*[Link]/180)/n2)<-1) or ((n1*[Link](theta1*[Link]/180))/n2>1):
print "There will be total internal reflection for the given input."
exit
theta2=([Link](n1*[Link](theta1*[Link]/180)/n2))*180/[Link]
print "The angle of refraction is %f degrees." %theta2

>>>
o Output:
>>>
1. refracive index of first medium
2. angle of incidence
[Link] index of second medium
4. angle of refraction

enter the number of the choice you want to find out: 1


enter the refractive index of second medium: 1.2
enter the angle of incidence: 25
enter the angle of refraction: 31
The refractive index of first medium is 1.462421.
>>>
" Assignment 2:
# Program to plot angle of incidence v/s angle of refraction in a particular pair of medium

from __future__ import division

import math

import [Link] as plt


P a g e | 27

print "1. Snell's law\n\nProgram to plot angle of incidence v/s angle of refraction\n\n"

theta1=[];
theta2=[];

n1=input('Enter the refractive index of first medium: ');


n2=input('Enter the refractive index of second medium: ');

loop_count=0

choice='y'

while choice=='y':
[Link](input('Enter the angle of incidence in degrees: '));
if (n1*[Link](theta1[loop_count]*[Link]/180)/n2<-1) or
(n1*[Link](theta1[loop_count]*[Link]/180)/n2>1):
print "There will be total internal reflection for the given angle of incidence. Try some other values.
\n"
[Link](input('Enter the angle of incidence in degrees: '));
[Link](([Link](n1*[Link](theta1[loop_count]*[Link]/180)/n2))*180/[Link]);
print "Angle of incidence is %f" %theta1[loop_count], "degrees and angle of refration is %f
degrees\n" %theta2[loop_count]
choice=raw_input("Do you want to enter more values? Type y for yes or n for no. \n")
while (choice!='y') and (choice!='n'):
print "Invalid entry. Type y or n."
choice=raw_input("Do you want to enter more values? Type y for yes or n for no. \n")
loop_count +=1;

if choice=='n':
fig=[Link]()
[Link]("Snell's Law",fontsize=14, fontweight='bold')

ax = fig.add_subplot(111)

ax.set_title('Angle of Incidence v/s Angle of Refraction plot',fontsize=10)

ax.set_xlabel('Angle of Incidence')
ax.set_ylabel('Angle of Refraction')

[Link](theta1, theta2, 'o')

[Link]([min(theta1), max(theta1), min(theta2), max(theta2)])


P a g e | 28

[Link]()

>>>
o Output:
>>>
1. Snell's law

Program to plot angle of incidence v/s angle of refraction

Enter the refractive index of first medium: .94


Enter the refractive index of second medium: 1.2
Enter the angle of incidence in degrees: 65
Angle of incidence is 65.000000 degrees and angle of refration is 45.230123 degrees

Do you want to enter more values? Type y for yes or n for no.
y
Enter the angle of incidence in degrees: 60
Angle of incidence is 60.000000 degrees and angle of refration is 42.717692 degrees

Do you want to enter more values? Type y for yes or n for no.
y
Enter the angle of incidence in degrees: 55
Angle of incidence is 55.000000 degrees and angle of refration is 39.916393 degrees

Do you want to enter more values? Type y for yes or n for no.
y
Enter the angle of incidence in degrees: 50
Angle of incidence is 50.000000 degrees and angle of refration is 36.874778 degrees

Do you want to enter more values? Type y for yes or n for no.
y
Enter the angle of incidence in degrees: 45
Angle of incidence is 45.000000 degrees and angle of refration is 33.635004 degrees

Do you want to enter more values? Type y for yes or n for no.
P a g e | 29

y
Enter the angle of incidence in degrees: 40
Angle of incidence is 40.000000 degrees and angle of refration is 30.232954 degrees

Do you want to enter more values? Type y for yes or n for no.
y
Enter the angle of incidence in degrees: 35
Angle of incidence is 35.000000 degrees and angle of refration is 26.698880 degrees

Do you want to enter more values? Type y for yes or n for no.
y
Enter the angle of incidence in degrees: 30
Angle of incidence is 30.000000 degrees and angle of refration is 23.058244 degrees

Do you want to enter more values? Type y for yes or n for no.
n

>>>
5.2 Critical Angle and Total Internal Reflection
If a light is allowed to fall on an interface separating two media of different refractive index, then there
are two possible cases:
i. Light can travel from a medium of lower refractive index to a medium of higher refractive index.
ii. Light can travel from a medium of higher refractive index to a medium of lower refractive index.
P a g e | 30

In the second case, refraction does not happen all the time.
𝑛
𝑛! > 𝑛! ↔ ! 𝑛! > 1
Now,
𝑛!
𝑠𝑖𝑛𝜃! = ∗ 𝑠𝑖𝑛𝜃!
𝑛!
If we increase 𝜃! , at one particular point of time, 𝑠𝑖𝑛𝜃! will become greater than 1, which is not possible
for any real value of 𝜃! . So we define a phenomenon called Total Internal Reflection (TIR):
When a light wave travelling in a medium having higher refractive index falls on an interface separating
the first medium from another having lower refractive index, if the angle of incidence is greater than a
certain angle, called critical angle, the light wave can no longer suffer refraction and is totally reflected
from the interface following the laws of reflection. This phenomenon is called Total Internal Reflection.
Critical angle 𝜃! can be derived from equation(1) by substituting 𝜃! by 𝜃! and 𝜃! by 900:
𝑛
𝜃! = 𝑠𝑖𝑛!! ! 𝑛! … (2)
" Assignment 3:
>>>
#Program to find the critical angle between a pair of medium
from __future__ import division

import math

n1=input('enter the refractive index of first medium: ');


n2=input('enter the refractive index of second medium: ');
if (n2/n1>1):
print "There is no critical angle for the pair of medium."
if (n2/n1<1):
theta=[Link]([Link](n2/n1))
print "The critical angle between the two media is %f degrees." %theta
>>>
o Output:
>>>
enter the refractive index of first medium: .9
enter the refractive index of second medium: 1.2
There is no critical angle for the pair of medium.
>>>
enter the refractive index of first medium: 1.2
enter the refractive index of second medium: .9
The critical angle between the two media is 48.590378 degrees.
>>>
P a g e | 31

CHAPTER 6: LENS AND MIRRORS


6.1 Sign Convention in Optics:
There are many sign conventions in Optics. The most commonly used sign convention is Saleh and Teich
text (S&T) convention. It states that:
a. Object distances are positive to the left of an optical element (and negative to the right).
b. Image distances are positive to the right (negative to the left) for lenses, and positive to the left
(negative to the right) for mirrors.
c. The curvature of a surface with its center of curvature to the right is positive.
d. The curvature of a surface with its center of curvature to the left is negative.
e. Ray heights above the optical axis are positive.
f. Ray heights below the optical axis are negative.
g. Lenses and mirrors that cause parallel light to converge are positive.
h. Lenses and mirrors that cause parallel light to diverge are negative.
i. Ray angles, for rays going forward, are:
i) positive if ray is rotated clockwise to reach the axis (closest rotation)
ii) negative if ray is rotated counter-clockwise to reach the axis (closest rotation)
! Note: this convention reverses sign for rays going backward. (e.g. reflected from mirror)
j. Ray angles are positive if the ray travels with an “upward” component when viewed with the local
optical axis oriented horizontally, and negative if the ray travels with a “downward” component relative
to a horizontal optical axis.

S & T sign convention in lenses, where F is the focal point of the lens.

6.2 Power of a Lens:


A lens is an optical device which transmits and refracts light, converging or diverging the beam.
Let rays of light travelling in a medium having refractive index 𝑛! fall on a lens having a medium of
refractive index 𝑛! lying on the other side of the lens, object and image distances being 𝑙! and 𝑙!
respectively. Then power P of the lens is given by:
𝑛 𝑛
𝑃= ! 𝑙 − ! 𝑙 … (2)
! !

If radius of curvature, R of lens is known, the power P of the lens is given by:
!! !!!
𝑃= … (3)
!
P a g e | 32

Magnification M of a lens is given by,


!! ∗!!
𝑀= … (4)
!! ∗!!

" Assignment 4:
>>>
from __future__ import division

import math

print "Program to find power and magnification of the lens\n"


print "Power formula of a lens:\n"
n1=input('Enter the refractive index of the first medium: ');
n2=input('Enter the refractive index of the second medium: ');
l=input('Enter the object distance: ');
l_prime=input('Enter the image distance: ')
Power=n2/l_prime-n1/l;
print "The power of the lens is %f D." %Power
Magnification=n1*l_prime/(n2*l);
print "Magnification of lens is %f." %Magnification
>>>
o Output:
>>>
Program to find power and magnification of the lens

Power formula of a lens:

Enter the refractive index of the first medium: 1.333


Enter the refractive index of the second medium: 1
Enter the object distance: 2.452
Enter the image distance: 1.235
The power of the lens is 0.266079 D.
Magnification of lens is 0.671393.
>>>
" Assignment 5:
>>>
P a g e | 33

from __future__ import division

import math

print "Power formula of a lens:\n"

choice=raw_input("Enter the name of the unknown variable:\n1. Power of the lens\n2. refractive index of
first medium\n3. refractive index of second medium\n4. radius of curvature of lens\n\nYour choice:");
#User has to input the name of the variable. For example to find how much power the lens has, type
"Power of the lens" i.e. the text associated with the corresponding variable. Watch out for case sensitivity
and space.

while (choice!='Power of the lens') and (choice!='refractive index of the first medium') and
(choice!='refractive index of the second medium') and (choice!='radius of curvature of lens'):
print "Error in input name. Check the spelling, casing and spacing of the input command. Foe example,
to know power of lens, type the word exactly as it appears in point number one."
choice=raw_input("Enter the name of the unknown variable:\n1. Power of the lens\n2. refractive index
of the first medium\n3. refractive index of second medium\n4. radius of curvature of lens\n\nYour
choice:");

if choice=='Power of the lens':


n=input('Enter the refractive index of first medium: ');
n_prime=input('Enter the refractive index of the second medium: ');
r=input('Enter the radius of curvature of the lens in m: ');
Power=(n_prime-n)/r;
print "The power of the lens is %f D." %Power

if choice=='refractive index of first medium':


Power=input('Enter the power of the lens: ');
n_prime=input('Enter the refractive index of the second medium: ');
r=input('Enter the radius of curvature of the lens: ');
n=n_prime-Power*r;
print "The refractive index of the first medium is %f." %n

if choice=='refractive index of second medium':


Power=input('Enter the power of the lens: ');
P a g e | 34

n=input('Enter the refractive index of the first medium: ');


r=input('Enter the radius of curvature of the lens: ');
n_prime=n+Power*r;
print "The refractive index of the second medium is %f." %n_prime

if choice=='radius of curvature of lens':


Power=input('Enter the power of the lens in Dioptre: ');
n=input('Enter the refractive index of the first medium: ');
n_prime=input('Enter the refractive index of the second medium: ');
r=(n_prime-n)/Power;
print "The radius of curvature of lens is %f m." %r
>>>
o Output:
>>>
Power formula of a lens:

Enter the name of the unknown variable:


1. Power of the lens
2. refractive index of first medium
3. refractive index of second medium
4. radius of curvature of lens

Your choice:2
Error in input name. Check the spelling, casing and spacing of the input command. Foe example, to know
power of lens, type the word exactly as it appears in point number one.
Enter the name of the unknown variable:
1. Power of the lens
2. refractive index of the first medium
3. refractive index of second medium
4. radius of curvature of lens

Your choice:Power of the lens


Enter the refractive index of first medium: 0.9857
Enter the refractive index of the second medium: 1.235
Enter the radius of curvature of the lens in m: 2.6
P a g e | 35

The power of the lens is 0.095885 D.


>>>
6.3 Thin Lens Equation
A thin lens is a lens whose thickness is very small compared to the radius of curvature of lens surface. It
negates the effect of thickness of the lens.
! ! !
+ = … (5)
! !/ !

" Assignment 6:
>>>
from __future__ import division

import math
import [Link] as plt
import sys

print "Thin lens equation, potting image distance vs object distance:\n"

f=input("Enter the focal length of the lens in m: ")

check=1;
count=0;
s1=[]
s2=[]

while check==1:
[Link](input("Enter the object distance in m: "))
if f==s1[count]:
print "The image distance is [Link] be plotted."
del s1[count]
count-=1
else:
[Link](1/(1/f-1/s1[count]))
check=input("Enter 1 for more values, 0 to stop: ")
while (check!=1) and (check!=0):
check=input("Invalid entry. Enter 1 for more values, 0 to stop: ")
count+=1;
P a g e | 36

fig=[Link]()
[Link]("Thin lens equation",fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
ax.set_title('object distance vs image distance',fontsize=10)
ax.set_xlabel('object distance')
ax.set_ylabel('image distance')
[Link](s1, s2, 'bo')
[Link]()
>>>
o Output:
>>>
Enter the focal length of the lens in m: 2
Enter the object distance in m: 4.5
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 4
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 3.5
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 3
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 2.5
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 2
The image distance is [Link] be plotted.
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 1.5
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: 1
Enter 1 for more values, 0 to stop: 1
Enter the object distance in m: .5
Enter 1 for more values, 0 to stop: 0
P a g e | 37

 
>>>
P a g e | 38

CHAPTER 7: POLARIZATION OF LIGHT


7.1 Brewster’s Angle:
When light falls on an interface separating two media, a part of it is transmitted, while the rest is reflected.
Brewster's angle (also known as the polarization angle, named after Sir David Brewster) is an angle of
incidence at which light, with a particular polarization, is perfectly transmitted through a
transparent dielectric surface, without any reflection.
Let 𝜃! be the Brewster’s angle for light, travelling from a medium with refractive index 𝑛! , falling on an
interface separating the first medium from the second medium having refractive index 𝑛! .
!!
𝜃! = 𝑡𝑎𝑛!! … (6)
!!

Brewster’s angle is a property between a pair of media. The physical significance of Brewster’s angle is
that when unpolarized light is incident on the interface at this angle, the light that is reflected from the
surface is therefore perfectly polarized.
" Assignment 7:
>>>
from __future__ import division

import math

print "Program related to Brewster's angle\n"


print "1. Brewster's angle\n2. Refractive index of first medium\n3. Refractive index of second medium\n"
casenumber=input('Enter the number corresponding to the unknown variable: ')

if (casenumber>4) or (casenumber<1):
print "Enter the number of the choice correctly."
exit

if casenumber==1:
n_first=input("Enter the refractive index of the first medium: ");
n_second=input("Enter the refractive index of the second medium: ");
theta=[Link](n_second/n_first)*180/[Link];
print "Brewster's angle is given by %f degrees." %theta

if casenumber==2:
theta=input("Enter the Brewster's angle in degrees: ");
n_second=input("Enter the refractive index of the second medium: ");
n_first=n_second/[Link](theta*[Link]/180);
P a g e | 39

print "Refractive index of first medium is given by %f" %n_first

if casenumber==3:
n_first=input("Enter the refractive index of the first medium: ");
theta=input("Enter the Brewster's angle in degrees: ");
n_second=n_first*[Link](theta*[Link]/180);
print "Refractive index of second medium is given by %f" %n_second
>>>
o Output:
>>>
Program related to Brewster's angle

1. Brewster's angle
2. Refractive index of first medium
3. Refractive index of second medium

Enter the number corresponding to the unknown variable: 2


Enter the Brewster's angle in degrees: 38
Enter the refractive index of the second medium: .75
Refractive index of first medium is given by 0.959956
>>>
7.2 Malus’ Law:
According to Malus, when completely plane polarized light is incident on the analyzer, the intensity I of
light transmitted by the analyzer is directly proportional to the square of the cosine of angle between the
transmission axes of the analyzer and the polarizer.
𝐼 = 𝐼! 𝑐𝑜𝑠 ! 𝜃 … (7)
where I is the intensity if light transmitted by the analyzer, 𝐼! is the initial intensity of light, and 𝜃 is the
angle between the transmission axes of the analyzer and the polarizer.
" Assignment 8:
>>>
from __future__ import division

import math

print "Malus' law\n"


P a g e | 40

print "1. Intensity of light passing through\n2. Initial Intensity\n3. Angle between light's initial
polarization direction and axis of polarizer."
casenumber=input('Enter the number corresponding to the unknown variable: ')

if (casenumber>4)or (casenumber<1):
print "The number of the choice incorrect."
exit

if casenumber==1:
I_initial=input('Enter the initial intensity of light: ');
theta=input("Enter the angle between light's initial polarization direction and axis of polarizer in
degrees: ");
I=I_initial*([Link](theta*[Link]/180)**2);
print "Intensity of light passing through is %f." %I

if casenumber==2:
I=input('Enter the intensity of light passing through: ');
theta=input("Enter the angle between light's initial polarization direction and axis of polarizer in
degrees: ");
I_initial=I/([Link](theta*[Link]/180)**2);
print "Initial intensity of light is %f." %I_initial

if casenumber==3:
I_initial=input('Enter the initial intensity of light: ');
I=input('Enter the intensity of light passing through: ');
theta=([Link]((I/I_initial)**.5))*180/[Link];
print "Angle between light's initial polarization direction and axis of polarizer is %f degrees." %theta

>>>
o Output:
>>>
Malus' law

1. Intensity of light passing through


2. Initial Intensity
3. Angle between light's initial polarization direction and axis of polarizer.
P a g e | 41

Enter the number corresponding to the unknown variable: 2


Enter the intensity of light passing through: 20
Enter the angle between light's initial polarization direction and axis of polarizer in degrees: 65
Initial intensity of light is 111.978199.
>>>
7.3 Rayleigh Scattering:
Rayleigh scattering, named after Lord Rayleigh, is the phenomenon of scattering of light or other
electromagnetic radiation by particles whose dimensions are much smaller compared to the wavelength of
light. The particles may be single atoms or molecules. Rayleigh scattering occurs due to the electric
polarizability of the particles.
The intensity I of light scattered by any one of the small spheres of diameter d and refractive index n from
a beam of unpolarized light of wavelength λ and intensity I0 is given by:
!
!!!"#! ! !! ! !! !! ! !
𝐼 = 𝐼! ∗ ∗ ∗ ∗ … (8)
!! ! ! !! !! !

where R is the distance to the particle and θ is the scattering angle.


Due to the strong inverse proportion, shorter wavelengths are scattered more than longer wavelengths.
" Assignment 9:
>>>
from __future__ import division

import math

print "Rayleigh's scattering\n"


I_initial=input("Enter the intensity of light: ")
R=input("Enter the distance to the particle in mm: ");
theta=input("Enter the scattering angle in radian: ");
n=input("Enter the refractive index of the medium: ");
wavelength=input("Enter the wavelength of light in mm: ");
diameter=input("Enter the diameter of the scattering particle in mm: ");
Intensity=I_initial*(1+[Link](theta)**2)/(2*R**2)*((2*[Link]/wavelength)**4)*(((n**2-
1)/(n**2+2))**2)*((diameter/2)**6)
print "The intensity of light scattered by one particle is %f." %Intensity
>>>
o Output:
>>>
Rayleigh's scattering
P a g e | 42

Enter the intensity of light: 2.145


Enter the distance to the particle in mm: 12.354
Enter the scattering angle in radian: .658
Enter the refractive index of the medium: .4
Enter the wavelength of light in mm: 2.5
Enter the diameter of the scattering particle in mm: 1.8
The intensity of light scattered by one particle is 0.036642.
>>>
" Assignment 10:
>>>
# Program to plot Intensity of light scattered by one particle of diameter d mm v/s wavelength of light
given by Rayleigh's scattering.

from __future__ import division

import math

import [Link] as plt

Intensity=[]
wavelength=[]

print "Rayleigh's scattering\n"

I_initial=input("Enter the intensity of light: ")


R=input("Enter the distance to the particle in mm: ");
theta=input("Enter the scattering angle in degrees: ");
n=input("Enter the refractive index of the medium: ");
diameter=input("Enter the diameter of the scattering particle in mm: ");

loop_count=0

choice='y'

while choice=='y':
P a g e | 43

[Link](input("Enter the wavelength of light in mm: "));

[Link](I_initial*(1+[Link](theta)**2)/(2*R**2)*((2*[Link]/wavelength[loop_count])**4)*(
((n**2-1)/(n**2+2))**2)*((diameter/2)**6));
print "The intensity of light scattered by one particle is %.20f" %Intensity[loop_count],
"corresponding to wavelength %f mm\n" %wavelength[loop_count]
choice=raw_input("Do you want to enter more values? Type y for yes or n for no. \n")
while (choice!='y') and (choice!='n'):
print "Invalid entry. Type y or n."
choice=raw_input("Do you want to enter more values? Type y for yes or n for no. \n")
loop_count += 1;

if choice=='n':
fig=[Link]()
[Link]("Rayleigh's scattering experiment",fontsize=14, fontweight='bold')

ax = fig.add_subplot(111)

ax.set_title('Intensity of light scattered v/s wavelength of light plot',fontsize=10)

ax.set_xlabel('Wavelength of light')
ax.set_ylabel('Intensity of light scattered')

[Link](wavelength, Intensity, 'o',color='r')

[Link](wavelength,Intensity,color='m')

[Link]([min(wavelength), max(wavelength), min(Intensity), max(Intensity)])

[Link]()
>>>
o Output:
>>>
Rayleigh's scattering

Enter the intensity of light: 85


P a g e | 44

Enter the distance to the particle in mm: 100


Enter the scattering angle in degrees: 35
Enter the refractive index of the medium: 1.1
Enter the diameter of the scattering particle in mm: 350e-6
Enter the wavelength of light in mm: 400e-6
The intensity of light scattered by one particle is 0.00000000005315012894 corresponding to wavelength
0.000400 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 425e-6
The intensity of light scattered by one particle is 0.00000000004170504245 corresponding to wavelength
0.000425 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 450e-6
The intensity of light scattered by one particle is 0.00000000003318136384 corresponding to wavelength
0.000450 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 475e-6
The intensity of light scattered by one particle is 0.00000000002672820843 corresponding to wavelength
0.000475 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 500e-6
The intensity of light scattered by one particle is 0.00000000002177029282 corresponding to wavelength
0.000500 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 525e-6
P a g e | 45

The intensity of light scattered by one particle is 0.00000000001791047378 corresponding to wavelength


0.000525 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 550e-6
The intensity of light scattered by one particle is 0.00000000001486940292 corresponding to wavelength
0.000550 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 575e-6
The intensity of light scattered by one particle is 0.00000000001244723557 corresponding to wavelength
0.000575 mm

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light in mm: 600e-6
The intensity of light scattered by one particle is 0.00000000001049879090 corresponding to wavelength
0.000600 mm

Do you want to enter more values? Type y for yes or n for no.
n

 
>>>
P a g e | 46

CHAPTER 8: DIFFRACTION OF LIGHT


Diffraction is the process by which a beam of light or other system of waves is spread out as a result of
passing through a narrow aperture or across an edge, typically accompanied by interference between the
waves produced.
The most common examples of diffraction are:
i) Single slit diffraction
ii) Young’s double slit diffraction
iii) Diffraction from circular aperture
8.1 Single Slit Diffraction
A long slit of infinitesimal width which is illuminated by light diffracts the light into a series of circular
waves and the wavefront which emerges from the slit is a cylindrical wave of uniform intensity.
If d is the width of the slit, λ be the wavelength of light and 𝜃! be the angle of incidence at which the n-th
minimum intensity occurs, then they are related by equation (9).
𝑑 ∗ sin 𝜃! = 𝑛𝜆 … (9)
The intensity profile, calculated using Fraunhofer diffraction pattern, is given as:
!"
𝐼 𝜃 = 𝐼! ∗ 𝑠𝑖𝑛𝑐 ! ∗ sin 𝜃 … (10)
!

where 𝐼 𝜃 is the intensity at a given angle 𝜃, and 𝐼! is the original intensity of light.
" Assignment 11:  
>>>
from __future__ import division

import math

import [Link] as plt

print "Single Slit Diffraction"

width=input('Enter the slit width in mm: ');


n=input('Enter the order at which minimum intensity of light occurs: ');
wavelength=input('Enter the wavelength of light: ');
theta=[Link]([Link]((n*wavelength/width)));

print "The angle of incidence is %f degrees." %theta


>>>
o Output:  
P a g e | 47

>>>
Single Slit Diffraction
Enter the slit width in mm: .23
Enter the order at which minimum intensity of light occurs: 6
Enter the wavelength of light: 400e-6
The angle of incidence is 0.597880 degrees.
>>>
8.2 Young’s Double slit Diffraction Experiment
The double-slit experiment, performed by Thomas Young, is a demonstration that proves light displaying
characteristics of both classically defined waves and particles; moreover, it displays the fundamentally
probabilistic nature of quantum mechanical phenomena. This experiment is sometimes referred to
as Young's experiment.
For far field, when the viewing distance d is large compared to the slit separation, the path difference ∆𝑥
between two waves travelling at an angle 𝜃, is given by:
∆𝑥 = 𝑑 ∗ 𝑠𝑖𝑛𝜃 ≈ 𝑑 ∗ 𝜃 (since 𝜃 → 0) … (11)
The resultant intensity of two waves depends not only on the intensity of each wave, but also on the phase
difference between the waves. If the waves are in phase, the resultant intensity is maximum. If there is
any phase difference between the waves, the resultant intensity increases from the maximum value. The
resultant intensity may also cancel each other, and in that case, the resultant intensity is 0. This effect is
called interference.
𝑑 ∗ 𝑠𝑖𝑛𝜃 = 𝑑 ∗ 𝜃 = 𝑛 ∗ 𝜆 … (12)
where n = 0, 1, 2, 3, … and λ is the wavelength of light.
The interference fringe maxima occur at angles that follow eqn. (4). In other words, the interference
fringe maxima occur when the path difference ∆𝑥 is an integral multiple of wavelength.
" Assignment 12:
>>>
from __future__ import division

import math

print " Young's Double slit experiment \n"


print "1. Separation of the slit\n2. angle for path difference\n3. wavelength of light used\n4. order of the
fringe\n"
casenumber=input('Enter the number corresponding to the unknown variable: ')

if (casenumber>4)or (casenumber<1):
print "The number of the choice incorrect."
exit
P a g e | 48

if casenumber==1:
theta=input('Enter the angle in degrees: ');
order=input('enter the order of the fringe: ');
wavelength=input('Enter the wavelength of light in mm: ');
d=wavelength*order/[Link](theta*[Link]/180);
print "The slit separation is %f mm." %d

elif casenumber==2:
d=input('Enter the slit separation in mm: ');
order=input('enter the order of the fringe: ');
wavelength=input('Enter the wavelength of light in mm: ');
if (wavelength*order/d <-1) or (wavelength*order/d>1):
print "There is error in input."
exit
theta=[Link](wavelength*order/d)*180/[Link];
print "Angle for path difference is %f degrees." %theta

elif casenumber==3:
d=input('Enter the slit separation in mm: ');
theta=input('Enter the angle for path difference in degrees: ');
order=input('enter the order of the fringe: ');
wavelength=d*[Link](theta*[Link]/180)/order;
print "The wavelength of light used is %f mm." %wavelength

elif casenumber==4:
d=input('Enter the slit separation: ');
theta=input('Enter the angle for path difference in degrees: ');
wavelength=input('Enter the wavelength of light in mm: ');
order=[Link](theta*[Link]/180)*d/wavelength;
print "The order of the fringe is %d." %round(order,0)
>>>
o Output:
>>>
Young's Double slit experiment
P a g e | 49

1. Separation of the slit


2. angle for path difference
3. wavelength of light used
4. order of the fringe

Enter the number corresponding to the unknown variable: 3


Enter the slit separation in mm: 5.58
Enter the angle for path difference in degrees: 12
enter the order of the fringe: 3
The wavelength of light used is 0.386716 mm.
>>>
" Assignment 13:  
>>>
# Young's double slit experiment to plot fringe spacing v/s wavelength

from __future__ import division

import math

import [Link] as plt

loop_count=0
print "Double slit experiment\n \nPlotting curve between fringe spacing and wavelength\n"

wavelength=[];
beta=[];

d=input("Enter the slit spacing in mm: ");


z=input("Enter the distance of observation in mm: ");

choice='y'

while choice=='y':
P a g e | 50

[Link](input("Enter the wavelength of light used in mm: "));


[Link](z*wavelength[loop_count]/d);
print "Fringe spacing is %f" %beta[loop_count], "mm corresponding to %f mm wavelength of
light.\n\n" %wavelength[loop_count]
choice=raw_input("Do you want to enter more values? Type y for yes or n for no. \n")
while (choice!='y') and (choice!='n'):
print "Invalid entry. Type y or n."
choice=raw_input("Do you want to enter more values? Type y for yes or n for no. \n")
loop_count += 1;
if choice=='n':
fig=[Link]()
[Link]("Young's Double Slit Experiment",fontsize=14, fontweight='bold')
ax = fig.add_subplot(111)
ax.set_title('Fringe spacing v/s wavelength plot',fontsize=10)
ax.set_xlabel('Wavelength of light')
ax.set_ylabel('Fringe spacing')
[Link](wavelength, beta, 'o')
[Link]([min(wavelength), max(wavelength), min(beta), max(beta)])
[Link](wavelength, beta, color='r')
[Link]()
>>>
o Output:
>>>
Double slit experiment

Plotting curve between fringe spacing and wavelength

Enter the slit spacing in mm: 0.025


Enter the distance of observation in mm: 5
Enter the wavelength of light used in mm: 400e-6
Fringe spacing is 0.080000 mm corresponding to 0.000400 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light used in mm: 450e-6
P a g e | 51

Fringe spacing is 0.090000 mm corresponding to 0.000450 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light used in mm: 500e-6
Fringe spacing is 0.100000 mm corresponding to 0.000500 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light used in mm: 550e-6
Fringe spacing is 0.110000 mm corresponding to 0.000550 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light used in mm: 600e-6
Fringe spacing is 0.120000 mm corresponding to 0.000600 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light used in mm: 650e-6
Fringe spacing is 0.130000 mm corresponding to 0.000650 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
y
Enter the wavelength of light used in mm: 700e-6
Fringe spacing is 0.140000 mm corresponding to 0.000700 mm wavelength of light.

Do you want to enter more values? Type y for yes or n for no.
n
P a g e | 52

 
>>>
8.3 Diffraction grating
In optics, a diffraction grating is an optical component with a periodic structure, which splits
and diffracts light into several beams travelling in different directions. The directions of these beams
depend on the spacing of the grating and the wavelength of the light.
If a plane wave is incident at any arbitrary angle 𝜃! , the grating equation is given by:
𝑑 𝑠𝑖𝑛 𝜃! + 𝑠𝑖𝑛 𝜃! =𝑛∗𝜆 … (13)
where 𝜃! is the angle for the n-th maxima, 𝜆 is the wavelength of light and d is the slit separation.
From equation (13) can be written as,
!∗!
𝜃! = 𝑠𝑖𝑛!! − 𝑠𝑖𝑛 𝜃! … (14)
!

" Assignment 14:  


>>>
from __future__ import division

import math

import [Link] as plt

print "Diffraction Grating"


theta=[]
theta2=[];
check=1;
index=0;
P a g e | 53

n=input('Enter the order of maxima or minima: ');


wavelength=input('Enter the wavelength of light used in mm: ');
d=input('Enter the slit separation in mm: ');

while check==1:
[Link](input('Enter the angle of incidence in degrees: '));
if (n*wavelength/[Link]([Link](theta[index]))>1) or (n*wavelength/d-
[Link]([Link](theta[index]))<-1):
print "Invalid input. Check input and try again."
exit
[Link]([Link]([Link](n*wavelength/[Link]([Link](theta[index])))))
print "The diffraction angle is %f degrees." %theta2[index]
print (check)
check=input("Enter 1 to enter for more values, 0 to stop: ")
while (check!=0) and (check!=1):
check=input("Invalid entry. Enter 1 to enter for more values, 0 to stop: ")
index+=1;

fig=[Link]()
[Link]("Diffraction Grating Experiment",fontsize=14, fontweight='bold')

[Link]('Incident angle v/s Diffracted angle',fontsize=10)

[Link]('Incident angle')
[Link]('Diffracted angle')

[Link](theta, theta2, 'r^')

[Link]()
>>>
o Output:
>>>
Diffraction Grating
Enter the order of maxima or minima: 45
Enter the wavelength of light used in mm: 500e-6
P a g e | 54

Enter the slit separation in mm: 0.02


Enter the angle of incidence in degrees: 10
The diffraction angle is 72.054834 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 20
The diffraction angle is 51.534224 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 30
The diffraction angle is 38.682187 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 40
The diffraction angle is 28.829997 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 50
The diffraction angle is 21.036067 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 60
The diffraction angle is 15.009227 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 70
The diffraction angle is 10.679054 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 80
The diffraction angle is 8.058971 degrees.
1
Enter 1 to enter for more values, 0 to stop: 1
Enter the angle of incidence in degrees: 90
The diffraction angle is 7.180756 degrees.
P a g e | 55

1
Enter 1 to enter for more values, 0 to stop: 2
Invalid entry. Enter 1 to enter for more values, 0 to stop: 0

 
>>>
8.4 Diffraction from Circular Aperture
When light from a point source passes through a small circular aperture, it does not produce a bright dot
as an image, but diffuse circular disc known as Airy's disc surrounded by much fainter concentric circular
rings.
Displacement y from the centerline on the screen is given by,
!"
𝑦=𝐷 … (15)
!

where D is the screen distance, 𝜆 is the wavelength of light, m is the m-order for minima or maxima; and
d is the aperture diameter. The smaller the aperture, the larger the spot size at a given distance, and the
greater the divergence of the diffracted beams.
" Assignment 15:
>>>
from __future__ import division

import math

print "Diffraction from circular aperture"


print "1. Screen distance\n2. Wavelength of light\n3. Diameter of the lens' aperture\n4. Displacement
from central axis"
P a g e | 56

casenumber=input('Enter the number of the choice you want to find out: ')

if (casenumber>4) or (casenumber<1):
print "The number of the choice incorrect."
exit

if casenumber==1:
order=input('Enter the order of minima or maxima: ');
Diameter=input("Enter the diameter of lens' aperture in mm: ");
y=input('Enter the dispalcement from central axis in mm: ');
wavelength=input("Enter the wavelength of light used in mm: ");
Distance=y*Diameter/(order*wavelength);
print "Screen distance is %f mm." %Distance

if casenumber==2:
Distance=input('Enter the screen distance in mm: ');
order=input('Enter the order of minima or maxima: ');
Diameter=input("Enter the diameter of lens' aperture in mm: ");
y=input('Enter the dispalcement from central axis in mm: ');
wavelength=y*Diameter/(order*Distance);
print "The wavelength of light is %f mm." %wavelength

if casenumber==3:
Distance=input('Enter the screen distance in mm: ');
order=input('Enter the order of minima or maxima: ');
wavelength=input('Enter the wavelength of light in mm: ');
y=input('Enter the dispalcement from central axis in mm: ');
Diameter=order*wavelength*Distance/order;
print "The diameter of lens' aperture is %f mm." %Diameter

if casenumber==4:
wavelength=input("Enter the wavelength of light used in mm: ");
order=input('Enter the order of minima or maxima: ');
Diameter=input("Enter the diameter of lens' aperture in mm: ");
Distance=input('Enter the screen distance in mm: ');
P a g e | 57

y=order*Distance*wavelength/Diameter
print "Screen distance is %f mm." %y
>>>
o Output:
>>>
Diffraction from circular aperture
1. Screen distance
2. Wavelength of light
3. Diameter of the lens' aperture
4. Displacement from central axis
Enter the number of the choice you want to find out: 2
Enter the screen distance in mm: 65
Enter the order of minima or maxima: 5
Enter the diameter of lens' aperture in mm: 2.65
Enter the dispalcement from central axis in mm: 3.6
The wavelength of light is 0.029354 mm.
>>>
8.5 Rayleigh Criterion:
The Rayleigh criterion is the generally accepted criterion for the minimum resolvable detail. The angular
resolution of an optical system can be estimated from the diameter d of the aperture and the wavelength of
the light λ by the Rayleigh criterion, named after Lord Rayleigh.
!.!!
𝜃= ∗𝜆 … (16)
!

" Assignment 16:


>>>
from __future__ import division

import math

print "Rayleigh criterion"


print "1. Angular Resolution\n2. Wavelength of light\n3. Diameter of the lens' aperture"

casenumber=input('Enter the number of the choice you want to find out: ')

if (casenumber>3) or (casenumber<1):
print "The number of the choice incorrect."
P a g e | 58

exit

if casenumber==1:
wavelength=input("Enter the wavelength of light used in mm: ");
D=input("Enter the diameter of the lens' aperture in mm: ");
theta=(1.22*wavelength)/D;
print "Angular Resolution is %f radians." %theta

if casenumber==2:
theta=input('Enter the angular resolution: ');
theta_choice=input('Enter 1 if angular resolution is in radian, 2 if it is in degrees: ');
D=input("Enter the diameter of the lens' aperture in mm: ")
if theta_choice==1:
wavelength=D*theta/1.22;
print "Wavelength of light used is %f mm." %wavelength
else:
wavelength=(D*(theta*[Link]/180))/1.22;
print "Wavelength of light used is %f mm." %wavelength

if casenumber==3:
theta=input('Enter the angular resolution: ');
theta_choice=input('Enter 1 if angular resolution is in radian, 2 if it is in degrees: ');
wavelength=input("Enter the wavelength of light used in mm: ")
if theta_choice==1:
D=wavelength*1.22/theta;
print "Diameter of lens' aperture is %f mm." %D
else:
D=wavelength*1.22/(theta*[Link]/180);
print "Diameter of lens' aperture is %f mm." %D
>>>
o Output:
>>>
Rayleigh criterion
1. Angular Resolution
2. Wavelength of light
P a g e | 59

3. Diameter of the lens' aperture


Enter the number of the choice you want to find out: 2
Enter the angular resolution: 2.6
Enter 1 if angular resolution is in radian, 2 if it is in degrees: 1
Enter the diameter of the lens' aperture in mm: 2.658
Wavelength of light used is 5.664590 mm.
>>>

View publication stats

Common questions

Powered by AI

Indentation in Python is crucial for defining the scope of loops and other control structures. It visually separates blocks of code, indicating that indented lines belong to the preceding block, such as a loop. This affects execution by determining which statements are executed inside the loop and which are not. For instance, in the given for loop example from Source 1, statement 2 is not a part of the for loop due to its lack of indentation, thus affecting the program output .

Nested loops are used to implement complex loop structures by placing one or more loops inside another loop. For example, if a for loop is placed inside a while loop, the inner loop will run completely for each iteration of the outer loop. This can be used to iterate over multi-dimensional data, such as matrices. An example from the context provided is the use of nested loops in controlling the execution flow with break and continue statements .

Mathematical functions in Python enhance programming efficiency by providing pre-built operations that save time and reduce error risks. For instance, 'math.log(x)' calculates the natural logarithm of x, and 'math.ceil(x)' returns the smallest integer greater than or equal to x. These functions simplify complex calculations, allowing programmers to focus on higher-level logic rather than implementing basic algorithms from scratch .

Rayleigh's scattering principle is applied in plotting graphs by varying parameters such as wavelength and observing intensity changes. For instance, in Python, the 'matplotlib.pyplot' library can be used to plot the intensity of light against the wavelength. Visual representations like these facilitate the understanding of scientific phenomena by clearly showing trends and dependencies, aiding in both analysis and presentation of data .

Iterative input in Python experiments allows the simulation to model real-world processes by accounting for a range of variables. In Young's Double Slit experiment simulation, users can iteratively input different wavelengths or slit separations, enabling the generation of multiple data points to observe patterns such as changes in fringe spacing. This makes Python a powerful tool for conducting virtual experiments where varying parameters is essential .

Loop control statements like 'break' and 'continue' manage the flow of loop execution by altering the natural sequence. The 'break' statement terminates the loop, allowing the program to proceed to the code immediately following the loop, useful for exiting the loop based on a condition. The 'continue' statement skips the remaining code within the current loop iteration and proceeds to the next iteration. These are used to fine-tune control over how a loop operates .

Rayleigh's scattering principle explains how shorter wavelengths scatter more than longer wavelengths, due to the inverse fourth power proportion to wavelength. In Python, this is demonstrated by using the expression ((2*math.pi/wavelength)**4) in calculating scattered light intensity. The formula reveals that as the wavelength decreases, the scattered intensity increases significantly, demonstrating the dependency of light scattering on wavelength .

Python represents complex numbers using the complex(x), complex(x, y) format for operations involving both real and imaginary parts. They are crucial in scientific computations for problems that inherently require complex numbers such as electrical engineering for AC circuit analysis or quantum mechanics where wavefunctions have imaginary components. They enable concise and efficient computations with inherent mathematical operations .

Using libraries like 'math' in Python provides significant computational benefits by offering optimized functions for complex calculations. This minimizes the need to manually implement mathematical algorithms, reducing coding errors and improving concentrate efficiency. Functions such as 'math.sin' and 'math.asin' handle trigonometric calculations accurately, critical in physics and engineering tasks like analyzing diffraction grating behavior .

In diffraction grating, the slit separation (d), wavelength (λ), and angular displacement relate through the grating equation dsinθ = nλ. This indicates that for light of a given wavelength, the angle θ for each diffraction order n depends linearly on 1/d. Thus, varying slit separation or wavelength changes the angle at which maxima appear, illustrating the grating's ability to separate different light wavelengths based on their direction .

You might also like