Math & Physics Lab

The professor Enzo Tonti’s Math & Physics Lab project aims to provide a series of small software programs implementing basic math and physics equations.

DMagic

prof. Enzo Tonti [A1] at the University of Trieste, Italy, pioneered in the early ‘80s the use of personal computers for scientific computing inspiring generation of future computational scientists.

We hope with this project to continue to inspire young student interests in math and physics and to become the next generation of computational scientists.

Features

  • Collection of software programs implementing basic math and physics equations

Content

About

This section describes what Math & Physics Lab project is about.

Install

This section covers the basics of how to download and install the Math & Physics Lab project.

Installing from source

Clone the Math & Physics Lab project from GitHub repository:

git clone https://github.com/enzotonti/mathlab.git mathlab

then:

cd mathlab
python setup.py install

API reference

project Modules:

mathlab.geometry

Collection of geometry tutorials

Functions:

point_line(xa, ya, xb, yb, xp, yp) Given a line r passing through two points A and B and assigned a point P, this function determines the projection of P on the line, evaluates its distance from the line and it indicates whether the projection is internal to the segment AB.
gravity_center(points) To do: complete documentation
electric_dipole(charge_location) To do: complete documentation
mathlab.geometry.point_line(xa, ya, xb, yb, xp, yp)[source]

Given a line r passing through two points A and B and assigned a point P, this function determines the projection of P on the line, evaluates its distance from the line and it indicates whether the projection is internal to the segment AB.

Parameters:xa, ya, xb, yb, xp, yp (float) – Coordinate (X, Y) of A, B and P.
Returns:distance – Distance between P and the line
mathlab.geometry.gravity_center(points)[source]

To do: complete documentation

Parameters:points – Coordinate ....
mathlab.geometry.electric_dipole(charge_location)[source]

To do: complete documentation

Parameters:charge_location – Coordinate ....

mathlab.differential

Collection of differential equation tutorials

Functions:

function_05(parameter_01, parameter_02, ...) Function description.
function_06(parameter_01, parameter_02, ...) Function description.
mathlab.differential.function_05(parameter_01, parameter_02, parameter_03)[source]

Function description.

Parameters:
  • parameter_01 (type) – Description.
  • parameter_02 (type) – Description.
  • parameter_03 (type) – Description.
Returns:

return_01 – Description.

mathlab.differential.function_06(parameter_01, parameter_02, parameter_03)[source]

Function description.

Parameters:
  • parameter_01 (type) – Description.
  • parameter_02 (type) – Description.
  • parameter_03 (type) – Description.
Returns:

return_01 – Description.

mathlab.module_03

Module for describing .....

Functions:

function_01(parameter_01, parameter_02, ...) Function description.
function_02(parameter_01, parameter_02, ...) Function description.
mathlab.module_03.function_01(parameter_01, parameter_02, parameter_03)[source]

Function description.

Parameters:
  • parameter_01 (type) – Description.
  • parameter_02 (type) – Description.
  • parameter_03 (type) – Description.
Returns:

return_01 – Description.

mathlab.module_03.function_02(parameter_01, parameter_02, parameter_03)[source]

Function description.

Parameters:
  • parameter_01 (type) – Description.
  • parameter_02 (type) – Description.
  • parameter_03 (type) – Description.
Returns:

return_01 – Description.

mathlab.module_04

Module for describing .....

Functions:

function_03(parameter_01, parameter_02, ...) Function description.
function_04(parameter_01, parameter_02, ...) Function description.
mathlab.module_04.function_03(parameter_01, parameter_02, parameter_03)[source]

Function description.

Parameters:
  • parameter_01 (type) – Description.
  • parameter_02 (type) – Description.
  • parameter_03 (type) – Description.
Returns:

return_01 – Description.

mathlab.module_04.function_04(parameter_01, parameter_02, parameter_03)[source]

Function description.

Parameters:
  • parameter_01 (type) – Description.
  • parameter_02 (type) – Description.
  • parameter_03 (type) – Description.
Returns:

return_01 – Description.

Examples

We provide Jupyter Notebooks for all the Math & Physics Lab functions.

To run these examples on your computer install and run Jupyter Notebook

