Sie sind auf Seite 1von 49

The icfai university

kamalghat, tripura

A Report On Essential Skills Of Python Programming For


Physicists
Submitted for the partial fulfilment of the requirement for the degree of M.sc Physics

SUBMITTED BY- BIDHAN ROY (18IUT0080024) MENTOR – Dr. LOKESH MOHAN


SUMAN DAS (18IUT0080019)
MANDIRA BHOWMIK (18IUT0080020)
CHAYANIKA SARKAR (18IUT0080022)
AKASH DEY (18IUT0080023)
MANIDIPA DAS (18IUT0080027)
MOURITA CHAKRABORTY (18IUT0080026)
What We Give you?

1. What is Python…?
2. History of Python..
3. Computational physics with Python.
4. Programmes With Python ,
a) Quantum Physics visulization with Python.
b) Trajectory of Projectile motion using Python.
c) Dot and Cross Product Of Two Vector Using Python.
d) Basic Types of Logic Gates Using Python Language.
e) Program in python to multiply two matrices using Nested loops.
5. Advantage of Python.
6. Conclusion.
What is Python…?

Python is a general purpose programming language that is often applied in scripting roles. So,
Python is programming language as well as scripting language.Python is also called as
Interpreted language
History

Invented in the Netherlands, early 90s by Guido van Rossum. Python was conceived in the late
1980s and its implementation was started in December 1989.Guido Van Rossum is fan of
‘Monty Python’s Flying Circus’, this is a famous TV show in Netherlands. Named after
Monty Python.Open sourced from the beginning.
Computational Physics with Python

The Python programming language is an excellent choice for learning, teaching, or doing
computational physics. It is a well-designed, modern programming language that is
simultaneously easy to learn and very powerful. It includes a range of features tailored for
scientific computing, including features for handling vectors, inverting and diagonalizing
matrices, performing Fourier transforms, making graphs, and creating 3D graphics.
Quantum Physics
Visualization
With Python Language
Presented By -: Bidhan Roy (18IUT0080024)
 Schrodinger Equation:
In 1926, Erwin Schrodinger advanced the famous wave equation that relates the energy of a system to
its wave properties. Because its application to the hydrogen atom is rather complicated, we shall first
use wave equation to solve the particle-in-a-box. The Schrodinger Wave equation expressing in 1D is ,
 Visualizing Particle-In-A-Box:

Now, to simplify our equation, we assume a Particle In A Box.


The particle-in-a-box problem does not correspond to any real chemical system. Its usefulness in our context is
that it illustrates several quantum mechanical features. The potential energy at the barrier is set to infinity (i.e.
the particle cannot escape) and the potential energy inside the barrier is set to 0. Under these conditions,
classical mechanics predicts that the particle has an equal probability of being in any part of the box and the
kinetic energy of the particle is allowed to have any value. Taking this assumption into consideration, we get
different equations for the particle’s energy at the barrier and inside the box.

At the barrier, V is infinite and the hence, the particle does not exist:

Inside the box, V is zero and hence the wave can have any finite value:

Continue...
Inside the box, we can rearrange the equation as follows:

As we can see above, the wave function would be such that if differentiated twice, should give the same function
multiplied by E. The sine function possesses this behavior.

Continue...
Now, we need to evaluate the values for the constants, α and A. For α, we use the wave equations at the barriers,
where the wave functions equal 0.

Now plugging in the value for α:

Continue...
We can determine the value of A by requiring the wave function to be normalized. This is because, the particle
must exist somewhere in the box. Hence, the sum of the probability of finding the particle in the box is 1:

Continue...
Plugging in the values, the final wave and energy equations are:
 Visualizing the Energy and wave functions using Python:
import matplotlib.pyplot as plt
import numpy as np

#Constants
h = 6.626e-34
m = 9.11e-31 plt.subplot(3,2,2*n-1)
plt.plot(x_list, psi_list)
plt.xlabel("L", fontsize=13)
#Values for L and x plt.ylabel("Ψ", fontsize=13)
x_list = np.linspace(0,1,100) plt.xticks(np.arange(0, 1, step=0.5))
L=1 plt.title("n="+str(n), fontsize=16)
plt.grid()
def psi(n,L,x):
return np.sqrt(2/L)*np.sin(n*np.pi*x/L) plt.subplot(3,2,2*n)
plt.plot(x_list, psi_2_list)
def psi_2(n,L,x): plt.xlabel("L", fontsize=13)
plt.ylabel("Ψ*Ψ", fontsize=13)
return np.square(psi(n,L,x))
plt.xticks(np.arange(0, 1, step=0.5))
plt.title("n="+str(n), fontsize=16)
plt.figure(figsize=(15,10)) plt.grid()
plt.suptitle("Wave Functions", fontsize=18)

for n in range(1,4):
#Empty lists for energy and psi wave
psi_2_list = []
psi_list = []
for x in x_list:
psi_2_list.append(psi_2(n,L,x))
psi_list.append(psi(n,L,x))
 OUTPUT:
