Posts

Showing posts from May, 2022

To study the growth and decay of current in RL circuit containing (a) DC source and (b) AC using Runge-Kutta method, and to draw graphs between current and time in each case.

Image
 To study the growth and decay of current in RL circuit containing (a) DC source and (b) AC using Runge-Kutta method, and to draw graphs between current and time in each case. Python Code: # --------------------------------------------------------------- # exp -10: To study the growth and decay of current in RL circuit # containing DC source using Runge - Kutta method , and to draw # graphs between current and time in each case # --------------------------------------------------------------- import  numpy  as  np import  math import  matplotlib . pyplot  as  plt e =  1.0 ;  # emf ( volt ) r =  0.2 ;  # resistance ( Ohm ) l =  1.0 ;  # inductor ( Henry ) tf ...

To study the motion of an artificial satellite by solving Newton’s equation for its orbit using Euler method.

Image
Study the motion of artificial satellite by solving Newton’s equation for its orbit using Euler method. Python Code for Euler's Method(Motion of Satellite) # ------------------------------------------------------------------------- # Exp -9: To study the motion of an artificial satellite by solving # N e w t o n s equation for its orbit using Euler method . # ------------------------------------------------------------------------- import  numpy  as  np import  math import  matplotlib . pyplot  as  plt pi =  22.0 / 7.0 ; G =  4 * pi ** 2 M =  1.0 R0 =  1 v = np . sqrt (G* M/ R0 ); n =  4 # ------------------------------------------------------------------------- def   euler_orbit  ( x ...

To simulate the random walk.

Image
  To simulate the random walk. Python Code for 1D Random Walk :  # --------------------------------------------------------------------- # exp -8: To simulate the random walk (1 -d) # --------------------------------------------------------------------- import  random import  numpy  as  np import  matplotlib . pyplot  as  plt n =  100000   # defining the number of steps x = np . zeros (n )  # creating empty array t = np . zeros (n ) # -------- filling the coordinates with random variables -------------- x [ 0 ] = random . randint ( 1  ,  10 ) for  i  in  range ( 1  , n):   t[i ] = i   val = random ....

To find the area of a unit circle by Monte Carlo integration.

Image
 To find the area of a unit circle by Monte Carlo integration. Python Code: # -------------------------------------------------------------------- # Exp -7: To find the area of a unit circle by Monte Carlo integration # -------------------------------------------------------------------- import  numpy  as  np import  matplotlib . pyplot  as  plt import  random def   in_circle  (  x_pos  ,  y_pos  ):    # Setting radius to 1 for unit circle   radius =  1    return  x_pos ** 2  + y_pos ** 2  < radius ** 2 # ------------------------------------------------------------------- # function to integrate a unit circle to find pi via monte_carlo def   monte_ca...

To fit the Einstein’s photoelectric equation to a realistic data set and hence calculate Planck’s constant. To estimate the value of by rectangular method, Simpson rule and Gauss quadrature by numerically evaluating suitable integral.

Image
 To fit the Einstein’s photoelectric equation to a realistic data set and hence calculate Planck’s constant. To estimate the value of by rectangular method, Simpson rule and Gauss quadrature by numerically evaluating suitable integral. Python Code: (Least Square Fitting) # --------------------------------------------------------- # exp -6 (a) Calculating the Plank ’s constant from Einstein ’s # photoelectric eqaution ( using least square fitting of # straight line ) # --------------------------------------------------------- import  numpy  as  np # --------- experimental data ------------------------------ lam = [ 500  ,  450  ,  400  ,  350  ,  300  ,  250 ];  # wavelength (nm) y = [ 0.19  ,  0.48  ,  0.83  ,  1.30 ...

To interpolate a real data set from an experiment using the Lagrange’s method, and Newton’s method of forward differences.

Image
  To interpolate a real data set from an experiment using the Lagrange’s method, and Newton’s method of forward differences. Python Program: (For Newton Forward Interpolation) # ------------------------------------------------ # Newton method of forward difference # ------------------------------------------------ def   fact  (  n ):   f =  1 ;    for  i  in  range ( 2  , n + 1 ) :     f = f *i  # f *= i    return  f; # ------------------------------------------------ def   p_cal  ( p  , n  ):  # p(p -1) (p -2) ........(p-n)   temp = p    for  i  in  range ( 1  , n):     temp = temp * ( p - i);    return  temp...

Solving Van Der Waals gas equation for volume of a real gas by the method of successive approximation.

Image
 To solve van der Waals gas equation for volume of a real gas by the method of successive approximation. Python Code: # ------------------------------------------------ # Exp -4: To solve van der Waals gas equation for # volume of a real gas by the method of # successive approximation ( iteration method ). # ------------------------------------------------ # V = R*T/(P + a/(V*V)) + b = g(V) # range of V = [3 , 10] # a = 1.5 # T = 300 K # R = 8.3144 J/(K. mol ) # ----------------------------------------------- import  numpy  as  np import  math a =  1.5   # constant T =  300   #K R =  8.3144   # J/(K. mol ) # -----...

Solving Kepler’s equation by Newton-Raphson method

Image
 To solve Kepler’s equation by Newton-Raphson method Python Program: # ------------------------------------------------------------- # Exp -3: To solve K e p l e r s equation by Newton - Raphson method # ------------------------------------------------------------- import  numpy  as  np import  math # ------------------------------------------------------------- def   kepler_eq  ( M  ,  E  ,  e  ,  err  ): # M [ rad ], E [ rad ], e = between 0 to 1, E inital assumption   print ( " --------------------------------------------------------------" )   print ( " value of M:" , M ,  ", value of e:" ,e ,  ", intial value of E:" ,E...

Determining Wien’s constant using bisection method and false position method. (Python Program)

Image
  To determine Wien’s constant using Bisection Method and False position method. Theory: Bisection Method # ---------------------------------------------- # Exp :2 To determine Wien ’s constant using bisection # method and false position method . # ----------------------------------------------- import  numpy  as  np import  math # ------------ equation --- ---- ----- ----- ---- ----- def   func  (  x ):    return   5 * math.exp(-x)+x  -5 # ---------- bisection method -- ----- ----- ---- ----- def   bisection  ( a  , b ) :    if ( func (a) * func (b) >=  0 ) :     print ( " you have not choose right a and b \n" )  ...

To find mean , standard deviation and frequency distribution of an actual data set (Python Program)

Image
  Python Program: # --------------------------------------------------------------------- # Exp -1: To find mean , standard deviation and frequency distribution # of an actual data set from any physics experiment # --------------------------------------------------------------------- import  numpy  as  np  # numpy related numerical python import  statistics import  matplotlib . pyplot  as  plt x = [ 102  ,  104  ,  107  ,  112  ,  108  ,  110  ,  103  ,  101  ,  100  ,  104  ,  103  ,  104  ,  101  ,  105 ]  print ( "-------------------------------------------------------" ) print ( "             Re...