Distance between a point and a line

Given a line r passing through two points A and B and assigned a point P, this function determines the projection of P on the line, evaluates its distance from the line and it indicates whether the projection is internal to the segment AB.

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
import mathlab

importing the Math and Physics Lab project

equation describing a line between two points A-B:

\[x = x_{\mathrm{A}} + s * (x_{\mathrm{B}} - x_{\mathrm{A}})\]
\[y = y_{\mathrm{A}} + s * (y_{\mathrm{B}} - y_{\mathrm{A}})\]

with:

\[0 \leq s \leq 1\]

equation of a line passing through P and orthogonal to A-B:

\[x = x_{\mathrm{P}} + t * sin(\alpha)\]
\[y = y_{\mathrm{P}} + t * cos(\alpha)\]

with:

\[sin(\alpha) = (y_{\mathrm{B}} - y_{\mathrm{A}})/L\]
\[cos(\alpha) = (x_{\mathrm{B}} - x_{\mathrm{A}})/L\]

and

\[L = \sqrt{(x_{\mathrm{B}} - x_{\mathrm{A}})^2 + (y_{\mathrm{B}} - y_{\mathrm{A}})^2 }\]

instersection between the two line:

\[x_{\mathrm{A}} + s * (x_{\mathrm{B}} - x_{\mathrm{A}}) = x_{\mathrm{P}} + t * sin(\alpha)\]
\[y_{\mathrm{A}} + s * (y_{\mathrm{B}} - y_{\mathrm{A}}) = y_{\mathrm{P}} - t * cos(\alpha)\]

system of equation:

\[s * (x_{\mathrm{B}} - x_{\mathrm{A}}) - t * sin(\alpha) = x_{\mathrm{P}} - x_{\mathrm{A}}\]
\[s * (y_{\mathrm{B}} - y_{\mathrm{A}}) + t * cos(\alpha) = y_{\mathrm{P}} - y_{\mathrm{A}}\]
\[x_{\mathrm{A}} = 0; y_{\mathrm{A}} = 0; x_{\mathrm{B}} = 100; y_{\mathrm{B}} = 110; x_{\mathrm{P}} = 70; y_{\mathrm{P}} = 22\]
In [4]:
result = mathlab.point_line(0, 0, 100, 100, 70, 22)
projection point:  46.0 46.0
distance:  -33.941125497
_images/source_ipynb_point_line_5_1.png
In [ ]:

Center of Gravity

Given n points defining a polygon it calculates the center of mass.

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
import mathlab

importing the Math and Physics Lab project

To Do: write equations/comments/

In [3]:
points = [[0,0], [8,1], [3,3], [1,8], [0,0]]
mathlab.gravity_center(points)
x[] [0, 8, 3, 1, 0]
y[] [0, 1, 3, 8, 0]
area[]: [0.0, 10.5, 10.5, 0.0]
total area:  21.0
_images/source_ipynb_gravity_center_5_1.png
In [ ]:

Electric Dipole

To complete.

In [1]:
%pylab inline
Populating the interactive namespace from numpy and matplotlib
In [2]:
import mathlab

importing the Math and Physics Lab project

To Do: write equations/comments/

In [4]:
charge_location = [[-2.0, 1.0], [2.0, 0]]
mathlab.electric_dipole(charge_location)
_images/source_ipynb_electric_dipole_5_0.png
In [ ]:

Credits

Citations

We kindly request that you cite the following article [A1] if you use the Math & Physics Lab project.

[A1]Enzo Tonti. Why starting from differential equations for computational physics? Journal of Computational Physics, 257, Part B():1260 – 1290, 2014. Physics-compatible numerical methods. URL: http://www.sciencedirect.com/science/article/pii/S0021999113005548, doi:http://dx.doi.org/10.1016/j.jcp.2013.08.016.

References

[B1]Enzo Tonti. Why starting from differential equations for computational physics? Journal of Computational Physics, 257, Part B():1260 – 1290, 2014. Physics-compatible numerical methods. URL: http://www.sciencedirect.com/science/article/pii/S0021999113005548, doi:http://dx.doi.org/10.1016/j.jcp.2013.08.016.