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.

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
Contribute¶
- Documentation: https://github.com/enzotonti/mathlab/tree/master/doc
- Issue Tracker: https://github.com/enzotonti/mathlab/issues
- Source Code: https://github.com/enzotonti/mathlab
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.
Contents:
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.differential
¶
Collection of differential equation tutorials
Functions:
function_05 (parameter_01, parameter_02, ...) |
Function description. |
function_06 (parameter_01, parameter_02, ...) |
Function 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_04
¶
Module for describing .....
Functions:
function_03 (parameter_01, parameter_02, ...) |
Function description. |
function_04 (parameter_01, parameter_02, ...) |
Function 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:
with:
equation of a line passing through P and orthogonal to A-B:
with:
and
instersection between the two line:
system of equation:
In [4]:
result = mathlab.point_line(0, 0, 100, 100, 70, 22)
projection point: 46.0 46.0
distance: -33.941125497

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

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)

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. |