Trajectory of Projectile motion
using Python

Presented By :- Suman Das (18IUT0080019)


 Trajectory of projectile motion using python:
 Output:-

T
Dot and Cross Product Of Two
Vector Using Python
Presented By :- Mandira Bhowmik (18IUT0080020)
 DOT AND CROSS PRODUCT OF TWO VECTOR USING
PYTHON:
Basic Types of Logic Gates
Using Python Language

Presented By :- Chayanika Sarkar (18IUT0080022)


Akash Dey (18IUT0080023)
Manidipa Das (18IUT0080027)
 Logic Gate:
Actually the term logic is applied to digital circuits used to implement logic functions. Several kinds of
digital logic circuits are the basic elements that form the building blocks for such complex digital system
as the computer.
 The lines connected to each symbols are the inputs and outputs.
 The inputs are on the left of each symbol and the output is on the right.
 A circuit that performs a specific logic operation (AND, OR) is called a logic gate.
 Basic types of logic gates:

• AND GATE
• OR GATE
• NOT GATE
• NAND GATE
• NOR GATE
• EX-OR GATE
 AND GATE:
 An AND gate can have two or more inputs and performs what is know as multiplication.
 The output of AND gate is high when all inputs are high otherwise all outputs are low.
 INPUT OF AND GATE USING PYTHON:
• def AND (a, b):

•     if a == 1 and b == 1:
•         return True
•     else:
•         return False

• if __name__=='__main__':
•     print(AND(1, 1))

•     print("+---------------+----------------+")
•     print(" | AND Truth Table | Result |")
•     print(" A = False, B = False | A AND B =",AND(False,False)," | ")
•     print(" A = False, B = True | A AND B =",AND(False,True)," | ")
•     print(" A = True, B = False | A AND B =",AND(True,False)," | ")
•     print(" A = True, B = True | A AND B =",AND(True,True)," | ")
 OUTPUT OF AND GATE USING PYTHON:
• True
• +---------------+----------------
• | AND Truth Table | Result |
• A = False, B = False | A AND B = False |
• A = False, B = True | A AND B = False |
• A = True, B = False | A AND B = False |
• A = True, B = True | A AND B = True |
 OR GATE:
 OR gate can have two or more inputs and performs what is known as logical addition.
 The output of OR gate is Low when all inputs are low, otherwise all outputs are high.
 INPUT OF OR GATE USING PYTHON:
• def OR(a, b):
•     if a == 1:
•         return True
•     elif b == 1:
•         return True
•     else:
•         return False

• if __name__=='__main__':
•     print(OR(0, 0))

•     print("+---------------+----------------+")
•     print(" | OR Truth Table | Result |")
•     print(" A = False, B = False | A AND B =",OR(False,False)," | ")
•     print(" A = False, B = True | A AND B =",OR(False,True)," | ")
•     print(" A = True, B = False | A AND B =",OR(True,False)," | ")
•     print(" A = True, B = True | A AND B =",OR(True,True)," | ")
 OUTPUT OF OR GATE USING PYTHON:
• False
• +---------------+----------------+
• | OR Truth Table | Result |
• A = False, B = False | A AND B = False |
• A = False, B = True | A AND B = True |
• A = True, B = False | A AND B = True |
• A = True, B = True | A AND B = True |
 NOT GATE:
•  The inverter (NOT circuit) performs the operation called inversion or complementation.
•  The NOT operation changes one logic level to the opposite logical level. When the input is Low,
the output is high.
 INPUT OF NOT GATE USING PYTHON:
  
• def NOT(a):
•     if(a == 0):
•         return 1
•     elif(a == 1):
•         return 0
• if __name__=='__main__':
•     print(NOT(0))

•     print("+---------------+----------------+")
•     print(" | NOT Truth Table | Result |")
•     print(" A = False | A NOT =",NOT(False)," | ")
•     print(" A = True, | A NOT =",NOT(True)," | ")
   
 OUTPUT OF NOT GATE USING PYTHON:
• 1
• +---------------+----------------+ |
• NOT Truth Table | Result |
• A = False | A NOT = 1 |
• A = True, | A NOT = 0 |
•  NAND GATE:
•  The NAND gate is the one of the popular logic element because it can be used as a universal
gate; that is NAND gate can be used in combination to perform the AND, OR, and inverter
operations.
•  NAND Gate is constructed by attaching NOT Gate at the output of AND Gate, hence NAND
Gate is called NOT- AND Gate.
•  The output of NAND gate is low when all inputs are high, otherwise all outputs are high
 INPUT OF NAND GATE USING PYTHON:
  
• def NAND (a, b):
•     if a == 1 and b == 1:
•         return False
•     else:
•         return True

• if __name__=='__main__':
•     print(NAND(1, 0))
 
