{ "cells": [ { "cell_type": "markdown", "metadata": { "colab_type": "text", "id": "view-in-github" }, "source": [ "\"Open" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00001-c12d0284-fed1-4a1e-b372-857ff0548700", "deepnote_cell_type": "markdown", "id": "SzxkJX78nwR8" }, "source": [ "To open in Colab use the previous button or replace in the address bar:\n", "```\n", "github.com → colab.research.google.com/github\n", "```\n", "\n", "Computational Methods for Physics & Astronomy\n", "===================================\n", "\n", "## Book version:\n", "https://restrepo.github.io/ComputationalMethods/\n", "\n", "by: **Sebastian Bustamante** *2014/2015* **Diego Restrepo** 2017...\n", "\n", "![](https://raw.githubusercontent.com/sbustamante/ComputationalMethods/master/material/figures/Collage.png)\n", "\n", "This course is intended for students of Astronomy and Physics at the Universidad de Antioquia \n", "and will cover some numerical methods commonly used in science and specially in physics ans astronomy. These topics will be addressed from a formal context but also keeping \n", "a practical and computational approach, illustrating many useful applications in\n", "problems of physics and astronomy.\n", "\n", "\n", "The practical component will be almost entirely developed in *Python* and \n", "slightly less in *C* (when computational performance is required). \n", "However students with knowledge in other programming languages (except\n", "privative languages like MatLab, Mathematica) are also aimed to use them.\n", "\n", "\n", "In this repository it can be found all the related material of the course, \n", "including the detailed program, notes and presentations, examples (ipython \n", "notebooks) and homeworks. (This repository may be subject to changes continuously \n", "as the course advances).\n", "\n", "## Instructions to use the repository\n", "* Use the Colab button to open the reposotry in an executable enviroment\n", "* To save changes: \n", " 1. `File` → `Download .ipynb`\n", " 2. Open a repository in GitHub and Upload the file\n", " 3. To open again in Colab replace in the address bar: `github.com → colab.research.google.com/github` \n", "\n", "\n", "\n", "[**SYLLABUS**](https://github.com/sbustamante/ComputationalMethods/raw/master/syllabus/Programa_M%C3%A9todos_Computacionales.pdf):\n", "detailed description of the program of the course, including a brief motivation and presentation, \n", "topics to be covered, evaluation and bibliography." ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Contents\n", "Links to chapters\n", "\n", "```{tableofcontents}\n", "```" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Contents\n", "--------\n", "\n", "Links to notebooks:\n", "\n", "### 1. **Python** *(1 week)*\n", " \n", "**Topics**\n", "\n", "- [Git usage](./material/Syncing_fork.ipynb) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/Syncing_fork.ipynb)\n", "\n", "_Processing_\n", "\n", "- [Overview of python](./overview-python.ipynb) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/overview-python.ipynb) \n", "- [Implementation of scientific libraries](./material/scientific-libraries.ipynb)\n", "\n", "\n", "_Data analysis_\n", "\n", "- [Pandas](https://github.com/restrepo/ComputationalMethods/blob/master/material/Pandas.ipynb)\n", "\n", "_Visualization_\n", "\n", "- [Plotting with matplotlib](https://github.com/restrepo/ComputationalMethods/blob/master/material/matplotlib.ipynb)\n", "- [Ipython notebooks](https://github.com/restrepo/ComputationalMethods/blob/master/material/ipython-notebooks.ipynb)\n", "\n", "**Activities**\n", "- *Activity 01:* Solve the problems in the section [Exercises](https://github.com/restrepo/ComputationalMethods/blob/master/material/Basic_exercises.ipynb). \n", "\n", "### 2. **Mathematical Preliminaries** *(1 week)*\n", " \n", "**Topics**\n", "\n", "- [Computer arithmetics and round-off methods](https://github.com/restrepo/ComputationalMethods/blob/master/material/computer-arithmetics.ipynb)\n", "- [Algorithms and convergence](https://github.com/restrepo/ComputationalMethods/blob/master/material/algorithms-convergence.ipynb)\n", "- [Optimization](https://github.com/restrepo/ComputationalMethods/blob/master/material/numba.ipynb)\n", "\n", "### 3. **One Variable Equations** *(2 weeks)*\n", " \n", "./one-variable-equations.ipynb\n", "**Topics**\n", "- [Bisection method](https://github.com/restrepo/ComputationalMethods/blob/master/material/one-variable-equations.ipynb#Bisection-Method)\n", "- [Fixed-point iteration](https://github.com/restrepo/ComputationalMethods/blob/master/material/one-variable-equations-fixed-point.ipynb#Fixed-point-Iteration)\n", "- [Newton-Raphson method](https://github.com/restrepo/ComputationalMethods/blob/master/material/one-variable-equations-fixed-point.ipynb#Newton-Raphson-Method)\n", "- [Secant method](https://github.com/restrepo/ComputationalMethods/blob/master/material/one-variable-equations-fixed-point.ipynb#Secant-Method)\n", "\n", "\n", "### 4. **Interpolation Techniques** *(2 weeks)*\n", " \n", "**Topics**\n", "- [Linear interpolation](./material/interpolation.ipynb#Linear-Interpolation) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/interpolation.ipynb#Linear-Interpolation)\n", "- [Lagrange polynomials](./material/interpolation.ipynb#Lagrange-Polynomial) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/interpolation.ipynb#Lagrange-Polynomial)\n", "- [Divided differences](./material/interpolation_details.ipynb#Divided-Differences) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/interpolation_details.ipynb#Divided-Differences)\n", "- [Hermite interpolation](./material/interpolation_details.ipynb#Hermite-Interpolation) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/interpolation_details.ipynb#Hermite-Interpolation)\n", "- [Minimization](./material/Minimization.ipynb) [[View]](https://github.com/restrepo/ComputationalMethods/blob/master/material/Minimization.ipynb)\n", "\n", "### 5. **Numerical Calculus** *(2 weeks)*\n", " \n", "**Topics**\n", "- [Numerical differentiation](https://github.com/restrepo/ComputationalMethods/blob/master/material/numerical-calculus.ipynb#Numerical-Differentiation)\n", "- [Numerical integration](https://github.com/restrepo/ComputationalMethods/blob/master/material/numerical-calculus-integration.ipynb#Numerical-Integration)\n", "- [Composite numerical integration](https://github.com/restrepo/ComputationalMethods/blob/master/material/numerical-calculus-integration.ipynb#Composite-Numerical-Integration)\n", "- [Adaptive quadrature methods](https://github.com/restrepo/ComputationalMethods/blob/master/material/numerical-calculus-integration.ipynb#Adaptive-Quadrature-Methods)\n", "- [Improper integrals](https://github.com/restrepo/ComputationalMethods/blob/master/material/numerical-calculus-integration.ipynb#Improper-Integrals)\n", "\n", "**Activities**\n", "- *Activity:* [ Derivative exercise ](http://nbviewer.jupyter.org/github/sbustamante/ComputationalMethods/blob/master/activities/T-profile-bar.ipynb)\n", "\n", "### 6. **Linear Algebra** *(2 weeks)*\n", " \n", "**Topics**\n", "- [Gaussian elimination](https://github.com/restrepo/ComputationalMethods/blob/master/material/linear-algebra.ipynb#Gaussian-Elimination)\n", "- [Linear systems of equations](https://github.com/restrepo/ComputationalMethods/blob/master/material/linear-algebra.ipynb#Linear-Systems-of-Equations) [[Local](./material/linear-algebra.ipynb#Linear-Systems-of-Equation)]\n", "- [Pivoting strategies](https://github.com/restrepo/ComputationalMethods/blob/master/material/linear-algebra.ipynb#Pivoting-Strategies)\n", "- [Matrix inversion](https://github.com/restrepo/ComputationalMethods/blob/master/material/linear-algebra.ipynb#Matrix-Inversion)\n", "- [Determinant of a Matrix](https://github.com/restrepo/ComputationalMethods/blob/master/material/linear-algebra.ipynb#Determinant-of-a-Matrix)\n", "- [LU factorization](https://github.com/restrepo/ComputationalMethods/blob/master/material/linear-algebra.ipynb#LU-Factorization)\n", "\n", "### 7. **Differential Equations** *(2 weeks)*\n", " \n", "**Topics**\n", "- [First order methods](https://github.com/restrepo/ComputationalMethods/blob/master/material/differential-equations.ipynb#First-Order-Methods) [[Local](./differential-equations.ipynb#First-Order-Methods)]\n", "- [High order methods](https://github.com/restrepo/ComputationalMethods/blob/master/material/differential-equations.ipynb#High-Order-Methods)\n", "- [Two-Point boundary value problems](https://github.com/restrepo/ComputationalMethods/blob/master/material/differential-equations.ipynb#Two-Point-Boundary-Value-Problems)\n", "\n", "### 8. **Statistics** *(1 week)*\n", "\n", "**Topics**\n", "- [Data adjust](https://github.com/restrepo/ComputationalMethods/blob/master/material/statistics.ipynb)\n", "- [Random Numbers](https://github.com/restrepo/ComputationalMethods/blob/master/material/statistics.ipynb#Random-Numbers)\n", "\n", "### 9. **Extra material** *(1 session)*\n", "\n", "**Topics**\n", "- [Online IDE](https://repl.it/)\n", "- [Clases](https://github.com/restrepo/ComputationalMethods/blob/master/material/Intro_clases.ipynb)\n", "- [C++](https://github.com/restrepo/ComputationalMethods/blob/master/material/cpp.ipynb)" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00002-87c7e56d-60ac-451e-b60f-4c67354c134e", "deepnote_cell_type": "markdown", "id": "pK5LAKa9nwSE" }, "source": [ "## Bibliography\n", "[1a] Gonzalo Galiano Casas, Esperanza García Gonzalo [Numerical Computation](https://www.unioviedo.es/compnum/expositive/handbook/metnum.pdf) - [GD](https://drive.google.com/file/d/1gwHYLx5aBf3oXRhmGeG-n1toTtAUhvfX/view?usp=sharing) - [Web page with notebooks](https://www.unioviedo.es/compnum/index.php/english-menu)
\n", "[1b] [Scipy Lecture Notes](https://scipy-lectures.org/) [[PDF]](https://scipy-lectures.org/_downloads/ScipyLectures-simple.pdf)
\n", "[1b] [Jensen, Computational_Physics](https://drive.google.com/file/d/0BxoOXsn2EUNIekRUMFVPYXVsSTg/view?usp=sharing). [GitHub](https://github.com/mhjensen)
\n", "[1d] [Introduction to computational physics](http://astro.physics.ncsu.edu/urca/course_files)
\n", "[1e] Thomas J. Sargent John Stachurski, [Python Programming for Quantitative Economics](https://python-programming.quantecon.org) \n", "[GitHub](https://github.com/QuantEcon/lecture-python-programming.notebooks)
\n", "[1f] Ani Adhikari and John DeNero, [Computational and Inferential Thinking](https://www.inferentialthinking.com/chapters/intro.html)
\n", "[1g] Mo Mu, [MATH 3311: Introduction to Numerical Methods](https://www.math.ust.hk/~mamu/courses/230/course.htm) [GD](https://drive.google.com/drive/folders/1vv38SS7Zpw8mOHG7Kq_3lZr6o9H4xOYP?usp=sharing)
\n", "[1h] Zhiliang Xu, [ACMS 40390: Fall 2016 - Numerical Analysis](https://www3.nd.edu/~zxu2/ACMS40390-F16.html) [GD](https://drive.google.com/drive/folders/1Z9Fws1v34PuPdGAp_mBCWmTvZM_Qd6Xk?usp=sharing)
\n", "[1f] Computational Physiscs, University of Toronto [https://computation.physics.utoronto.ca/](https://computation.physics.utoronto.ca/)
\n", "[1g] Simon Sirca, Computational Methods for Physicists [GD](https://drive.google.com/file/d/1Yg19RBSe0ifGCn2J-9J5kiY990PL6h7i/view?usp=sharing)
\n", "[1h] Anthony Scopatz and Kathryn D. Huff, Effective Computation in Physics: Field Guide to Research with Python [PDF](http://lilith.fisica.ufmg.br/~dickman/transfers/comp/textos/Effective%20Computation%20in%20Physics%20(Python).pdf) [GD](https://drive.google.com/file/d/13822qJgXS5HbimBz5czM4gDHMg3p7d02/view?usp=sharing)
\n", "[1i] Tao Pang, An Introduction to Computational Physics [PDF](http://lilith.fisica.ufmg.br/~dickman/transfers/comp/textos/Pang%20-%20An%20introduction%20to%20computational%20physics%20(2ed.,%20CUP,%202006).pdf)
\n", "[1k] Raúl Ramos [Inteligencia Artificial para las Ciencias e Ingenierías](https://rramosp.github.io/ai4eng.v1)
\n", "[1l] Marijn Haverbeke [Eloquent JavaScript](https://eloquentjavascript.net/)
\n", "[1m] Diego Restrepo [Computadores en física](https://sites.google.com/site/computadoresenfisica/)
\n", "[2] [Landau Paez, A Survey of Computational Physics ](https://drive.google.com/file/d/0BxoOXsn2EUNIejJXVEVRUV9DclU/view?usp=sharing)
\n", "[3] [Kiusalaas, Numerical Methods in Engineering with Python](https://drive.google.com/file/d/0BxoOXsn2EUNIQUdFVkctR2xWRUk/view?usp=sharing)
\n", "[4] [Sørenssen Elementary Mechanics Using Python_ A Modern Course Combining Analytical and Numerical Techniques_](https://drive.google.com/file/d/0BxoOXsn2EUNIVHR4T1BKMEVDX2c/view?usp=sharing)
\n", "[5] [Langtangen_Python_Scripting_for_Computational_Science_3rd_edition](https://drive.google.com/file/d/0BxoOXsn2EUNIZTNsT2RYUTloZzQ/view?usp=sharing)
\n", "[6] [Python programming standards](http://docs.python-guide.org/en/latest/) Repository: https://github.com/kennethreitz/python-guide)
\n", "[7] [Lecture notes Course Numerical Analysis (MatLab)](http://pages.cs.wisc.edu/~amos/412/lecture-notes/)
\n", "[8] Jupyter+Python: [Python in Science](http://www.physics.nyu.edu/pine/pymanual/html/)
\n", "[9] Jupyter+Python: Python for Computational Science and Engineering [PDF](http://www.southampton.ac.uk/~fangohr/teaching/python/book/Python-for-Computational-Science-and-Engineering.pdf) [Notebooks](http://www.southampton.ac.uk/~fangohr/teaching/python/book/ipynb/)
\n", "[10] Jupyter+Python: [Scientific Computing and Simulation ](http://sam-dolan.staff.shef.ac.uk/mas212)
\n", "[11] E. Ayres, [Computational Physics With Python](http://bit.ly/CPwPython)
\n", "[12] Hans Petter Langtangen [A worked example on scientific computing with Python](https://hplgit.github.io/bumpy/doc/pub/bumpy.pdf)
\n", "[12] By Ani Adhikari and John DeNero [Computational and Inferential Thinking](https://www.inferentialthinking.com/)
\n", "[13] By Sam Lau, Joey Gonzalez, and Deb Nolan. DS100 Principles and Techniques of Data Science](https://www.textbook.ds100.org/)
\n", "[14] Software Design and Development: The Preliminary Course, – January 1, 2002, by Samuel Davis (Author) [[PDF]](https://drive.google.com/file/d/1mq6Mj15VqM62M1cA24WOk60-t1UsKYyE/view?usp=sharing)
\n", "[15] Bradley Voytek, _et al_, [Data Science in Practice](https://datascienceinpractice.github.io/)
\n", "[16] P. DeVries, A First Course in Computational Physics [PDF](http://lilith.fisica.ufmg.br/~dickman/transfers/comp/textos/DeVries_A_first_course_in_computational_physics.pdf)
" ] }, { "cell_type": "markdown", "metadata": {}, "source": [] }, { "cell_type": "markdown", "metadata": { "cell_id": "00003-f5283430-bd3a-47b1-a2ae-edbd1b87f2bc", "deepnote_cell_type": "markdown", "id": "LAcGVcJanwSJ" }, "source": [ "# Appendix\n", "General configuration modules. It is recommended to use the following _magic_ command to load all the plotting capabilities of python (also load `numpy as np`) and `display`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00004-8c0ffc23-9126-402f-808d-f4c6bfd52fce", "deepnote_cell_type": "code", "id": "bKyhbSJJnwSP", "outputId": "96d4b8c4-6fca-4423-cc28-adfdebb7c367" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Populating the interactive namespace from numpy and matplotlib\n" ] } ], "source": [ "%pylab inline" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00005-90c175b7-2f99-479a-81ea-b308ee6e7446", "deepnote_cell_type": "markdown", "id": "3iEG9zwRnwSh" }, "source": [ "Some times it is convenient to have advance display capabilities in the evaluation cells. It is possible with the module [`Ipython.display`](http://ipython.readthedocs.io/en/stable/api/generated/IPython.display.html). To have multiple special outputs in the same cell, it is necessary to use the `display` function loaded with `%pylab inline`" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00006-1814ace8-9675-4ee2-a329-f0d59c2d7705", "deepnote_cell_type": "code", "id": "QjgmVsHAnwSk" }, "outputs": [], "source": [ "from IPython.display import Math, Latex, HTML, JSON , Markdown, YouTubeVideo" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00007-b7123fdd-83f6-4742-9688-00be86d2ad1d", "deepnote_cell_type": "code", "id": "eVTjdC6DnwSt", "outputId": "595abc73-e995-482d-d349-6c13d4114925" }, "outputs": [ { "data": { "text/html": [ "

Hola mundo

" ], "text/plain": [ "" ] }, "execution_count": 13, "metadata": { "tags": [] }, "output_type": "execute_result" } ], "source": [ "HTML('

Hola mundo

')" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00008-ddd5ebcf-cf9a-425a-8000-95a44e394a96", "deepnote_cell_type": "code", "id": "g_a4kToTnwS3", "outputId": "a32e5672-923c-43f4-8335-0f1480c6b06d" }, "outputs": [ { "data": { "text/html": [ "

Hola mundo

" ], "text/plain": [ "" ] }, "metadata": { "tags": [] }, "output_type": "display_data" }, { "data": { "text/latex": [ "$$ \\int \\sin x\\, d x$$" ], "text/plain": [ "" ] }, "metadata": { "tags": [] }, "output_type": "display_data" }, { "name": "stdout", "output_type": "stream", "text": [ "multiple and mixed print with display(..)\n" ] } ], "source": [ "display( HTML('

Hola mundo

') ) \n", "display( Math(' \\int \\sin x\\, d x') )\n", "print('multiple and mixed print with display(..)')" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00009-a0e36473-69d8-4270-bf52-c000aadbadca", "deepnote_cell_type": "markdown", "id": "nvCus-IVnwTA" }, "source": [ "LaTeX is fully supported (see: https://stackoverflow.com/a/44375719/2268280)" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00010-af1199f2-8075-4766-897d-bd3db12dc7f0", "deepnote_cell_type": "markdown", "id": "S90GK-FonwTE" }, "source": [ "## Requirements\n", "* Modules installed with pip(3)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00011-4b516939-0a77-441f-a8dd-58741712dafc", "deepnote_cell_type": "code", "id": "e-UBnxIUnwTI", "outputId": "58d179b6-a98e-481a-ac3e-68868ce41d6a" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing requirements.txt\n" ] } ], "source": [ "%%writefile requirements.txt\n", "sympy\n", "ipywidgets" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00012-6d489714-bdc8-48af-949d-1ee9dbc674b1", "deepnote_cell_type": "code", "id": "Udp5S3RcnwTT", "outputId": "c211530c-17c6-41c8-881c-7af39a870710" }, "outputs": [ { "name": "stdout", "output_type": "stream", "text": [ "Writing postBuild\n" ] } ], "source": [ "%%writefile postBuild\n", "jupyter nbextension enable --py widgetsnbextension" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00013-3cdfe62c-4b93-4828-9c4b-ab1f346587bf", "deepnote_cell_type": "markdown", "id": "CV2qQwOxnwTf" }, "source": [ "* Special modules\n", "[HOWTO: Install JSAnimation for IPython Notebook](https://gist.github.com/gforsyth/188c32b6efe834337d8a)\n", "```bash\n", "git clone https://github.com/jakevdp/JSAnimation.git\n", "cd JSAnimation\n", "python3 setup.py install\n", "python setup.py install\n", "```" ] }, { "cell_type": "markdown", "metadata": { "cell_id": "00014-50ca4876-b65c-4960-a738-5a66291c949f", "deepnote_cell_type": "markdown", "id": "3raJelN8nwTh" }, "source": [ "# Recomended libraries for final projects\n", "* [Vpython-jupyter](https://github.com/BruceSherwood/vpython-jupyter) See [demo.ipynb](./demo.ipynb)\n", "* [bullet3](https://github.com/restrepo/bullet3)\n", "* [Pydstool](https://github.com/robclewley/pydstool)" ] }, { "cell_type": "code", "execution_count": null, "metadata": { "cell_id": "00015-4098ad05-4f75-487a-8c26-472dfc3322c5", "deepnote_cell_type": "code", "id": "9k2a0XihzzqQ" }, "outputs": [], "source": [] }, { "cell_type": "markdown", "metadata": { "created_in_deepnote_cell": true, "deepnote_cell_type": "markdown", "id": "B36-A6LkzzqQ", "tags": [] }, "source": [ "\n", "Created in deepnote.com \n", "Created in Deepnote" ] } ], "metadata": { "colab": { "include_colab_link": true, "name": "index.ipynb", "provenance": [] }, "deepnote": {}, "deepnote_execution_queue": [], "deepnote_notebook_id": "3f62b4a1-510c-4bdb-a330-5caa1d2a3f4e", "kernelspec": { "display_name": "Python 3 (ipykernel)", "language": "python", "name": "python3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.9.2" } }, "nbformat": 4, "nbformat_minor": 4 }