Skip to content

Commit 3170fc7

Browse files
Create README for Numpy and Matplotlib projects
Added detailed README for Numpy and Matplotlib usage in physics problems, covering Maxwell-Boltzmann distribution, Lennard-Jones potential, radioactive decay, and trapped quantum particles.
1 parent e22127c commit 3170fc7

1 file changed

Lines changed: 122 additions & 0 deletions

File tree

README.md

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
# Reading Data Files into a Numpy arrays and Graph Plotting with Matplotlib Bar and Scatter Plots
2+
- This work aims to applying the main function for reading text files and statistically summarizing the values into a Numpy array.
3+
- Important Numpy data including: `genfromtxt`, `min`, `max`, `sign`, `sum`, `std`, and others in solving physics problems by Python 3 and Jupyter Notebook.
4+
5+
- # P6.1 - Maxwell-Boltzmann Distribution
6+
Write a function to the plot the Maxwell-Boltzmann Distribution of molecular speed for a gas of particles of a given mass at a given temperature, indicating the modal speed ($v_{*}$), mean ($\langle v \rangle$), and root mean square (rms, $\langle v^{2} \rangle^{1/2}$) speeds with vertical lines.
7+
8+
Call this function for the atomic gasses Helium (m = 4u), and Argon (m = 40u) at 300 K.
9+
10+
__Hints__: The modal speed is the maximum of the probability distribution and can be found $df/dv$. The mean and rms speeds can be obtained, respectively, from the integrals.
11+
12+
$\langle v\rangle = \int_{0}^{\infty} vf(v)$ and $\langle v^{2} \rangle = \int_{0}^{\infty} v^{2}f(v) dv$.
13+
14+
The following expression for the different types of average speed can be derived:
15+
16+
- $v_{*} = \sqrt{\frac{2k_{B}T}{m}}$ (mode)
17+
- $\langle v \rangle = \sqrt{\frac{8k_{B}T}{\pi m}}$ (mean)
18+
- $\langle v^{2} \rangle^{1/2} = \sqrt{\frac{3k_{B}T}{m}}$ (rms speed).
19+
20+
- ![Maxwell-Boltzmann Distribution of He and Ar](https://github.com/dindagustiayu/Aggregation-Indexing-Boleean-and-Reading-Data-into-Numpy-Array-for-Physics-problems./blob/master/Boleean-svg/Maxwell-Boltzmann%20Distribution%20of%20He%20and%20Ar.svg).
21+
22+
- # P6.2 Maxwell Boltzmann Distribution
23+
The Maxwell-Boltzmann equation, the basis of the kinetic thoery of gases, defines the distribution of speeds for a gas at a certain temperature. The Maxwell-Boltzmann distribuiton can be used to determine the distribution of the kinetic energy is identical to the distribution of the speeds for a certain gas at any temperature, _T_:
24+
25+
$f(v)=4\pi V^{2}(\frac{m}{2\pi k_{B}T})^{3/2}e^{\frac{-mv^{2}}{2k_{B}T}}$
26+
27+
__The key Functions and Argument__:
28+
29+
- `def`: starts the function
30+
- `return`: sends back the computed value when the function is called
31+
- `for` loop: iterate over multiple items
32+
- `zip`: combines multiple list into tuples
33+
- `np.linspace`: generate evenly spaced numbers (start/beginning range, stop/end of range, num/number of points)
34+
- `plt.rxParams`: control global plot settings(fonts, sizes, styles)
35+
- `plt.legend`: show labels for each curve
36+
37+
Calculated speed distribution of particles in He, Ne, Ar, and Xe, with temperature at 300 K.
38+
39+
Reference:
40+
- [The Maxwell-Boltzmann](https://bingweb.binghamton.edu/~suzuki/ModernPhysics/29_Boltzmann_theory_of_gas.pdf)
41+
- [P.33 Atomic Mass Unit](http://localhost:8888/lab/tree/Quantum-Code/posts/String_Flow_Control.ipynb)
42+
43+
![Probability Density of He, Ne, Ar and Xe at T = 300 K](https://github.com/dindagustiayu/Aggregation-Indexing-Boleean-and-Reading-Data-into-Numpy-Array-for-Physics-problems./blob/master/Boleean-svg/Probability%20Density%20of%20He%2C%20Ne%2C%20Ar%2C%20and%20Xe%20at%20T%20%3D%20300%20K.svg).
44+
45+
# P6.3 - The Lennard-Jones Interatomic Potential
46+
The Lennard-Jones potential is given by the following equation:
47+
48+
$V(r) = 4\epsilon[(\frac{\sigma}{r})^{12}-(\frac{\sigma}{r})^{6}]$
49+
50+
or sometimes expressed as:
51+
52+
$V(r)=\frac{A}{r^{12}}-\frac{B}{r^{6}}$
53+
54+
reference: [Lennard-Jones Potential](https://chem.libretexts.org/Bookshelves/Physical_and_Theoretical_Chemistry_Textbook_Maps/Supplemental_Modules_(Physical_and_Theoretical_Chemistry)/Physical_Properties_of_Matter/Atomic_and_Molecular_Properties/Intermolecular_Forces/Specific_Interactions/Lennard-Jones_Potential)
55+
56+
__The key argument__:
57+
58+
- `plt` and `pyplot`: matplotlib's functionality
59+
- `plt.xlim` and `plt.ylim`: set the plot limits manually
60+
- `linestyle`, `linewidth`, `color`, `marker`: matplotlib properties
61+
- `zorder`: controls the drawing order
62+
- `def`: intriduces a function definition
63+
- `return`: species the output of the function, without `return`, a function gives back `None` by default.
64+
65+
66+
(a) The $\epsilon$ and $\sigma$ for Xenon are found to be 1.77 kJ/mol and 4.10 Angstroms, respectively is the separation distance at which the potential is zero: $V(\sigma)=0$. Determine the van der Waals radius for the Xenon atom. Simply plotting _V(r)_ on a grid _r_ values will not yield a very satisfaction graph.
67+
68+
(b) Calculate the intermolecular potential between two Argon (Ar) atoms separated by a distance of 4.0 $\mathring{\text{A}}$ (use $\epsilon=0.997$ kJ/mol and $\sigma=3.40 \mathring{\text{A}}$).
69+
70+
![Lennard-Jones Potential for Xenon](https://github.com/dindagustiayu/Aggregation-Indexing-Boleean-and-Reading-Data-into-Numpy-Array-for-Physics-problems./blob/master/Boleean-svg/Lennard-Jones.svg).
71+
72+
# P6.4 - Radioactive list
73+
A radioactive material with an original mass, $N_{0}$, after a time _t_.
74+
75+
- $N(t)=N_{0}e^{\frac{-t}{\tau}}$
76+
77+
(a) Make a while loop which fills two lists: One with spaced time-points _t_, and with values of _N(t)_ at these time-points. The loop should run until the remaining amount of materials is below 50% of the original. Start in _t = 0 s_, and use time-steps of 60s, a mass $N_{0}=4.5$ kg of carbon-11, which has a time constant $\tau=1760 s$.
78+
79+
__The key argument__:
80+
81+
- `append`: add something to the end of the list
82+
- `zip()`: combine two (or more) sequences element by element
83+
- `while x() >= () * x0`: ensure the loop runst until the x is below the original x
84+
- `pyplot`: used to create and annonate figures using simple
85+
86+
(b) You might have notices that by aborting the loop when half of the material is gone, the last element in our time-list should be the _half-life_ of the carbon-11, $t_{1/2}$. The half life of a material to decay.
87+
test that this is true by printing and comparing the last element in your time-list to the _half-life_ of carbon-11, defined as
88+
89+
- $t_{1/2}=\tau ln2$
90+
91+
Remember that because your program uses time-steps of one minute, your measured _half-life_ can have an error up to 60 seconds.
92+
93+
(c) Combine the list into a nested list Nt, such that every element in the list Nt is a pair of matching t and _N(t)_ values. For example, the first element Nt[0] of this listshould be [0, 4.5]. Use the new nested list to wirte nicely a formatted table of corresponding _t_ and _N(t)_ values to the terminal.
94+
95+
![Radioactive decay of carbon-11](https://github.com/dindagustiayu/Aggregation-Indexing-Boleean-and-Reading-Data-into-Numpy-Array-for-Physics-problems./blob/master/Boleean-svg/Radioactive%20decay%20of%20carbon-11.svg).
96+
97+
# P6.5 - Trapped Quantum Particle
98+
One of the rules in quantum mechanics is that, sometimes, particles are only allowed to have specific energies, and can never have an energy in between these allowed levels. The particle must therefor must jump straight from one energy level to another.
99+
100+
__The key functions and arguments:__
101+
102+
- `sum()`: adds up all elements in an iterable (like a list)
103+
- `np.array()`: creates a NumPy array from a list or other sequence
104+
- `np.concatenates()`: joins (concatenates) multiple arrays along specified axis
105+
- `plt.subplota`: create a new figure and one or more subplots. Return (`fog, ax` objects.
106+
- `set_array`: set the value that control colormap coloring (`line collection`)
107+
- `ax.scatter`: creates a scatter plot on a specific axis(`ax`)
108+
- `ax.autoscal`" automatically adjust the axis limits to fit the data.
109+
110+
When a particle is trapped in a tiny box of size _L_, quantum mechanics say that it is only allowed to have energies.
111+
112+
$E_{n}=\frac{n^{1}h^{2}}{8mL^{2}}, n =1,2,3...$
113+
114+
where _m_ is the particle's mass and _h_ is Planck's constant, $h=6.626 \times 10^{-34} Js$.
115+
116+
Consider an electron with mass $9.11 \times 10^{-31}$ kg, trapped in a box size $10^{-11}$ m. I ts starts at the lowest energy-level, $E_{1}$ (not $E_{0}$), and jumps upwards, one step at a time, ending up at a much higher energy level, $E_{30}$. Each step from a level $E_{i}$ to a level $E_{i+1}$ will have required an energy.
117+
118+
$E_{i+1}-E_{i}=\frac{(i+1)^{2}-i^{2}h^{2}}{8mL^{2}}$
119+
120+
Write a for loop which calculates the energy required for each step along the way,and saves them in alist. Sum also up the total energy the particle has used on its way upwards.
121+
122+
![Trapped Quantum Particle](https://github.com/dindagustiayu/Aggregation-Indexing-Boleean-and-Reading-Data-into-Numpy-Array-for-Physics-problems./blob/master/Boleean-svg/Trapped%20Quantum%20Particle.svg).

0 commit comments

Comments
 (0)