Open navigation menu
Close suggestions
Search
Search
en
Change Language
Upload
Sign in
Sign in
Download free for days
0 ratings
0% found this document useful (0 votes)
15 views
Python Unit - 5
Python programming in physics
Uploaded by
premsnp2003
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save python unit -5 For Later
Download
Save
Save python unit -5 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
0 ratings
0% found this document useful (0 votes)
15 views
Python Unit - 5
Python programming in physics
Uploaded by
premsnp2003
AI-enhanced title
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content,
claim it here
.
Available Formats
Download as PDF or read online on Scribd
Download now
Download
Save python unit -5 For Later
Carousel Previous
Carousel Next
Download
Save
Save python unit -5 For Later
0%
0% found this document useful, undefined
0%
, undefined
Embed
Share
Print
Report
Download now
Download
You are on page 1
/ 11
Search
Fullscreen
Radioactivity = Apr 10, 2021 * 1 min read Q |View on GitHub launch |binder Open in Golab import numpy as np import matplotlib.pyplot as plt import random from scipy.integrate import odeint from scipy.integrate import solve_ivp| See eee Radioactive Decay by solving ODE Rate of decay of a radioactive nuclei is dN ‘dt This is a first order differential equation which can be solved by any standard method. But, we must mention initial condition of the decay, i.e. at time t = 0 , what is number of radioactive nuclei =-\Nimport numpy as np import matplotlib.pyplot as plt import random from scipy.integrate import odeint from scipy.integrate import solve_ivf SSS eo Radioactive Decay by solving ODE Rate of decay of a radioactive nuclei is dN a —rAN This is a first order differential equation which can be solved by any standard method. But, we must mention initial condition of the decay, i.e. at time t — ( , what is number of radioactive nuclei N(0) present in the substance? Consider,Consider, at t=0, N(0) = No ¢ NO = 1000 T_half = 4.5*60 lamda = 1/ T_half Creating time array t_init, t_final, step_size = 0, 1000, t = np.arange(t_init, t_final, step_g ee) Model of radioactivity def model( return -la By odeint method from scipy.integrate = odeint(model, NO, t) sol[:, 0] -plot(t, N, ls='- color='red', -plot(t, NO - N, ls ar1000 800 600 Parent nucleus --- Daughter nucleus 400 200 0 200 400 600 800 1000 By solve.ivp from scipy.integrate def model(t, N): # order of the ar return -lamda*N sol = solve_ivp(model, t_span=(t[0], sol.t1000 800 600 400 200 Simulation of Radioactive Decay by Monte Carlo method = 4,5*60 lamda = 1/ T_half N = 1000 Xo ean) time = np.arange(0, for t in time: P.append(Np) D.append(Nd) decay = 0 for n in range(Np): Parent Nucl ae TOF 4p) 18] Ee ea # Decay const. Initial numi 0, 1)P.append(N D.append(Nd) decay = 0 for n in range(Np): pe random. random() if p < lamda: decay += 1 Np -= decay Nd += decay plt.plot(P, linestyle='-', color='red plt.plot(D, linestyle='-', color='blu plt.legen plt.xlabel('t', fontsize=14) plt.ylabel('N(t)', fontsize=14) plt.sho QE 1000 800 600 Parent Nucleus — Daughter Nucleus N(t) 400 200 r T T 0 200 400 600 800 1000Estimating the value of Pi using Monte Carlo Monte Carlo estimation Monte Carlo methods are a broad class of computational algorithms that rely on repeated random sampling to obtain numerical results. One of the basic examples of getting started with the Monte Carlo algorithm is the estimation of Pi. Estimation of Pi The idea is to simulate random (x, y) points in a 2- D plane with domain as a square of side 2r units centered on (0,0). Imagine a circle inside the same domain with same radius r and inscribed into the square. We then calculate the ratio of number points that lied inside the circle and total number of generated points. Refer to the image below:Random points are generated only few of which lie outside the imaginary circle We know that area of the square is 4p? unit sq while that of circle is are. The ratio of these two areas is as follows : area of the circle _ ar? __ Tr area of the square — 472 — > | Now for a very large number of generated points, no. of points generated inside the circle otal no. of points generated or no. of points generated inside the square t. The beauty of this algorithm is that we don’t need any graphics or simulation to display the generated points. We simply generate random (x, y) pairs and then check if x + y? <1 yes, we increment the number of points that appears inside the circle. In randomized and simulation algorithms like Monte Carlo, the more the number of iterations, the more accurate the result is. Thus, the title is “Estimating the value of Pi” and not “Calculating the value of Pi”. Below is the algorithm for the method:Pi” and not “Calculating the value of Pi”. Below is the algorithm for the method: The Algorithm 1. Initialize circle_points, square_points and interval to 0. 2. Generate random point x. . Generate random point y. . Calculate d = x*x + y*y, . If d <= 1, increment circle_points. . Increment square_points. . Increment interval. . If increment < NO_OF_ITERATIONS, repeat from Non Aas w 9. Calculate pi = 4*(circle_points/square_points). 10. Terminate. The code doesn't wait for any input via stdin as the macro INTERVAL could be changed as per the required number of iterations. Number of iterations are the square of INTERVAL. Also, I’ve paused the screen for first 10 iterations with getch() and outputs are displayed for every iteration with format given below. You can change or delete them as per requirement. x y circle_points square_points - piExamples: INTERVAL = 5 Output : Final Estimation of Pi = 2.56 INTERVAL = 10 Output : Final Estimation of Pi = 3.24 INTERVAL = 100 Output : Final Estimation of Pi = 3.0916 C++ Java Python C# Javascript for estimation of Pi using Monte tion */ stdce++.h> ision for x and y values. More the re the number of significant digits L 10000 std; 1, oh; -x, vand_y, origin_dist, pi; points = 0, square_points = 0; zing rand() NULL) );Examples: TEAL = 5 utout + Final estination of Pi = 2.56 rnTERUAL = 10 futout + Final estination of PL = 3.26 INTERVAL = 100 output : Final Estinetion of Pi ~ 3.0916 cr Java Python ce /* Cee program for estimation of Pi using Monte cart simuiation */ Haneluse
// Dezinee precision for x and y values. More the (o Zntervals nore the sumber of sapnsficane asgste Sgetine INTERVAL 10000 using nes pace sta: sot main t Ant sntervat, i double rend_x. randy, origin-dist. pi: Ant circle points = 0, sguare_potnte = 0: 1) Initializing rand) arena( tame( NULL!) {7 Total Rendon numbers generated + possible x 17 vatues * possabie y values for (i = 0: i < (INTERVAL © INTERVAL: i+) [ 11 Randonty generated x and y values rendx = double(rend(1 % (INTERVAL + 1) / INTERVAL, pand_y + double(rand(1 % (INTERVAL + 101 / INTERVAL: // Diotence vetween (x. y) from the ortgan, origin-dist + rand.x * randoe + randy | rand. 1/ Checking af (x. y) lies ineide the define i esrcle with Ret Af lorigin diet <= 1) // Total number of pointe generated // eotinated pi after this iteration pa + doubleis * cizeteposnts) / aquareposnte: / For visual underetanding (Optéons1) cout << rand <<" * << randy <<" * k< citele points << * * << aquare_pointe ee st ee pa ce end // Bausing extimation for first 10 velues (Optional! sf 3 < 20) wotchar(): d 1) Samah Estamated Value cout << “\nFinal Estimation of PA = *
You might also like
Calculation of Pi Using The Monte Carlo Method
PDF
No ratings yet
Calculation of Pi Using The Monte Carlo Method
12 pages
pi complete
PDF
No ratings yet
pi complete
5 pages
pi ka value
PDF
No ratings yet
pi ka value
6 pages
Simulation Lab1 Word
PDF
No ratings yet
Simulation Lab1 Word
5 pages
Labreport Simulation Modeling
PDF
No ratings yet
Labreport Simulation Modeling
14 pages
UE223115 - Zodrick John (Exp - 6)
PDF
No ratings yet
UE223115 - Zodrick John (Exp - 6)
2 pages
Metodo_numericos_trabajo_1
PDF
No ratings yet
Metodo_numericos_trabajo_1
3 pages
matlab14
PDF
No ratings yet
matlab14
4 pages
Monte Carlo Simulation For Finding Pi
PDF
No ratings yet
Monte Carlo Simulation For Finding Pi
2 pages
Simulation Lab1 PDF NW
PDF
No ratings yet
Simulation Lab1 PDF NW
4 pages
Monte Carlo Simulation
PDF
No ratings yet
Monte Carlo Simulation
6 pages
Simulation Lab1 PDF
PDF
No ratings yet
Simulation Lab1 PDF
4 pages
Monte_Carlo_Project
PDF
No ratings yet
Monte_Carlo_Project
2 pages
Pi - Chudnovsky
PDF
No ratings yet
Pi - Chudnovsky
9 pages
Monte_Carlo_Project_Advanced
PDF
No ratings yet
Monte_Carlo_Project_Advanced
3 pages
Monte Carlo Simulation
PDF
No ratings yet
Monte Carlo Simulation
6 pages
Project 1: Numerical Method Programming (Python - Monte Carlo)
PDF
No ratings yet
Project 1: Numerical Method Programming (Python - Monte Carlo)
12 pages
Document15
PDF
No ratings yet
Document15
3 pages
Approximation of Pi by Monte Carlo Simulation
PDF
No ratings yet
Approximation of Pi by Monte Carlo Simulation
2 pages
estimation
PDF
No ratings yet
estimation
11 pages
Motecarlopi
PDF
No ratings yet
Motecarlopi
2 pages
Monte Carlo Simulation: MATLAB, Extra Credit Assignment
PDF
No ratings yet
Monte Carlo Simulation: MATLAB, Extra Credit Assignment
3 pages
Simulation: Programming in R For Data Science Anders Stockmarr, Kasper Kristensen, Anders Nielsen
PDF
No ratings yet
Simulation: Programming in R For Data Science Anders Stockmarr, Kasper Kristensen, Anders Nielsen
19 pages
Un Peu de Math... : Using Monte Carlo Simulation For The Estimation of Pi
PDF
No ratings yet
Un Peu de Math... : Using Monte Carlo Simulation For The Estimation of Pi
3 pages
Monte Carlo Simulation-Project
PDF
No ratings yet
Monte Carlo Simulation-Project
33 pages
Application of Monte-Carlo Simulations in Estimati
PDF
No ratings yet
Application of Monte-Carlo Simulations in Estimati
6 pages
Ray.tracing.the.Rest.of.Your.life.v4.0.0 Alpha.1
PDF
No ratings yet
Ray.tracing.the.Rest.of.Your.life.v4.0.0 Alpha.1
68 pages
2d650fb8-6954-4f7b-b2ac-57c911bdb7c4
PDF
No ratings yet
2d650fb8-6954-4f7b-b2ac-57c911bdb7c4
33 pages
Lab File Os Upto 8th
PDF
No ratings yet
Lab File Os Upto 8th
47 pages
A Ballistic Monte Carlo Approximation of π
PDF
No ratings yet
A Ballistic Monte Carlo Approximation of π
4 pages
Monte Carlo Simulation-Project
PDF
No ratings yet
Monte Carlo Simulation-Project
33 pages
Why Calculate PI
PDF
No ratings yet
Why Calculate PI
3 pages
Editedcode
PDF
No ratings yet
Editedcode
3 pages
AGH Computer Science C Programming Laboratory 5
PDF
No ratings yet
AGH Computer Science C Programming Laboratory 5
4 pages
Simulation Lab Report 9
PDF
No ratings yet
Simulation Lab Report 9
6 pages
AI Obse-2
PDF
No ratings yet
AI Obse-2
32 pages
Monte Carlo Simulation-Project
PDF
No ratings yet
Monte Carlo Simulation-Project
33 pages
Slides Monte Carlo
PDF
No ratings yet
Slides Monte Carlo
51 pages
Term Paper On Monte Carlo Method
PDF
No ratings yet
Term Paper On Monte Carlo Method
10 pages
C++ Examples - Cumulative Normal Distribution Function
PDF
No ratings yet
C++ Examples - Cumulative Normal Distribution Function
7 pages
Monte Carlo Method
PDF
No ratings yet
Monte Carlo Method
3 pages
A Review of Monte Carlo Methods and Their Application in Medical
PDF
No ratings yet
A Review of Monte Carlo Methods and Their Application in Medical
38 pages
N Ways of Measuring PI
PDF
No ratings yet
N Ways of Measuring PI
12 pages
Lecture8 1
PDF
No ratings yet
Lecture8 1
30 pages
Ray Tracing_ the Rest of Your Life
PDF
No ratings yet
Ray Tracing_ the Rest of Your Life
53 pages
RayTracingTheRestOfYourLife-v4.0.2
PDF
No ratings yet
RayTracingTheRestOfYourLife-v4.0.2
84 pages
Python Handson
PDF
No ratings yet
Python Handson
16 pages
Monte Carlo Methods Monte Carlo Methods: Fall 2010
PDF
No ratings yet
Monte Carlo Methods Monte Carlo Methods: Fall 2010
15 pages
Chapter 3 - Random Numbers - 2013 - Simulation
PDF
No ratings yet
Chapter 3 - Random Numbers - 2013 - Simulation
8 pages
The Unit Circle: For The Quarter Circle and The Pi Experiment, See The Graph Below
PDF
No ratings yet
The Unit Circle: For The Quarter Circle and The Pi Experiment, See The Graph Below
36 pages
Calculation of Pi Using The Monte Carlo Method
PDF
No ratings yet
Calculation of Pi Using The Monte Carlo Method
5 pages
MSC Ivsem
PDF
No ratings yet
MSC Ivsem
37 pages
Monte Carlo Estimation of e
PDF
No ratings yet
Monte Carlo Estimation of e
4 pages
explanationschatgtp (1)
PDF
No ratings yet
explanationschatgtp (1)
8 pages
OpenMP Pi Calculation
PDF
No ratings yet
OpenMP Pi Calculation
1 page
Solutions To C Moler MATLAB Experiments Chapter 1
PDF
No ratings yet
Solutions To C Moler MATLAB Experiments Chapter 1
7 pages
Monte Carlo Simul NB
PDF
No ratings yet
Monte Carlo Simul NB
2 pages
IE 403 Ch03 RNG RVG With Comments
PDF
No ratings yet
IE 403 Ch03 RNG RVG With Comments
27 pages
CM_Unit II_1
PDF
No ratings yet
CM_Unit II_1
3 pages
DOC-20250309-WA0200
PDF
No ratings yet
DOC-20250309-WA0200
51 pages
CM_Unit I_11
PDF
No ratings yet
CM_Unit I_11
2 pages
PG PHYSICS SEM SCHEDULE NOV 2024
PDF
No ratings yet
PG PHYSICS SEM SCHEDULE NOV 2024
4 pages
1 MSc 25
PDF
No ratings yet
1 MSc 25
39 pages
Thin Film Notes
PDF
No ratings yet
Thin Film Notes
68 pages