•     print("+---------------+----------------+")
•     print(" | NAND Truth Table | Result |")
•     print(" A = False, B = False | A AND B =",NAND(False,False)," | ")
•     print(" A = False, B = True | A AND B =",NAND(False,True)," | ")
•     print(" A = True, B = False | A AND B =",NAND(True,False)," | ")
•     print(" A = True, B = True | A AND B =",NAND(True,True)," | ")
 OUTPUT OF NAND GATE USING PYTHON:
• True
• +---------------+---------------- |
• NAND Truth Table | Result |
• A = False, B = False | A AND B = True |
• A = False, B = True | A AND B = True |
• A = True, B = False | A AND B = True |
• A = True, B = True | A AND B = False |
•  NOR GATE:
•  The NOR gate, like the NAND gate, NOR gate is also useful logical element because it can also be
used as a universal gate.
•  NOR gate can be used in combination to perform the AND, OR and Inverter operations.
•  NOR Gate is the combination of NOT gate at the output of OR gate, hence NOR gate is type of
NOT-OR gate.
•  The Output of NOR gate is high when all inputs are low otherwise the output is low.
 INPUT OF NOR GATE USING PYTHON:
  
• def NOR(a, b):
•     if(a == 0) and (b == 0):
•         return 1
•     elif(a == 0) and (b == 1):
•         return 0
•     elif(a == 1) and (b == 0):
•         return 0
•     elif(a == 1) and (b == 1):
•         return 0
  
•  
• if __name__=='__main__':
•     print(NOR(0, 0))
  
•     print("+---------------+----------------+")
•     print(" | NOR Truth Table | Result |")
•     print(" A = False, B = False | A AND B =",NOR(False,False)," | ")
•     print(" A = False, B = True | A AND B =",NOR(False,True)," | ")
•     print(" A = True, B = False | A AND B =",NOR(True,False)," | ")
•     print(" A = True, B = True | A AND B =",NOR(True,True)," | ")
 OUTPUT OF NOR GATE USING PYTHON:
• 1
• +---------------+----------------+
• | NOR Truth Table | Result |
• A = False, B = False | A AND B = TRUE |
• A = False, B = True | A AND B = FALSE |
• A = True, B = False | A AND B = FALSE |
• A = True, B = True | A AND B = FALSE |  
•  EX- OR GATE:
•  The exclusive-OR gate has a graphical symbol similar to that of the OR gate, except for the
additional curved line on the input side.
•  If both inputs are Low or both are High then it produces the output Low or 0. otherwise it produce the
High.
 INPUT OF EX-OR GATE USING PYTHON:
• def XOR (a, b):
•     if a != b:
•         return 1
•     else:
•         return 0
  
• if __name__=='__main__':
•     print(XOR(5, 5))
 
•     print("+---------------+----------------+")
•     print(" | XOR Truth Table | Result |")
•     print(" A = False, B = False | A AND B =",XOR(False,False)," | ")
•     print(" A = False, B = True | A AND B =",XOR(False,True)," | ")
•     print(" A = True, B = False | A AND B =",XOR(True,False)," | ")
•     print(" A = True, B = True | A AND B =",XOR(True,True)," | ")
 OUTPUT OF EX-OR GATE USING PYTHON:
.0
. +-------------+----------------+
• | XOR Truth Table | Result |
• A = False, B = False | A AND B = FALSE |
• A = False, B = True | A AND B = TRUE |
• A = True, B = False | A AND B = TRUE |
• A = True, B = True | A AND B = FALSE |
Program in python to
multiply two matrices using
Nested loops

Presented By :- Mourita Chakraborty (18IUT0080026)


 Program in python to multiply two matrices using nested loops:
X = [[12,7,3],
[4 ,5,6],
[7 ,8,9]]
Y = [[5,8,1,2],
[6,7,3,0],
[4,5,9,1]]
result = [[0,0,0,0],
[0,0,0,0],
[0,0,0,0]]
for i in range(len(X)):
for j in range(len(Y[0])):
for k in range(len(Y)):
result[i][j] += X[i][k] * Y[k][j]
for r in result:
print(r)
 Advantages:-

1. Easy to use:
Python is compact and very easy to use object oriented language with very simple syntax
rules. It is very high level language and thus very-very programmer friendly.
2. Interpreted language:
Python is an interpreted language, not a compiled language. This means that the pinstallation
interprets and executes the code line by line at a time. It makes python an easy to debug
language and suitable for beginners to advanced users.
3. Free and open source:
Python language is freely available i,e, without any cost and not only is it free, its source code
is also available, i.e. it is open source also.
Conclusion:

In the end, I would like to conclude that different programmes using python programming
could have been made in more efficient way. I have given my level best for doing this report on
python programming. I am almost content with the outcome and i am looking forward to learn
from its flaws and try and improvise my skills on python programming in future internship
projects. We hope this report reaches the expectations of our respected professors.

Das könnte Ihnen auch gefallen