You can write standard Python:
\begin{equation} \int_0^\infty f(x) dx \end{equation}from math import *
print(cos(pi))
print(pi)
2*pi
-1.0 3.141592653589793
6.283185307179586
import math
from scipy import *
from numpy import *
print(dir(math))
print( log2(10) )
print( math.log(10,2), math.log2(10) )
#info(log2)
['__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', 'acos', 'acosh', 'asin', 'asinh', 'atan', 'atan2', 'atanh', 'ceil', 'comb', 'copysign', 'cos', 'cosh', 'degrees', 'dist', 'e', 'erf', 'erfc', 'exp', 'expm1', 'fabs', 'factorial', 'floor', 'fmod', 'frexp', 'fsum', 'gamma', 'gcd', 'hypot', 'inf', 'isclose', 'isfinite', 'isinf', 'isnan', 'isqrt', 'ldexp', 'lgamma', 'log', 'log10', 'log1p', 'log2', 'modf', 'nan', 'perm', 'pi', 'pow', 'prod', 'radians', 'remainder', 'sin', 'sinh', 'sqrt', 'tan', 'tanh', 'tau', 'trunc'] 3.321928094887362 3.3219280948873626 3.321928094887362
Command Mode and Edit Mode
"Return" and "Esc" to switch between Command and Edit modes
To Execute : "Shift Return"
To return to Edit mode : "Return/double click"
hide long cell output double click
import requests
resp = requests.get("http://www.physics.rutgers.edu/grad/509/")
resp.content
b'<html>\n\n<head>\n<meta name="GENERATOR" content="Microsoft FrontPage 5.0">\n<meta name="ProgId" content="FrontPage.Editor.Document">\n<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">\n<meta http-equiv="Content-Language" content="en-us">\n<title>Computational Physics, Course 509 - Physics Applications of Computers</title>\n</head>\n\n<body>\n\n<div align="center">\n <center>\n <table border="0" cellpadding="0" cellspacing="8" width="98%">\n <tr>\n <td align="right" valign="top" width="20%"> </td>\n <td width="15"></td>\n <td valign="bottom"\n width="80%"><font size="5"><strong>Computational Physics 2023, Course 509 - Physics Applications of Computers</strong></font></td>\n </tr>\n\n <tr>\n\n <td valign="top" width="20%">\n <br>\n <font size="2">\n <p>\n <strong>Overview</strong><br>\n </p>\n <p>\n <strong><A href="Introductory.html">Introductory lecture material</A></strong><br>\n </p>\n <p>\n <strong><A href="program.html">Programming</A></strong><br>\n </p>\n <p>\n <strong>Basic numerical methods</strong><br>\n </p>\n <p>\n <strong>Methods and Algorithms</strong><br>\n <A href=MC.html>Monte Carlo methods</A><br>\n <A href=QMC.html>Quantum Monte Carlo methods</A><br>\n\t<A href=CTQMC.html> Continuous Time Quantum Monte Carlo</A><br>\n <A href="HartreeFock.html">Hartree-Fock method</A><br>\n <A href="DFT.html">Density functional theory</A><br>\n <A href="MolecularDynamics.html">Molecular Dynamics</A><br>\n </font>\n </p>\n <br><br>\n </td>\n <td width="15"></td>\n <td valign="top" width="80%"><font size="3">\n\n <img src="dla.gif"> <img src="md.gif">\n <br>\n <font size="1"><em><strong>\n Left: Simulation of a bacteria growth by DLA method, Right: Molecular dynamics simulation of a small system of atoms\n Simulation codes is available to download in lecture material.\n </strong></em></font><br>\n\n <p>\n This course introduces algorithmic concepts and familiarizes\n students with the basic computational tools which are essential\n for graduate students in computational physics, but are also very useful to most graduate students in STEM and related\n areas, as well as to those students who plan to look for a job in the IT industry.\n <br><br>\n In this course, students work toward mastering computational\n skills, and basic algorithms which appear in classical and quantum physics, but are not limited to those fields, for example\n large scale minimization problems, high dimensional integration problems, and solving partial differential equations are constituting the bulk of the course,\n but these same algorithms appear in all STEM fields and are also used by quants in major banks. While the examples are drawn mostly from quantum physics, \n their applicability is far beyond this specific physics subfield.\n <br><br>\n As the programing language, we will use mostly Python and\n its scientific library scipy & numpy.\n To speed up parts of the code, we will also\n use C++ (with pybind11) and fortran90 (f2py) for short examples, which will be used\n through the Python interface.\n <br><br>\n This course has no prerequisites except for familiarity with \n programming language. It is designed for the student who wishes to\n broaden his/her knowledge of applications and develop\n techniques.\n\n To complete the homework and perform the hands-on\n training, it is desired that students use their laptops and bring their own laptops to\n the class (when in person).\n</p>\n<br>\n <p><strong>Class Time: ARC 205 3:50pm-5:10pm Tuesday and Thursday</strong></p>\n <table border="0" align="left" width=100%>\n <tr>\n <td valign=top width=10%><strong>Instructor:</strong></td>\n <td align=LEFT>\n Kristjan Haule<br> \n Office: Serin E267<br> \n email: haule@physics.rutgers.edu<br> \n Phone: 445-3881<br>\n Office hours: after lecture<br>\n </td>\n </tr>\n </table>\n </p>\n <p> </p>\n \n <!--\n <p><A href="homeworks.html"><strong>Homeworks</strong></A></p>\n -->\n <!-- <p><A href="http://www.physics.rutgers.edu/~jishim/comphys.htm"><strong>Homeworks -- -- received</strong></A></p> -->\n <!--\n <p> </p>\n <p> <a href="https://sirs.ctaar.rutgers.edu/blue">Student\'s survey link </a>\n <br>\n <a href="https://sirs.ctaar.rutgers.edu/sirsBlueQR.html">QR code for survey</a>\n <br>\n <p>\n -->\n\tCodes available at <a href="https://github.com/haulek/CompPhysics">https://github.com/haulek/CompPhysics</a><br>\n\t<br>\n\tYoutube videos from 2021:\n\t<a href="https://www.youtube.com/watch?v=AXb_O_4JA7w&feature=youtu.be">Lecture 1</a>,\n\t<a href="https://www.youtube.com/watch?v=E9FEFywoveI">Lecture 2</a>,\n\t<a href="https://www.youtube.com/watch?v=QxNpCwUfb4A">Lecture 3</a>,\n\t<a href="https://www.youtube.com/watch?v=1jhsN-KYuSc">Lecture 4</a>,\n\t<a href="https://www.youtube.com/watch?v=H5tEe_UB-ZM">Lecture 5</a>,\n\t<a href="https://www.youtube.com/watch?v=nTdsJ0VDyEQ">Lecture 6</a>,\n\t<a href="https://www.youtube.com/watch?v=3Bf7zI0IKXU">Lecture 7</a>,\n\t<a href="https://www.youtube.com/watch?v=lDCDhwmdx4s">Lecture 8</a>,\n\t<a href="https://www.youtube.com/watch?v=GeGvMvttkn4">Lecture 9</a>,\n\t<a href="https://www.youtube.com/watch?v=eEIreA_UMPw">Lecture 10</a>,\n\t<a href="https://www.youtube.com/watch?v=1LhaEo2gY9E">Lecture 11</a>,\n\t<a href="https://www.youtube.com/watch?v=xoezDaVWRPM">Lecture 12</a>,\n\t<a href="https://www.youtube.com/watch?v=tpTXpUbl7jc">Lecture 13</a>,\n\t<a href="https://www.youtube.com/watch?v=L_s3Qgl_F6U">Lecture 14</a>,\n\t<a href="https://www.youtube.com/watch?v=HumK6HH1jGg">Lecture 15</a>,\n\t<a href="https://www.youtube.com/watch?v=UGgxYS0Rqks">Lecture 16</a>,\n\t<a href="https://www.youtube.com/watch?v=AsVMwaNeG2c">Lecture 17</a>,\n\t<a href="https://www.youtube.com/watch?v=3Sdy8WA9TFA">Lecture 18</a>,\n\t<a href="https://www.youtube.com/watch?v=1JsUFC4otlE">Lecture 19</a>,\n\t<a href="https://www.youtube.com/watch?v=M2oXbIOg108">Lecture 20</a>,\n\t<a href="https://www.youtube.com/watch?v=-rxSflHSPIk">Lecture 21</a>,\n\t<a href="https://www.youtube.com/watch?v=JEBXUjuffh4">Lecture 22</a>,\n\t<a href="https://www.youtube.com/watch?v=S7W6IOfXrqk">Lecture 23</a>,\n\t<a href="https://www.youtube.com/watch?v=emqK1krNCw8">Lecture 24</a>,\n\t<a href="https://www.youtube.com/watch?v=T3BpKvkH9Oo">Lecture 25</a>,\n\t<a href="https://www.youtube.com/watch?v=tVigsLbaH7c">Lecture 26</a>\n\t<br>\n\t<p>\n <strong>Preliminary Course Outline and Tentative List of Topics include</strong> <br><br>\n\n <strong>A) Introduction </strong>\n <p>\n <ol>\n <li><A href="Intro0.pdf">Installation, comparison of\n programing languages by computing Mandelbrot set, speed up the code with numba, f2py, pybind11, \n parallelization with openMP</A></li>\n <li><A href="Intro1.pdf">Numerical error accumulation, stable\n recursion and Miller\'s algorithm</A></li>\n </ol>\n </p>\n <p>\n Source code: <a href="https://github.com/haulek/CompPhysics/tree/main/Introductory"> https://github.com/haulek/CompPhysics </a>\n <br><br>\n Text for recursive Homework in <a href="Hmw2_Kn_recursion.pdf">pdf</a>\n <br><br>\n local copy of codes:\n <lo>\n <li><A href="src1/mandelbrot/">Plots of Mandelbrot set using fortran, C++, Perl and Python </A></li>\n <li><A href="src1/f2py_c2py/">Glues fortran and C++ to Python using f2py and pybind11 </A></li>\n <li><A href="src1/sbessel/">Computes Bessel functions with upward and downward recursion, shows the error.</A></li>\n </lo>\n <br>\n\t\n <strong>B) Learning high level programming with examples in Python(Numpy, SciPy, Pylab)</strong>\n <p>\n <ol>\n\t<li><A href="00_Introduction.html">00_Introduction (to Jupyter)</a></li>\n\t<li><A href="01_Basic_Python.html">01_Basic_Python </a></li>\n\t<li><A href="02_Numpy.html">02_Numpy </a></li>\n\t<li><A href="03_Scipy.html">03_Scipy</a></li>\n\t<li><A href="04_Scipy_example_Hydrogen_atom.html"> 04_Scipy_example_Hydrogen_atom</a></li>\n\t<li><A href="05_Atom_in_LDA.html"> 05_Atom_in_LDA </a></li>\n\tJupyter notebooks of these lectures can be downloaded at\n\t<A href="https://github.com/haulek/CompPhysics/tree/main/Programing">https://github.com/haulek/CompPhysics/tree/main/Programing</a><br>\n </ol>\n\n This lectures are adopted from <A href="https://github.com/jrjohansson/scientific-python-lectures">https://github.com/jrjohansson/scientific-python-lectures</a>\n\t\n </p>\n <p>\n Homeworks:<br>\n <A href=src_prog/python/homework5/atom1.pdf>Homework 3</A>,\n <!-- solution in <a href="src_prog/hmw/Hydrogen.html">Jupyter Notebook</a> form \n <br> -->\n <A href=numerov.pdf>Numerov algorithm</A>\n <br>\n <A href=src_prog/python/homework5/atom2.pdf>Homework 4</A>,\n <!-- solution in <a href="src_prog/hmw/Atom.html">Jupyter Notebook</a> form \n <br> -->\n   Script for XC potential: <A href=src_prog/python/homework5/excor.py>excor.py</A><br>\n <A href=http://physics.nist.gov/PhysRefData/DFTdata/Tables/ptable.html>Total energies from NIST</A> (Energies are given in Hartree\'s)<br>\n </p>\n\tMore literature on Learning Python:\n\t<lo>\n <li><A href="http://software-carpentry.org/">Software carpentry</a></li>\n\t <li><A href="http://greenteapress.com/thinkpython/thinkCSpy/">\n How to Think Like a Computer Scientist: Learning with Python</A></li>\n\t <li><A href="http://wiki.python.org/moin/BeginnersGuide">Python for beginners</A></li>\n\t <li><A href="http://docs.python.org/"> Python documentation</a></li>\n\t <li><A href="http://www.regular-expressions.info/python.html">Python regular expressions</a></li>\n\t</lo>\n\t<br>\n\n <strong>C) Monte Carlo and Simulated Annealing</strong>\n <ol>\n\t<li><A href="random.pdf">Random numbers, multidimensional Vegas integration</A>\n (<A href="src_numerics/Random/Vegas/Vegas_2021.html">source code in html</A>)</li> \n <li><A href="MC.pdf">Classical Monte Carlo, Simulated Annealing</A>\n (source code for <a href="src_MC1/Ising model.html">Ising model,</a>\n <a href="src_MC1/Wang Landau.html">Wang Landau,</a>\n <a href="src_MC1/Traveling Salesman.html">Traveling Salesman</a>)\n </li>\n <li><A href="MCI.html">High-Dimensional integration by Metropolis</A><br>\n\t<A href="Hmw_MCI.html"> Homework for high-D integration by Metropolis</A>\n </ol>\n <p>\n Alternative implementation of Ising: <a href="https://mattbierbaum.github.io/ising.js/">online Ising model simulation</a>\n </p>\n <lo>\n Source Codes:\n <li><A href="src_numerics/Random/Vegas/Vegas_2021.ipynb">jupyter nb for Vegas algorithm</A></li>\n <li> <A href="src_MC1/Ising model.ipynb">jupyter nb for Ising model</A></li>\n <li> <A href="src_MC1/Wang Landau.ipynb">jupyter nb for Wang Landau</A></li>\n <li> <A href="src_MC1/Traveling Salesman.ipynb">jupyter nb for The Traveling Salesman problem</A> </li>\n <li> <A href="src_MC1/highd_int.ipynb">jupyter nb for High-D integration by\n Metropolis</A>, <a href="src_MC1/mweight.py"> mweight.py</a>\n <a href="src_MC1/C_version.tgz">C version of High-D integration</a>\n </li>\n <li><A href="src_numerics/Random/dla2.py">Diffusion limited aggregation</a></li>\n <li> <A href="http://www.physics.rutgers.edu/~haule/681/src_MC/"> Other MC codes </A></li>\n </lo>\n \n <br>\n <strong>D) Machine Learning</strong>\n <ol>\n\t<li><A href="src_ML/Linear Regresion.html"> Linear regression</A>, <a href="src_ML/Linear Regresion.pdf">pdf</a> (<a href="src_ML/Linear Regresion.ipynb"> jupyter notebook</a>, <a href="src_ML/NucleousEnergy.dat">NucleousEnergy.dat</a>)</li>\n\t<li><A href="src_ML/Logistic regression.html"> Logistic regression</A>, <a href="src_ML/Logistic regression.pdf">pdf</a> (<a href="src_ML/Logistic regression.ipynb"> jupyter notebook</a>)</li>\n\t<li><A href="src_ML/Deep Learning.html"> Deep Learning</A>, <a href="src_ML/Deep Learning.pdf">pdf</a> (<a href="src_ML/Deep Learning.ipynb">jupyter notebook</a>,<a href="src_ML/NNfig.pdf">NNfig.pdf</a>,<a href="src_ML/or_xor.pdf">or_xor.pdf</a>,<a href="src_ML/NN_digits.pdf">NN_digits.pdf</a>)</li>\n </ol>\n <br>\n <strong>E) Parallel Programing</strong>\n <ol>\n <li><A href="parallel.pdf">Parallel programming with MPI</A>\t(<A href="src_MPI/"> source code</A>) </li>\n </ol>\n\n <strong>F) Basic numerical methods:</strong>\n\t<ol>\n\t <li><A href="integr.pdf">Numeric integration</A> (<A href="src_numerics/integration/">source code</A>) <!--<A href="homeworks/shomework7"> solution of homework 7</A>-->\n </li>\n <li><A href="interpol.pdf">Interpolation, Splines and Fourier transformation</A> (<A href="src_numerics/interpolation/">source code</A>)</li>\n\t <li><A href="ODE.pdf">Differential equations</A> (<A href="src_numerics/ODE/">source code</A>)</li>\n\t </ol>\n\t Literature:\n\t <A href="http://numerical.recipes/oldverswitcher.html">Numerical Recipes online</A>\n\t <br><br>\n\n\t \n <strong>G) More advanced topics in Computational Condensed Matter physics</strong>:\n\t <ol>\n <li><A href="HartreeFock.html">Hartree-Fock method</A></li>\n <li><A href="DFT.html">Density functional theory</A></li>\n <li><A href="QMC.html">Quantum Monte Carlo methods</A></li>\n <li><A href="CTQMC.html">Continuous Time Quantum Monte Carlo method</A></li>\n\t <li><A href="MolecularDynamics.html">Molecular dynamics simulation</A></li>\n\t </ol>\n\t Literature:\n\t <ol>\n\t <LI><A href="books0001.jpg">Computational Physics by J.M. Thijssen</A></LI>\n\t <li><A\n\t href="https://www.compadre.org/osp/items/detail.cfm?ID=7375">An introduction to Computer Simulation Methods by H. Gould, J Tobocnik and W. Christian</A></li>\n <li> <A href="books0002.jpg">Electronic Structure, Basic Theory and Practical Methods by Richard M. Martin</A>(Very good book for the Density functional part of the course)</li>\n <li> <A href="books0005.jpg">An Introduction to Computational Physics by Tao Pang</A></li>\n <li><A href="books0004.jpg">Computational Physics by Rubin H. Landau and Manuel J. Paez</A>(More elementary but good book)</li>\n\t </ol>\n\n\t <br>\n\n </p>\n <p><a href="http://www.physics.rutgers.edu/ugrad/disabilities.html">Students with Disabilities</A></p>\n \n <!-- <p><A href="igor/setupIgor5.exe">igor win</A></p> -->\n <!-- <p><A href="igor/Igor5Installer.bin">igor mac</A></p> -->\n <!-- <p><A href="igor/up.txt">up</A></p> -->\n <p> </p>\n </td>\n </td>\n </table>\n </center>\n</div>\n\n</body>\n\n</html>\n'
In a different type of cell, you can:
So you can add comments to your code explaining that, to calculate your cycling speed, you must make use of the fact that
$[x,p_x]=i \hbar$.
Toggling toolbars.
The different types of Return:
Choosing cell type:
Use ! to use shell comman right inside notebook
!ls -ltr
!pwd
total 37432 -rw-r--r--@ 1 haule staff 1756407 Dec 18 2020 Scientific-Computing-with-Python.pdf -rw-r--r--@ 1 haule staff 611082 Jan 20 2021 00_Introduction.html -rw-r--r--@ 1 haule staff 615891 Jan 20 2021 01_Basic_Python.html -rw-r--r--@ 1 haule staff 627779 Jan 20 2021 02_Numpy.html -rw-r--r--@ 1 haule staff 1303621 Mar 4 2021 03_Scipy.html -rw-r--r--@ 1 haule staff 1040661 Mar 4 2021 04_Scipy_example_Hydrogen_atom.html -rw-r--r-- 1 haule staff 47733 Jan 3 17:57 01_Basic_Python.ipynb -rw-r--r-- 1 haule staff 210051 Jan 3 17:57 02_Numpy.ipynb -rw-r--r-- 1 haule staff 826208 Jan 3 17:57 03_Scipy.ipynb -rw-r--r-- 1 haule staff 533268 Jan 3 17:57 04_Scipy_example_Hydrogen_atom.ipynb -rw-r--r-- 1 haule staff 4336264 Jan 3 17:57 ST_data.npy -rw-r--r-- 1 haule staff 3889864 Jan 3 17:57 StockholmT.dat -rw-r--r--@ 1 haule staff 430767 Jan 3 17:57 double_pendulum.mp4 -rw-r--r-- 1 haule staff 752 Jan 3 17:57 mymodule.py -rw-r--r-- 1 haule staff 2038 Jan 3 17:57 pendulum.py -rw-r--r-- 1 haule staff 2864984 Jan 3 17:57 stockholm_td_adj.dat.txt -rw-r--r-- 1 haule staff 264 Jan 3 17:57 ttt.cc -rw-r--r-- 1 haule staff 24310 Jan 6 16:02 00_Introduction.ipynb /Users/haule/Teaching/488/Programing
You can just send people the .ipynb files; they'll contain your input and (optionally) your output.
Other ways to view and run:
The running Python environment is determined by the kernel setting of your notebook and not, for example, by the virtualenv you happen to be in.
Here's where your shell environment will find python, pip etc:
!which python
/Users/haule/opt/anaconda3/bin/python
That's often the Python that's running the notebook server.
And here's the Python running this notebook, defined by the choice of kernel:
import sys
sys.executable
'/Users/haule/opt/anaconda3/bin/python'
Close and Halt