# <a id="sec-top"></a>easyPhysi
easyPhysi is a physics library to solve pre-university physics problems. The physics areas that are covered by easyPhysi are summarized hereafter. See the main structure to use easyPhysi in [Section](#sec-main-structure) and also some [Examples](#sec-examples).
- Kinematics
- Dynamics
- Energy conservation
- Gravitational field
- Electrical field
> [!Note]
> Visit GitHub page at https://github.com/girdeux31/easyPhysi
The main characteristics for easyPhysi are summarized in the following table.
<a id="tab-characteristics"></a>
| Characteristic | Value |
|------------------|---------------|
| Name | easyPhysi |
| Version | 1.0.1 |
| Author | Carles Mesado |
| Date | 22/12/2023 |
| Size | ~ 40 KiB |
> [!NOTE]
> Notes are use through this document to remark some features.
> [!TIP]
> Tips are use through this document to link relevant examples or show their solution.
## <a id="sec-index"></a>0. Index
0. [Index](#sec-index)
1. [Installation](#sec-installation)
2. [Usage](#sec-usage)
- [Main structure](#sec-main-structure)
- [Properties](#sec-properties)
- [Special bodies](#sec-special-bodies)
- [Equations](#sec-equations)
- [Advance features](#sec-advance-features)
3. [Examples](#sec-examples)
- [Kinematics](#sec-example-kinematics)
- [Dynamics](#sec-example-dynamics)
- [Energy conservation](#sec-example-energy-conservation)
- [Gravitational field](#sec-example-gravitational-field)
- [Electrical field](#sec-example-electrical-field)
4. [Limitations and bugs](#sec-limitations-bugs)
- [Limitations](#sec-limitations)
- [Bugs](#sec-bugs)
5. [Changelog](#sec-changelog)
6. [License](#sec-licence)
7. [Contact](#sec-contact)
## <a id="sec-installation"></a>1. Installation
> [!NOTE]
> easyPhysi is developed and tested with Python 3.10.
Install the package with pip,
`pip install easyphysi`
or clone the GitHub repository.
`gh repo clone girdeux31/easyPhysi`
The following third-party modules are requirements.
- matplotlib>=3.7.0
- scipy>=1.11.0
- sympy==1.12
## <a id="sec-usage"></a>2. Usage
### <a id="sec-main-structure"></a>2.0. Main structure
Most pre-university physics problems can be solved following this structure composed of a few lines.
```
from easyphysi.drivers.universe import Universe
from easyphysi.drivers.body import Body
universe = Universe(dimensions=2) # 2 o 3 dimensions, default is 2
universe.set('my_prop', value)
body = Body('my_body', dimensions=2) # 2 o 3 dimensions, default is 2
body.set('my_prop', value)
# define more properties or more bodies as needed
universe.add_body(body)
# add more bodies as needed
solution = universe.physics_equation('my_body').solve('my_unknown')
```
Let's take the code apart line by line.
- Line 1 and 2: import `Universe` and `Body` classes, these are needed in every single problem solved with easyPhysi.
- Line 4: define a universe instance with `Universe` class. The `dimensions` is an optional argument, but only 2 o 3 dimensions are allowed, default is 2.
- Line 5: define as many properties for the universe as needed. Universe properties are listed in [Table](#tab-universe-properties), name and value must be included as arguments. Values must be consistent with property type, see [Section](#sec-property-types).
- Line 7: define as many body instances as needed with `Body` class provided that they have different names. Its name must be included as first argument, the `dimensions` is an optional argument, but only 2 o 3 dimensions are allowed, default is 2.
- Line 8: define as many properties for the body as needed. Body properties are listed in [Table](#tab-body-properties), name and value must be included as arguments. Values must be consistent with property type, see [Section](#sec-property-types).
- Line 12: add all defined bodies to the universe (body and universe dimensions must match).
- Line 16: solve the relevant physics equation over a specific body and define the unknown(s). See a list of allowed equations and unknowns in [Table](#tab-equations).
> [!NOTE]
> Define all bodies and properties before solving any equation.
> [!TIP]
> [Example](#sec-example-ef2) defines a 3D problem.
### <a id="sec-properties"></a>2.1. Properties
Some properties are defined on a body, while others are defined on a universe. Next [Table](#tab-body-properties) lists all properties that are allowed to be defined on a body.
> [!NOTE]
> Property names are case sensitive.
<a id="tab-body-properties"></a>
|Property |Description |Type |Components |
|---------|--------------------------------|----------|---------------------|
|a |Acceleration |Vector |(a_x, a_y[, a_z]) |
|q |Charge |Scalar |q |
|Fe |Electrical force |Vector |(Fe_x, Fe_y[, Fe_z]) |
|Ue |Electrical potential energy |Scalar |Ue |
|Fg |Gravitational force |Vector |(Fg_x, Fg_y[, Fg_z]) |
|Ug |Gravitational potential energy |Scalar |Ug |
|p0 |Initial position |Vector |(p0_x, p0_y[, p0_z]) |
|v0 |Initial velocity |Vector |(v0_x, v0_y[, v0_z]) |
|m |Mass |Scalar |m |
|p |Position |Vector |(p_x, p_y[, p_z]) |
|v |Velocity |Vector |(v_x, v_y[, v_z]) |
Next [Table](#tab-universe-properties) lists all properties that are allowed to be defined in a universe.
<a id="tab-universe-properties"></a>
|Property |Description |Type |Value |
|---------|--------------------------------|----------|---------------------|
|Ee |Electrical field intensity |Vector |(Ee_x, Ee_y[, Ee_z]) |
|Ve |Electrical potential |Scalar |Ve |
|gg |Gravitational field intensity |Vector |(gg_x, gg_y[, gg_z]) |
|Vg |Gravitational potential |Scalar |Vg |
|g |Gravity |Vector |(g_x, g_y[, g_z]) |
|t |Time |Scalar |t |
Use `set` method in an instanciated body or universe to define its property and define its value according to its type, see [Section](#sec-property-types).
> [!NOTE]
> Units are up to the user. Even though SI is recommended, other systems can be used provided that different units are consistent.
> [!NOTE]
> Force and energy cannot be defined as properties since each force and energy is defined by its own algebraic formula, see [Section](#sec-property-nondefined).
#### <a id="sec-property-types"></a>2.1.0. Property types
There are two types of properties: **scalars** (for example `m` for mass) and **vectors** (for example `g` for gravity).
##### <a id="sec-property-type-scalar"></a>2.1.0.i Scalars
They are integers of floats, examples follow.
```
body.set('prop', 250) # int
body.set('prop', 5.0E-9) # float
```
##### <a id="sec-property-type-vectors"></a>2.1.0.ii Vectors
They are list or tuples (either integers or floats), examples follow.
```
body.set('prop', [0.0, -9.81]) # list
body.set('prop', (0, +3)) # tuple
```
The length of `value` (components) must be the same as defined in the instance of the body or universe the property applies to.
> [!NOTE]
> It is also possible to define only one component in a vector parameter (the other may be irrelevant or unknown). To do so, append `_x`, `_y` or `_z` to the property name according to the desired axis.
```
body.set('prop_x', value_x)
body.set('prop_y', value_y)
body.set('prop_z', value_z)
```
#### <a id="sec-property-nondefined"></a>2.1.1. Non-defined properties
Force (mainly used in `newton_equation`) and energy (mainly used in `energy_conservation_equation`) cannot be defined as properties in an instanciated body (note that they are not listed in [Table](#tab-equations)). Instead they can be defined in with `add_force` and `add_energy` methods over any instanciated body.
```
body.add_force('my_force', value)
body.add_energy('my_energy', value)
```
This is designed on purpose because many different forces and energies can apply to a body and could have different algebraic expressions. Thus, the algebraic expression for the force and energy must be defined by the user.
> [!TIP]
> [Section](#sec-example-dynamics) shows examples using `newton_equation` and `add_force` method.
> [!TIP]
> [Section](#sec-example-energy-conservation) shows examples using `energy_conservation_equation` and `add_energy` method.
### <a id="sec-special-bodies"></a>2.2. Special bodies
Special bodies are pre-defined bodies that are ready to be used. There are two types of special bodies: subatomic particles and celestial bodies, see following tables. The mass and charge of subatomic particles are defined in kilograms and coulombs.
<a id="tab-body-particles"></a>
| Body | Mass (kg) | Charge (C) |
|----------|-----------|------------|
| electron | 9.109e-31 | -1.602e-19 |
| proton | 1.673e-27 | 1.602e-19 |
| neutron | 1.675e-27 | 0.0 |
The mass and position of celestial bodies are defined in kilograms and kilometers.
> [!NOTE]
> The distance of celestial bodies is the average distance to the Sun (except for the Moon, which is the average distance to the Earth) and is defined in the x-axis.
<a id="tab-body-celestial"></a>
| Body | Mass (kg) | Position (km) |
|----------|-----------|---------------|
| sun | 1.988e30 | 0.0 |
| mercury | 3.301e23 | 57900000 |
| venus | 4.867e24 | 108200000 |
| earth | 5.972e24 | 149600000 |
| moon | 7.348e22 | 384400 |
| mars | 6.417e23 | 227900000 |
| jupiter | 1.899e27 | 778600000 |
| saturn | 5.685e26 | 1433500000 |
| uranus | 8.682e25 | 2872500000 |
| neptune | 1.024e26 | 4495100000 |
Import them using the following line and use them without instanciating the body or defining its main properties.
`from easyphysi.drivers.body import special_body`
> [!TIP]
> [Example](#sec-example-ef1) imports an electron from special bodies.
### <a id="sec-equations"></a>2.3. Equations
The following equations can be solved, each one is a method defined in the `Universe` class.
> [!NOTE]
> Equation names are case sensitive.
<a id="tab-equations"></a>
|Equation |Type |Unknowns |
|----------------------------------------|----------|--------------- |
|electrical_field_intensity_equation |Vectorial |Ee, p, q |
|electrical_force_equation |Vectorial |Fe, p, q |
|electrical_potential_energy_equation |Scalar |Ue, p, q |
|electrical_potential_equation |Scalar |Ve, p, q |
|energy_conservation_equation |Scalar |- |
|gravitational_field_intensity_equation |Vectorial |gg, m, p |
|gravitational_force_equation |Vectorial |Fg, m, p |
|gravitational_potential_energy_equation |Scalar |Ug, m, p |
|gravitational_potential_equation |Scalar |Vg, m, p |
|linear_position_equation |Vectorial |g, p, p0, t, v0 |
|linear_velocity_equation |Vectorial |g, t, v, v0 |
|newton_equation |Vectorial |a, m |
Use any of these equation in an instance of universe and include the body the equation applies to. Then use the `solve` method and include the unknown(s) to be solved, see third column in [Table](#tab-equation).
`universe.physics_equation('my_body').solve('my_unknown')`
#### <a id="sec-equation-types"></a>2.3.0. Equation types
There are two types of equations: scalar (for example `energy_conservation_equation`) and vectorial (for example `newton_equation`).
##### <a id="sec-equation-type-scalar"></a>2.3.0.i Scalar
Only one unknown is accepted.
```
out = universe.physics_equation('my_body').solve('my_unk')
```
> [!NOTE]
> The output is always a list of roots.
##### <a id="sec-equation-type-vectorial"></a>2.3.0.ii Vectorial
As many unknowns as universe dimensions are accepted, these must be defined in a list and passed as argument of `solve` method. Vector components must be append to unknown names, such as `a_x`, `a_y` and `a_z` for acceleration, see [Section](#sec-property-type-vectors). The same number of unknowns must be defined as outputs, no name restriction apply for output unknowns.
```
out_x, out_y = universe.physics_equation('my_body').solve(['unk_x', 'unk_y'])
```
> [!NOTE]
> The output always has as many list of roots as unknowns.
### <a id="sec-advance-features"></a>2.4. Advance features
The most useful features are already defined. However, for the sake of completeness, a few more features for the advance user are defined in this section.
#### <a id="sec-other-feature-magnitude"></a>2.4.0. Vector module
Function `magnitude` is available to obtain a vector module or magnitude.
```
from easyphysi.utils import magnitude
prop = magnitude((prop_x, prop_y))
```
> [!TIP]
> [Example](#sec-example-k0) makes use of `magnitude` function to calculate the modulo of the velocity.
#### <a id="sec-other-feature-symbol"></a>2.4.1. Define new unknowns
Most unknowns are already defined when a universe or body are instanciated, see [Table](#tab-universe-properties) and [Table](#tab-body-properties). However, sometimes new unknowns must be defined, specially with `newton_equation` and `energy_conservation_equation` since force and energy algebraic expressions are defined by user, see [Section](#sec-property-nondefined). In these case, `Symbol` class from Sympy library can be used. Then, the new unknown can be used as argument in `solve` method to calculate its numerical value.
```
from sympy import Symbol
my_unknown = Symbol('my_unknown')
```
> [!TIP]
> [Example](#sec-example-ec0) makes uso of `Symbol` class to define the final velocity (`vf`) as an unknown and then solve its value.
#### <a id="sec-other-feature-subs"></a>2.4.2. Substitute variable
Method `solve` returns numerical values if there is only one unknown (all properties are defined but one), but returns expressions if there is more than one unknown (two or more properties are left undefined). Use `subs` method to replace an unknown by a specified numerical value.
```
foo = universe.physics_equation('body').solve('my_unk') # several undefined properties
out = foo.subs('my_sym', value)
```
> [!Note]
> There is no need to import `subs` since it is a method inherent in any Sympy expression.
> [!TIP]
> [Example](#sec-example-d0) makes uso of `subs` method to substitute the friction coefficient by its value.
#### <a id="sec-other-feature-get-equation"></a>2.4.3. Get equation from system
In some cases, it is only interesting to solve a specific equation from a vectorial equation (that is a set of equations or a system). The method `get_equation` can be used over any vectorial equation to return the specific equation, the axis component is expected as method argument.
`universe.physics_equation('my_body').get_equation('axis')`
> [!TIP]
> [Example](#sec-example-k0) makes use of `get_equation` method to extract an equation from a vectorial equation (or set of equations) and, then, solve its unknown.
#### <a id="sec-other-feature-solve-systems"></a>2.4.4. Solving system of equations
System of equations can be defined -with `System` class- and solved with `solve` method. The `solve` method accepts a list with as many unknowns as equations defined in the system.
```
from easyphysi.drivers.system import System
equation = universe.physics_equation('body').solve('my_unk')
system = System()
system.add_equation(equation)
# define and add as many equations as needed
x, y, z = system.solve(['x', 'y', 'z'])
```
> [!TIP]
> [Example](#sec-example-d2) makes use of `System` class to solve a set of equations.
#### <a id="sec-other-feature-plot"></a>2.4.5. Plotting equations
Method `plot` can be used over any equation -scalar or vectorial- to plot unknowns in the form of function `independent = f(dependent)`.
`universe.physics_equation('my_body').plot(independent, dependent, x_range, points=100, path=None, show=True)`
Arguments are described hereafter.
- `independent`: if equation is [scalar](#sec-equation-type-scalar), then only one independent unknown is expected. If equation is [vectorial](#sec-equation-type-vectorial), then a list with length equal to the number of components (or universe dimensions) is expected.
- `dependent`: exactly one unknown is expected.
- `x_range`: range to plot for dependent unknown (x-axis).
- `points`: number of points to plot, optional argument, default is 100.
- `path`: path to save image as file, optional argument, by default it is None and no image is saved.
- `show`: if `True` the plot is shown on screen, optional argument, by default it is `True`.
> [!TIP]
> [Example](#sec-example-ec1) makes uso of `plot` method to plot a scalar equation (final velocity as a function of initial velocity).
## <a id="sec-examples"></a>3. Examples
### <a id="sec-example-kinematics"></a>3.0. Kinematics
#### <a id="sec-example-k0"></a>3.0.0. Example K-0
[Problem 10](https://fq.iespm.es/documentos/janavarro/fisica2bach/T0_vectores_cinematica.pdf)
A ball falls from a roof located 10 m high, forming a 30º angle with the horizontal, with a speed of 2 m/s. Calculate:
a) At what distance from the wall does it hit the ground?
b) The speed it has when it reaches the ground (disregard air friction).
```
import math
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.utils import magnitude
alpha = math.radians(-30)
g = (0.0, -9.81)
p0 = (0.0, 10.0)
v0 = (2.0*math.cos(alpha), 2.0*math.sin(alpha))
py = 0.0
body = Body('body') # by default 2D
body.set('p0', p0)
body.set('v0', v0)
body.set('p_y', py)
universe = Universe() # by default 2D
universe.set('g', g)
universe.add_body(body)
t = universe.linear_position_equation('body').get_equation('y').solve('t')
universe.set('t', t[1])
p_x = universe.linear_position_equation('body').get_equation('x').solve('p_x')
v_x[0], v_y[0] = universe.linear_velocity_equation('body').solve(['v_x', 'v_y'])
v = magnitude((v_x[0], v_y[0]))
```
> [!TIP]
> **Solution:** `p_x[0] = 2.30 m, v = 14.15 m/s`
### <a id="sec-example-dynamics"></a>3.1. Dynamics
#### <a id="sec-example-d0"></a>3.1.0. Example D-0
[Problem 14](https://fq.iespm.es/documentos/rafael_artacho/4_ESO/08.%20Problemas%20Las%20fuerzas.pdf)
The following ramp has an inclination of 25º. Determine the force that must be exerted on the 250 kg wagon to make it go up with constant velocity:
a) If there is no friction.
b) If 𝜇 = 0.1.
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.drivers.system import System
mu = Symbol('mu')
alpha = math.radians(25)
m = 250
g = 9.81
W = (-m*g*math.sin(alpha), -m*g*math.cos(alpha))
N = (0.0, m*g*math.sin(alpha))
Fr = (-mu*m*g*math.cos(alpha), 0.0)
body = Body('body')
body.set('m', m)
body.add_force('W', W)
body.add_force('Fr', Fr)
body.add_force('N', N)
universe = Universe()
universe.add_body(body)
a_x[0], a_y[0] = universe.newton_equation('body').solve(['a_x', 'a_y'])
f_00 = m*a_x[0].subs('mu', 0.0)
f_01 = m*a_x[0].subs('mu', 0.1)
```
> [!TIP]
> **Solution:** `f_00 = -1036.47 N, f_01 = -1258.74 N`
#### <a id="sec-example-d1"></a>3.1.1. Example D-1
Following previous example, calculate the angle if the acceleration is known.
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.drivers.system import System
mu = 0.1
sin_alpha = Symbol('sin_alpha')
cos_alpha = Symbol('cos_alpha')
m = 250
g = 9.81
a = (-5.03497308675920, -4.74499424315328) # from previous example
W = (-m*g*sin_alpha, -m*g*cos_alpha)
N = (0.0, m*g*sin_alpha)
Fr = (-mu*m*g*cos_alpha, 0.0)
body = Body('body')
body.set('m', m)
body.set('a', a)
body.add_force('W', W)
body.add_force('Fr', Fr)
body.add_force('N', N)
universe = Universe()
universe.add_body(body)
sin_alpha, cos_alpha = universe.newton_equation('body').solve(['sin_alpha', 'cos_alpha'])
alpha_from_sin = math.degrees(math.asin(sin_alpha[0]))
alpha_from_cos = math.degrees(math.acos(cos_alpha[0]))
```
> [!TIP]
> **Solution:** `alpha_from_sin = 25º, alpha_from_cos = 25º`
#### <a id="sec-example-d2"></a>3.1.2. Example D-2
In the system shown in the figure, the three masses are mA = 1 kg, mB = 2 kg, and mC = 1.5 kg. If the coefficient of friction is 𝜇 = 0.223, calculate the acceleration of the system when it is released.
![System of three masses](https://github.com/girdeux31/easyPhysi/blob/main/tests/ref/system_dynamics.png?raw=true)
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.drivers.system import System
g = 9.81
mu = 0.223
alpha = math.radians(30)
ma, mb, mc = 1, 2, 1.5
Fra = (-mu*ma*g*math.cos(alpha), 0.0)
Frb = (-mu*mb*g, 0.0)
Wa = (-ma*g*math.sin(alpha), -ma*g*math.cos(alpha))
Wc = (mc*g, 0.0)
Tab = (Symbol('T2'), 0.0)
Tba = (-Symbol('T2'), 0.0)
Tbc = (Symbol('T1'), 0.0)
Tcb = (-Symbol('T1'), 0.0)
body_a = Body('A')
body_a.set('m', ma)
body_a.add_force('T2', Tab)
body_a.add_force('Fra', Fra)
body_a.add_force('Wa', Wa)
body_b = Body('B')
body_b.set('m', mb)
body_b.add_force('T1', Tbc)
body_b.add_force('T2', Tba)
body_b.add_force('Frb', Frb)
body_c = Body('C')
body_c.set('m', mc)
body_c.add_force('Wc', Wc)
body_c.add_force('T1', Tcb)
universe = Universe()
universe.add_body(body_a)
universe.add_body(body_b)
universe.add_body(body_c)
eq_a = universe.newton_equation('A').get_equation('x')
eq_b = universe.newton_equation('B').get_equation('x')
eq_c = universe.newton_equation('C').get_equation('x')
unknowns = ['T1', 'T2', 'a_x']
system = System()
system.add_equation(eq_a)
system.add_equation(eq_b)
system.add_equation(eq_c)
T1, T2, a_x = system.solve(unknowns)
```
> [!TIP]
> **Solution:** `T1[0] = 13.54 N, T2[0] = 7.59 N, a_x[0] = 0.79 m/s2`
#### <a id="sec-example-d3"></a>3.1.3. Example D-3
In the system shown in the figure, the three masses are mA = 1 kg, mB = 2 kg, and mC = 1.5 kg. If the coefficient of friction is 𝜇 = 0.223, calculate the acceleration of the system when it is released.
![System of three masses](https://github.com/girdeux31/easyPhysi/blob/main/tests/ref/system_dynamics.png?raw=true)
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.drivers.system import System
from easyphysi.utils import magnitude
g = 9.81
mu = 0.223
alpha = math.radians(30)
ma = 1
mb = 2
mc = 1.5
Fra = (-mu*ma*g*math.cos(alpha), 0.0)
Frb = (-mu*mb*g, 0.0)
Wa = (-ma*g*math.sin(alpha), -ma*g*math.cos(alpha))
Wc = (mc*g, 0.0)
Tab = (Symbol('T2'), 0.0)
Tba = (-Symbol('T2'), 0.0)
Tbc = (Symbol('T1'), 0.0)
Tcb = (-Symbol('T1'), 0.0)
body = Body('body')
body.set('m', ma+mb+mc)
body.add_force('T2', Tab)
body.add_force('Fra', Fra)
body.add_force('Wa', Wa)
body.add_force('T1', Tbc)
body.add_force('T2', Tba)
body.add_force('Frb', Frb)
body.add_force('Wc', Wc)
body.add_force('T1', Tcb)
universe = Universe()
universe.add_body(body)
a_x, a_y = universe.newton_equation('body').solve(['a_x', 'a_y'])
a = magnitude((a_x[0], a_y[0]))
```
> [!TIP]
> **Solution:** `a = 2.05 m/s2`
### <a id="sec-example-energy-conservation"></a>3.2. Energy conservation
#### <a id="sec-example-ec0"></a>3.2.0. Example EC-0
[Problem 15.a](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)
From the top of an inclined plane of 2 m in length and 30º of slope, a 500 g body is allowed to slide with an initial velocity of 1 m/s. Assuming that there is no friction during the journey, with what speed does it reach the base of the plane?
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
m = 1.0
v0 = 1.0
alpha = math.radians(30)
length = 2.0
g = 9.81
h0 = length*math.sin(alpha)
hf = 0.0
vf = Symbol('vf')
Ep0 = m*g*h0
Ek0 = 1/2*m*v0**2
Epf = -m*g*hf
Ekf = -1/2*m*vf**2
body = Body('body')
body.add_energy('Ep0', Ep0)
body.add_energy('Ek0', Ek0)
body.add_energy('Epf', Epf)
body.add_energy('Ekf', Ekf)
universe = Universe()
universe.add_body(body)
vf = universe.energy_conservation_equation('body').solve('vf')
```
> [!TIP]
> **Solution:** `vf[0] = 4.54 m/s`
#### <a id="sec-example-ec1"></a>3.2.1. Example EC-1
[Problem: 15.a](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)
From the top of an inclined plane of 2 m in length and 30º of slope, a 500 g body is allowed to slide with an initial velocity of 1 m/s. Assuming that there is no friction during the journey, plot the final velocity as a function of the initial velocity.
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
file = 'vf_f_v0.png'
m = 1.0
v0 = Symbol('v0')
alpha = math.radians(30)
length = 2.0
g = 9.81
h0 = length*math.sin(alpha)
hf = 0.0
vf = Symbol('vf')
Ep0 = m*g*h0
Ek0 = 1/2*m*v0**2
Epf = -m*g*hf
Ekf = -1/2*m*vf**2
body = Body('body')
body.add_energy('Ep0', Ep0)
body.add_energy('Ek0', Ek0)
body.add_energy('Epf', Epf)
body.add_energy('Ekf', Ekf)
universe = Universe()
universe.add_body(body)
universe.energy_conservation_equation('body').plot('vf', 'v0', [0, 4], points=200, path=file, show=False)
```
**Solution:**
![Plot of final velocity as a function of initial velocity](https://github.com/girdeux31/easyPhysi/blob/main/tests/ref/vf_f_v0.png?raw=true)
#### <a id="sec-example-ec2"></a>3.2.2. Example EC-2
[Problem 15.b](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)
If upon reaching the flat surface, it collides with a spring of constant k = 200 N/m, what distance will the spring compress?
```
import math
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
m = 0.5
k = 200.0
v0 = 1.0
alpha = math.radians(30)
length = 2.0
g = 9.81
h0 = length*math.sin(alpha)
hf = 0.0
vf = 0.0
dx = Symbol('dx')
Ep0 = m*g*h0
Ek0 = 1/2*m*v0**2
Epf = -m*g*hf
Ekf = -1/2*m*vf**2
Epe = -1/2*k*dx**2
body = Body('body')
body.add_energy('Ep0', Ep0)
body.add_energy('Ek0', Ek0)
body.add_energy('Epf', Epf)
body.add_energy('Ekf', Ekf)
body.add_energy('Epe', Epe)
universe = Universe()
universe.add_body(body)
dx = universe.energy_conservation_equation('body').solve('dx')
```
> [!TIP]
> **Solution:** `dx[0] = 0.227 m`
#### <a id="sec-example-ec3"></a>3.2.3. Example EC-3
[Problem 20.c](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)
A 3 kg block situated at a height of 4 m is allowed to slide down a smooth, frictionless curved ramp. When it reaches the ground, it travels 10 m on a rough horizontal surface until it stops. Calculate the coefficient of friction with the horizontal surface.
```
from sympy import Symbol
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
m = 3.0
hc = 0.0
hb = 0.0
vc = 0.0
vb = 8.86
x = 10.0
g = 9.81
mu = Symbol('mu')
Epb = m*g*hb
Ekb = 1/2*m*vb**2
Epc = -m*g*hc
Ekc = -1/2*m*vc**2
Wfr = -mu*m*g*x
body = Body('body')
body.add_energy('Epb', Epb)
body.add_energy('Ekb', Ekb)
body.add_energy('Epa', Epc)
body.add_energy('Eka', Ekc)
body.add_energy('Wfr', Wfr)
universe = Universe()
universe.add_body(body)
mu = universe.energy_conservation_equation('body').solve('mu')
```
> [!TIP]
> **Solution:** `mu[0] = 0.40`
### <a id="sec-example-gravitational-field"></a>3.3. Gravitational field
#### <a id="sec-example-gf0"></a>3.3.0. Example GF-0
[Problem B1.a 2019 junio](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F2-PAU-Gravitacion.pdf)
A point mass A, MA = 3 kg, is located on the xy-plane, at the origin of coordinates. If a point mass B, MB = 5 kg, is placed at point (2, -2) m, determine the force exerted by mass A on mass B.
```
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.utils import magnitude
body_a = Body('A')
body_a.set('m', 3)
body_a.set('p', (0, 0))
body_b = Body('B')
body_b.set('m', 5)
body_b.set('p', (2, -2))
universe = Universe()
universe.add_body(body_a)
universe.add_body(body_b)
Fg_x, Fg_y = universe.gravitational_force_equation('B').solve(['Fg_x', 'Fg_y'])
Fg = magnitude((Fg_x[0], Fg_y[0]))
```
> [!TIP]
> **Solution:** `Fg = 1.25E-10 N`
#### <a id="sec-example-gf1"></a>3.3.1. Example GF-1
[Problem B1.b 2019 junio](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F2-PAU-Gravitacion.pdf)
A point mass A, MA = 3 kg, is located on the xy-plane, at the origin of coordinates. If a point mass B, MB = 5 kg, is placed at point (2, -2) m, determine the work required to move mass B from point (2, -2) m to point (2, 0) m due to the gravitational field created by mass A.
```
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
pa = (0, 0)
pb_0 = (2, -2)
pb_1 = (2, 0)
body_a = Body('A')
body_a.set('m', 3)
body_a.set('p', pa)
body_b = Body('B')
body_b.set('m', 5)
universe = Universe()
universe.add_body(body_a)
universe.add_body(body_b)
body_b.set('p', pb_0)
Ug_0 = universe.gravitational_potential_energy_equation('B').solve('Ug')
body_b.set('p', pb_1)
Ug_1 = universe.gravitational_potential_energy_equation('B').solve('Ug')
W = Ug_0[0] - Ug_1[0] # W = -AEp = Ug_0 - Ug_1
```
> [!TIP]
> **Solution:** `W = 1.47E-10 J`
#### <a id="sec-example-gf2"></a>3.3.2. Example GF-2
[Problem A1.a 2019 junio](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F2-PAU-Gravitacion.pdf)
A point mass m1 = 5 kg is located at the point (4, 3) m. Determine the intensity of the gravitational field created by mass m1 at the origin of coordinates.
```
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.utils import magnitude
body_a = Body('A')
body_a.set('m', 5)
body_a.set('p', (4, 3))
point = (0, 0)
universe = Universe()
universe.add_body(body_a)
g_x, g_y = universe.gravitational_field_intensity_equation(point).solve(['gg_x', 'gg_y'])
g = magnitude((g_x[0], g_y[0]))
```
> [!TIP]
> **Solution:** `g = 1.33E-11 m/s2`
### <a id="sec-example-electrical-field"></a>3.4. Electrical field
#### <a id="sec-example-ef0"></a>3.4.0. Example EF-0
[Problem A3.a 2021 junio coincidentes](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F4.1-PAU-CampoEl%C3%A9ctrico.pdf)
At the vertices of a square with a side of 2 m and centered at the origin of coordinates, four electric charges are placed as shown in the figure. Obtain the electric field created by the charges at the center of the square.
```
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
from easyphysi.utils import magnitude
point = (0, 0)
body_1 = Body('1')
body_1.set('q', 5E-9)
body_1.set('p', (-1, +1))
body_2 = Body('2')
body_2.set('q', 5E-9)
body_2.set('p', (+1, +1))
body_3 = Body('3')
body_3.set('q', 3E-9)
body_3.set('p', (+1, -1))
body_4 = Body('4')
body_4.set('q', 3E-9)
body_4.set('p', (-1, -1))
universe = Universe()
universe.add_body(body_1)
universe.add_body(body_2)
universe.add_body(body_3)
universe.add_body(body_4)
Ee_x, Ee_y = universe.electrical_field_intensity_equation(point).solve(['Ee_x', 'Ee_y'])
Ee = magnitude((Ee_x[0], Ee_y[0]))
```
> [!TIP]
> **Solution:** `Ee = 12.72 N/C`
#### <a id="sec-example-ef1"></a>3.4.1. Example EF-1
[Problem A3.b 2021 junio coincidentes](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F4.1-PAU-CampoEl%C3%A9ctrico.pdf)
At the vertices of a square with a side of 2 m and centered at the origin of coordinates, four electric charges are placed as shown in the figure. If an electron is launched from the center of the square with a velocity v = 3E4 j m/s, obtain the work done by the electric field when the electron leaves the square through the midpoint of the top side.
```
from easyphysi.drivers.body import Body, electron
from easyphysi.drivers.universe import Universe
point_0 = (0, 0)
point_1 = (0, 1)
body_1 = Body('1')
body_1.set('q', 5E-9)
body_1.set('p', (-1, +1))
body_2 = Body('2')
body_2.set('q', 5E-9)
body_2.set('p', (+1, +1))
body_3 = Body('3')
body_3.set('q', 3E-9)
body_3.set('p', (+1, -1))
body_4 = Body('4')
body_4.set('q', 3E-9)
body_4.set('p', (-1, -1))
universe = Universe()
universe.add_body(body_1)
universe.add_body(body_2)
universe.add_body(body_3)
universe.add_body(body_4)
universe.add_body(electron)
electron.set('p', point_0)
Ue_0 = universe.electrical_potential_energy_equation('electron').solve('Ue')
electron.set('p', point_1)
Ue_1 = universe.electrical_potential_energy_equation('electron').solve('Ue')
W = Ue_0[0] - Ue_1[0] # W = -AUe = Ue_0 - Ue_1
```
> [!TIP]
> **Solution:** `W = 1.97E-18 J`
#### <a id="sec-example-ef2"></a>3.4.2. Example EF-2
[Problem A3.b 2023 modelo](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F4.1-PAU-CampoEl%C3%A9ctrico.pdf)
A hollow spherical shell with a radius of 3 cm and centered at the origin of coordinates is charged with a uniform surface charge density σ = 2 µC/m2. Obtain the work done by the electric field to move a particle with a charge of 1 nC from the point (0, 2, 0) m to the point (3, 0, 0) m.
```
from easyphysi.drivers.body import Body
from easyphysi.drivers.universe import Universe
point_0 = (0, 2, 0)
point_1 = (3, 0, 0)
sphere = Body('sphere', dimensions=3)
sphere.set('q', 22.62E-9)
sphere.set('p', (0, 0, 0))
point = Body('point', dimensions=3)
point.set('q', 1E-9)
universe = Universe(dimensions=3)
universe.add_body(sphere)
universe.add_body(point)
point.set('p', point_0)
Ue_0 = universe.electrical_potential_energy_equation('point').solve('Ue')
point.set('p', point_1)
Ue_1 = universe.electrical_potential_energy_equation('point').solve('Ue')
W = Ue_0[0] - Ue_1[0] # W = -AEp = Ue_0 - Ue_1
```
> [!TIP]
> **Solution:** `W = 3.393E-8 J`
## <a id="sec-limitations-bugs"></a>4. Limitations and bugs
### <a id="sec-limitations"></a>4.0. Limitations
* Trigonometric functions are not able to handle symbols or expressions (for example `math.sin`, `math.cos` or `math.atan2`). Therefore, position unknown (`p`) cannot be solved for the following equations (this error is shown: `TypeError: Cannot convert expression to float`):
- electrical_field_intensity_equation
- electrical_force_equation
- gravitational_field_intensity_equation
- gravitational_force_equation
* For the same reason, when defining forces for `newton_equation` with `add_force` method, the angle cannot be set as un unknown as it is usually inside `math.sin` or `math.cos` functions. Fortunately, since the algebraic formula that defines each force is set by the user, arbitrary unknowns can be set instead of `math.sin(alpha)` or `math.cos(alpha)`. Then, easily get the angle with `math.asin` or `math.acos`.
> [!TIP]
> [Example](#sec-example-d1) uses this workaround to solve the unknown angle in a dynamics problem.
### <a id="sec-bugs"></a>4.1. Bugs
Contact the main author if you discover any bug, see [Section](#sec-contact).
## <a id="sec-changelog"></a>5. Changelog
Main changes:
* 25/06/23 - Initial idea
* 21/12/23 - v1.0.0 first stable version
* 22/12/23 - v1.0.1 minor changes in README and examples
## <a id="sec-licence"></a>6. License
This project includes GPL-3.0 License. The GPL-3.0 is a free software license that enforces the copyleft principle, requiring any modifications or derivatives to be distributed under the same terms. It mandates source code availability, compatibility with other open-source licenses, and prohibits additional restrictions. The license promotes equal user rights and addresses patent issues.
## <a id="sec-contact"></a>7. Contact
Feel free to contact mesado31@gmail.com for any suggestion or bug.
Raw data
{
"_id": null,
"home_page": "https://github.com/girdeux31/easyPhysi",
"name": "easyphysi",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": "",
"keywords": "{physics,pre-university,bachiller,uarm,kinematics,dynamics,energy conservation,gravitational field,electrical field}",
"author": "Carles Mesado",
"author_email": "mesado31@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/82/dd/a7a94ac865b555e792799083cb9dc33d376ae590d5788675edc25f89adc5/easyphysi-1.0.1.tar.gz",
"platform": "any",
"description": "# <a id=\"sec-top\"></a>easyPhysi\n\neasyPhysi is a physics library to solve pre-university physics problems. The physics areas that are covered by easyPhysi are summarized hereafter. See the main structure to use easyPhysi in [Section](#sec-main-structure) and also some [Examples](#sec-examples).\n\n - Kinematics\n - Dynamics\n - Energy conservation\n - Gravitational field\n - Electrical field\n\n> [!Note]\n> Visit GitHub page at https://github.com/girdeux31/easyPhysi\n\nThe main characteristics for easyPhysi are summarized in the following table.\n\n<a id=\"tab-characteristics\"></a>\n\n | Characteristic | Value |\n |------------------|---------------|\n | Name | easyPhysi |\n | Version | 1.0.1 |\n | Author | Carles Mesado |\n | Date | 22/12/2023 |\n | Size | ~ 40 KiB |\n\n> [!NOTE]\n> Notes are use through this document to remark some features.\n\n> [!TIP]\n> Tips are use through this document to link relevant examples or show their solution.\n\n## <a id=\"sec-index\"></a>0. Index\n\n0. [Index](#sec-index)\n1. [Installation](#sec-installation)\n2. [Usage](#sec-usage)\n - [Main structure](#sec-main-structure)\n - [Properties](#sec-properties)\n - [Special bodies](#sec-special-bodies)\n - [Equations](#sec-equations)\n - [Advance features](#sec-advance-features)\n3. [Examples](#sec-examples)\n - [Kinematics](#sec-example-kinematics)\n - [Dynamics](#sec-example-dynamics)\n - [Energy conservation](#sec-example-energy-conservation)\n - [Gravitational field](#sec-example-gravitational-field)\n - [Electrical field](#sec-example-electrical-field)\n4. [Limitations and bugs](#sec-limitations-bugs)\n - [Limitations](#sec-limitations)\n - [Bugs](#sec-bugs)\n5. [Changelog](#sec-changelog)\n6. [License](#sec-licence)\n7. [Contact](#sec-contact)\n\n## <a id=\"sec-installation\"></a>1. Installation\n\n> [!NOTE]\n> easyPhysi is developed and tested with Python 3.10.\n\nInstall the package with pip,\n\n`pip install easyphysi`\n\nor clone the GitHub repository.\n\n`gh repo clone girdeux31/easyPhysi`\n\nThe following third-party modules are requirements.\n\n - matplotlib>=3.7.0\n - scipy>=1.11.0\n - sympy==1.12\n\n## <a id=\"sec-usage\"></a>2. Usage\n\n### <a id=\"sec-main-structure\"></a>2.0. Main structure\n\nMost pre-university physics problems can be solved following this structure composed of a few lines.\n\n```\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.drivers.body import Body\n\nuniverse = Universe(dimensions=2) # 2 o 3 dimensions, default is 2\nuniverse.set('my_prop', value)\n\nbody = Body('my_body', dimensions=2) # 2 o 3 dimensions, default is 2\nbody.set('my_prop', value)\n\n# define more properties or more bodies as needed\n\nuniverse.add_body(body)\n\n# add more bodies as needed\n\nsolution = universe.physics_equation('my_body').solve('my_unknown')\n```\n\nLet's take the code apart line by line. \n\n - Line 1 and 2: import `Universe` and `Body` classes, these are needed in every single problem solved with easyPhysi.\n - Line 4: define a universe instance with `Universe` class. The `dimensions` is an optional argument, but only 2 o 3 dimensions are allowed, default is 2.\n - Line 5: define as many properties for the universe as needed. Universe properties are listed in [Table](#tab-universe-properties), name and value must be included as arguments. Values must be consistent with property type, see [Section](#sec-property-types).\n - Line 7: define as many body instances as needed with `Body` class provided that they have different names. Its name must be included as first argument, the `dimensions` is an optional argument, but only 2 o 3 dimensions are allowed, default is 2.\n - Line 8: define as many properties for the body as needed. Body properties are listed in [Table](#tab-body-properties), name and value must be included as arguments. Values must be consistent with property type, see [Section](#sec-property-types).\n - Line 12: add all defined bodies to the universe (body and universe dimensions must match).\n - Line 16: solve the relevant physics equation over a specific body and define the unknown(s). See a list of allowed equations and unknowns in [Table](#tab-equations).\n\n> [!NOTE]\n> Define all bodies and properties before solving any equation.\n\n> [!TIP]\n> [Example](#sec-example-ef2) defines a 3D problem.\n\n### <a id=\"sec-properties\"></a>2.1. Properties\n\nSome properties are defined on a body, while others are defined on a universe. Next [Table](#tab-body-properties) lists all properties that are allowed to be defined on a body.\n\n> [!NOTE]\n> Property names are case sensitive.\n\n<a id=\"tab-body-properties\"></a>\n\n |Property |Description |Type |Components |\n |---------|--------------------------------|----------|---------------------|\n |a |Acceleration |Vector |(a_x, a_y[, a_z]) |\n |q |Charge |Scalar |q |\n |Fe |Electrical force |Vector |(Fe_x, Fe_y[, Fe_z]) |\n |Ue |Electrical potential energy |Scalar |Ue |\n |Fg |Gravitational force |Vector |(Fg_x, Fg_y[, Fg_z]) |\n |Ug |Gravitational potential energy |Scalar |Ug |\n |p0 |Initial position |Vector |(p0_x, p0_y[, p0_z]) |\n |v0 |Initial velocity |Vector |(v0_x, v0_y[, v0_z]) |\n |m |Mass |Scalar |m |\n |p |Position |Vector |(p_x, p_y[, p_z]) |\n |v |Velocity |Vector |(v_x, v_y[, v_z]) |\n\nNext [Table](#tab-universe-properties) lists all properties that are allowed to be defined in a universe.\n\n<a id=\"tab-universe-properties\"></a>\n\n |Property |Description |Type |Value |\n |---------|--------------------------------|----------|---------------------|\n |Ee |Electrical field intensity |Vector |(Ee_x, Ee_y[, Ee_z]) |\n |Ve |Electrical potential |Scalar |Ve |\n |gg |Gravitational field intensity |Vector |(gg_x, gg_y[, gg_z]) |\n |Vg |Gravitational potential |Scalar |Vg |\n |g |Gravity |Vector |(g_x, g_y[, g_z]) |\n |t |Time |Scalar |t |\n\nUse `set` method in an instanciated body or universe to define its property and define its value according to its type, see [Section](#sec-property-types).\n\n> [!NOTE]\n> Units are up to the user. Even though SI is recommended, other systems can be used provided that different units are consistent.\n\n> [!NOTE]\n> Force and energy cannot be defined as properties since each force and energy is defined by its own algebraic formula, see [Section](#sec-property-nondefined).\n\n#### <a id=\"sec-property-types\"></a>2.1.0. Property types\n\nThere are two types of properties: **scalars** (for example `m` for mass) and **vectors** (for example `g` for gravity).\n\n##### <a id=\"sec-property-type-scalar\"></a>2.1.0.i Scalars\n\nThey are integers of floats, examples follow.\n\n```\nbody.set('prop', 250) # int\nbody.set('prop', 5.0E-9) # float\n```\n\n##### <a id=\"sec-property-type-vectors\"></a>2.1.0.ii Vectors\n\nThey are list or tuples (either integers or floats), examples follow.\n\n```\nbody.set('prop', [0.0, -9.81]) # list\nbody.set('prop', (0, +3)) # tuple\n```\n\nThe length of `value` (components) must be the same as defined in the instance of the body or universe the property applies to.\n\n> [!NOTE]\n> It is also possible to define only one component in a vector parameter (the other may be irrelevant or unknown). To do so, append `_x`, `_y` or `_z` to the property name according to the desired axis.\n\n```\nbody.set('prop_x', value_x)\nbody.set('prop_y', value_y)\nbody.set('prop_z', value_z)\n```\n\n#### <a id=\"sec-property-nondefined\"></a>2.1.1. Non-defined properties\n\nForce (mainly used in `newton_equation`) and energy (mainly used in `energy_conservation_equation`) cannot be defined as properties in an instanciated body (note that they are not listed in [Table](#tab-equations)). Instead they can be defined in with `add_force` and `add_energy` methods over any instanciated body.\n\n```\nbody.add_force('my_force', value)\nbody.add_energy('my_energy', value)\n```\n\nThis is designed on purpose because many different forces and energies can apply to a body and could have different algebraic expressions. Thus, the algebraic expression for the force and energy must be defined by the user.\n\n> [!TIP]\n> [Section](#sec-example-dynamics) shows examples using `newton_equation` and `add_force` method.\n\n> [!TIP]\n> [Section](#sec-example-energy-conservation) shows examples using `energy_conservation_equation` and `add_energy` method.\n\n### <a id=\"sec-special-bodies\"></a>2.2. Special bodies\n\nSpecial bodies are pre-defined bodies that are ready to be used. There are two types of special bodies: subatomic particles and celestial bodies, see following tables. The mass and charge of subatomic particles are defined in kilograms and coulombs.\n\n<a id=\"tab-body-particles\"></a>\n\n| Body | Mass (kg) | Charge (C) |\n|----------|-----------|------------|\n| electron | 9.109e-31 | -1.602e-19 |\n| proton | 1.673e-27 | 1.602e-19 |\n| neutron | 1.675e-27 | 0.0 |\n\nThe mass and position of celestial bodies are defined in kilograms and kilometers.\n\n> [!NOTE]\n> The distance of celestial bodies is the average distance to the Sun (except for the Moon, which is the average distance to the Earth) and is defined in the x-axis.\n\n<a id=\"tab-body-celestial\"></a>\n\n| Body | Mass (kg) | Position (km) |\n|----------|-----------|---------------|\n| sun | 1.988e30 | 0.0 |\n| mercury | 3.301e23 | 57900000 |\n| venus | 4.867e24 | 108200000 |\n| earth | 5.972e24 | 149600000 |\n| moon | 7.348e22 | 384400 |\n| mars | 6.417e23 | 227900000 |\n| jupiter | 1.899e27 | 778600000 |\n| saturn | 5.685e26 | 1433500000 |\n| uranus | 8.682e25 | 2872500000 |\n| neptune | 1.024e26 | 4495100000 |\n\nImport them using the following line and use them without instanciating the body or defining its main properties.\n\n`from easyphysi.drivers.body import special_body`\n\n> [!TIP]\n> [Example](#sec-example-ef1) imports an electron from special bodies.\n \n### <a id=\"sec-equations\"></a>2.3. Equations\n\nThe following equations can be solved, each one is a method defined in the `Universe` class.\n\n> [!NOTE]\n> Equation names are case sensitive.\n\n<a id=\"tab-equations\"></a>\n\n |Equation |Type |Unknowns |\n |----------------------------------------|----------|--------------- |\n |electrical_field_intensity_equation |Vectorial |Ee, p, q |\n |electrical_force_equation |Vectorial |Fe, p, q |\n |electrical_potential_energy_equation |Scalar |Ue, p, q |\n |electrical_potential_equation |Scalar |Ve, p, q |\n |energy_conservation_equation |Scalar |- \t\t |\n |gravitational_field_intensity_equation |Vectorial |gg, m, p |\n |gravitational_force_equation |Vectorial |Fg, m, p |\n |gravitational_potential_energy_equation |Scalar |Ug, m, p |\n |gravitational_potential_equation |Scalar |Vg, m, p |\n |linear_position_equation |Vectorial |g, p, p0, t, v0 |\n |linear_velocity_equation |Vectorial |g, t, v, v0 \t |\n |newton_equation |Vectorial |a, m \t |\n \nUse any of these equation in an instance of universe and include the body the equation applies to. Then use the `solve` method and include the unknown(s) to be solved, see third column in [Table](#tab-equation).\n\n`universe.physics_equation('my_body').solve('my_unknown')`\n\n#### <a id=\"sec-equation-types\"></a>2.3.0. Equation types\n\nThere are two types of equations: scalar (for example `energy_conservation_equation`) and vectorial (for example `newton_equation`).\n\n##### <a id=\"sec-equation-type-scalar\"></a>2.3.0.i Scalar\n\nOnly one unknown is accepted.\n\n```\nout = universe.physics_equation('my_body').solve('my_unk')\n```\n\n> [!NOTE]\n> The output is always a list of roots.\n\n##### <a id=\"sec-equation-type-vectorial\"></a>2.3.0.ii Vectorial\n\nAs many unknowns as universe dimensions are accepted, these must be defined in a list and passed as argument of `solve` method. Vector components must be append to unknown names, such as `a_x`, `a_y` and `a_z` for acceleration, see [Section](#sec-property-type-vectors). The same number of unknowns must be defined as outputs, no name restriction apply for output unknowns.\n\n```\nout_x, out_y = universe.physics_equation('my_body').solve(['unk_x', 'unk_y'])\n```\n\n> [!NOTE]\n> The output always has as many list of roots as unknowns.\n\n### <a id=\"sec-advance-features\"></a>2.4. Advance features\n\nThe most useful features are already defined. However, for the sake of completeness, a few more features for the advance user are defined in this section.\n\n#### <a id=\"sec-other-feature-magnitude\"></a>2.4.0. Vector module\n\nFunction `magnitude` is available to obtain a vector module or magnitude.\n\n```\nfrom easyphysi.utils import magnitude\nprop = magnitude((prop_x, prop_y))\n```\n\n> [!TIP]\n> [Example](#sec-example-k0) makes use of `magnitude` function to calculate the modulo of the velocity.\n\n#### <a id=\"sec-other-feature-symbol\"></a>2.4.1. Define new unknowns\n\nMost unknowns are already defined when a universe or body are instanciated, see [Table](#tab-universe-properties) and [Table](#tab-body-properties). However, sometimes new unknowns must be defined, specially with `newton_equation` and `energy_conservation_equation` since force and energy algebraic expressions are defined by user, see [Section](#sec-property-nondefined). In these case, `Symbol` class from Sympy library can be used. Then, the new unknown can be used as argument in `solve` method to calculate its numerical value.\n\n```\nfrom sympy import Symbol\nmy_unknown = Symbol('my_unknown')\n```\n\n> [!TIP]\n> [Example](#sec-example-ec0) makes uso of `Symbol` class to define the final velocity (`vf`) as an unknown and then solve its value.\n\n#### <a id=\"sec-other-feature-subs\"></a>2.4.2. Substitute variable\n\nMethod `solve` returns numerical values if there is only one unknown (all properties are defined but one), but returns expressions if there is more than one unknown (two or more properties are left undefined). Use `subs` method to replace an unknown by a specified numerical value.\n\n```\nfoo = universe.physics_equation('body').solve('my_unk') # several undefined properties\nout = foo.subs('my_sym', value)\n```\n\n> [!Note]\n> There is no need to import `subs` since it is a method inherent in any Sympy expression.\n\n> [!TIP]\n> [Example](#sec-example-d0) makes uso of `subs` method to substitute the friction coefficient by its value.\n\n#### <a id=\"sec-other-feature-get-equation\"></a>2.4.3. Get equation from system\n\nIn some cases, it is only interesting to solve a specific equation from a vectorial equation (that is a set of equations or a system). The method `get_equation` can be used over any vectorial equation to return the specific equation, the axis component is expected as method argument.\n\n`universe.physics_equation('my_body').get_equation('axis')`\n\n> [!TIP]\n> [Example](#sec-example-k0) makes use of `get_equation` method to extract an equation from a vectorial equation (or set of equations) and, then, solve its unknown.\n\n#### <a id=\"sec-other-feature-solve-systems\"></a>2.4.4. Solving system of equations\n\nSystem of equations can be defined -with `System` class- and solved with `solve` method. The `solve` method accepts a list with as many unknowns as equations defined in the system.\n\n```\nfrom easyphysi.drivers.system import System\n\nequation = universe.physics_equation('body').solve('my_unk')\n\nsystem = System()\nsystem.add_equation(equation)\n\n# define and add as many equations as needed\n\nx, y, z = system.solve(['x', 'y', 'z'])\n```\n\n> [!TIP]\n> [Example](#sec-example-d2) makes use of `System` class to solve a set of equations.\n\n#### <a id=\"sec-other-feature-plot\"></a>2.4.5. Plotting equations\n\nMethod `plot` can be used over any equation -scalar or vectorial- to plot unknowns in the form of function `independent = f(dependent)`.\n\n`universe.physics_equation('my_body').plot(independent, dependent, x_range, points=100, path=None, show=True)`\n\nArguments are described hereafter.\n\n - `independent`: if equation is [scalar](#sec-equation-type-scalar), then only one independent unknown is expected. If equation is [vectorial](#sec-equation-type-vectorial), then a list with length equal to the number of components (or universe dimensions) is expected.\n - `dependent`: exactly one unknown is expected.\n - `x_range`: range to plot for dependent unknown (x-axis).\n - `points`: number of points to plot, optional argument, default is 100.\n - `path`: path to save image as file, optional argument, by default it is None and no image is saved.\n - `show`: if `True` the plot is shown on screen, optional argument, by default it is `True`.\n\n> [!TIP]\n> [Example](#sec-example-ec1) makes uso of `plot` method to plot a scalar equation (final velocity as a function of initial velocity).\n\n## <a id=\"sec-examples\"></a>3. Examples\n\n### <a id=\"sec-example-kinematics\"></a>3.0. Kinematics\n\n#### <a id=\"sec-example-k0\"></a>3.0.0. Example K-0\n\n[Problem 10](https://fq.iespm.es/documentos/janavarro/fisica2bach/T0_vectores_cinematica.pdf)\n\nA ball falls from a roof located 10 m high, forming a 30\u00ba angle with the horizontal, with a speed of 2 m/s. Calculate:\n\na) At what distance from the wall does it hit the ground?\n\nb) The speed it has when it reaches the ground (disregard air friction).\n\n```\nimport math\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.utils import magnitude\n\nalpha = math.radians(-30)\ng = (0.0, -9.81)\np0 = (0.0, 10.0)\nv0 = (2.0*math.cos(alpha), 2.0*math.sin(alpha))\npy = 0.0\n\nbody = Body('body') # by default 2D\n\nbody.set('p0', p0)\nbody.set('v0', v0)\nbody.set('p_y', py)\n\nuniverse = Universe() # by default 2D\n\nuniverse.set('g', g)\nuniverse.add_body(body)\n\nt = universe.linear_position_equation('body').get_equation('y').solve('t')\n\nuniverse.set('t', t[1])\n\np_x = universe.linear_position_equation('body').get_equation('x').solve('p_x')\n\nv_x[0], v_y[0] = universe.linear_velocity_equation('body').solve(['v_x', 'v_y'])\nv = magnitude((v_x[0], v_y[0]))\n```\n\n> [!TIP]\n> **Solution:** `p_x[0] = 2.30 m, v = 14.15 m/s`\n\n### <a id=\"sec-example-dynamics\"></a>3.1. Dynamics\n\n#### <a id=\"sec-example-d0\"></a>3.1.0. Example D-0\n\n[Problem 14](https://fq.iespm.es/documentos/rafael_artacho/4_ESO/08.%20Problemas%20Las%20fuerzas.pdf)\n\nThe following ramp has an inclination of 25\u00ba. Determine the force that must be exerted on the 250 kg wagon to make it go up with constant velocity:\n\na) If there is no friction.\n\nb) If \ud835\udf07 = 0.1.\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.drivers.system import System\n\nmu = Symbol('mu')\nalpha = math.radians(25)\nm = 250\ng = 9.81\nW = (-m*g*math.sin(alpha), -m*g*math.cos(alpha))\nN = (0.0, m*g*math.sin(alpha))\nFr = (-mu*m*g*math.cos(alpha), 0.0)\n\nbody = Body('body')\n\nbody.set('m', m)\nbody.add_force('W', W)\nbody.add_force('Fr', Fr)\nbody.add_force('N', N)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\na_x[0], a_y[0] = universe.newton_equation('body').solve(['a_x', 'a_y'])\nf_00 = m*a_x[0].subs('mu', 0.0)\nf_01 = m*a_x[0].subs('mu', 0.1)\n```\n\n> [!TIP]\n> **Solution:** `f_00 = -1036.47 N, f_01 = -1258.74 N`\n\n#### <a id=\"sec-example-d1\"></a>3.1.1. Example D-1\n\nFollowing previous example, calculate the angle if the acceleration is known.\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.drivers.system import System\n\nmu = 0.1\nsin_alpha = Symbol('sin_alpha')\ncos_alpha = Symbol('cos_alpha')\nm = 250\ng = 9.81\na = (-5.03497308675920, -4.74499424315328) # from previous example\nW = (-m*g*sin_alpha, -m*g*cos_alpha)\nN = (0.0, m*g*sin_alpha)\nFr = (-mu*m*g*cos_alpha, 0.0)\n\nbody = Body('body')\n\nbody.set('m', m)\nbody.set('a', a)\nbody.add_force('W', W)\nbody.add_force('Fr', Fr)\nbody.add_force('N', N)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\nsin_alpha, cos_alpha = universe.newton_equation('body').solve(['sin_alpha', 'cos_alpha'])\n\nalpha_from_sin = math.degrees(math.asin(sin_alpha[0]))\nalpha_from_cos = math.degrees(math.acos(cos_alpha[0]))\n```\n\n> [!TIP]\n> **Solution:** `alpha_from_sin = 25\u00ba, alpha_from_cos = 25\u00ba`\n\n#### <a id=\"sec-example-d2\"></a>3.1.2. Example D-2\n\nIn the system shown in the figure, the three masses are mA = 1 kg, mB = 2 kg, and mC = 1.5 kg. If the coefficient of friction is \ud835\udf07 = 0.223, calculate the acceleration of the system when it is released.\n\n![System of three masses](https://github.com/girdeux31/easyPhysi/blob/main/tests/ref/system_dynamics.png?raw=true)\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.drivers.system import System\n\ng = 9.81\nmu = 0.223\nalpha = math.radians(30)\nma, mb, mc = 1, 2, 1.5\n\nFra = (-mu*ma*g*math.cos(alpha), 0.0)\nFrb = (-mu*mb*g, 0.0)\nWa = (-ma*g*math.sin(alpha), -ma*g*math.cos(alpha))\nWc = (mc*g, 0.0)\n\nTab = (Symbol('T2'), 0.0)\nTba = (-Symbol('T2'), 0.0)\nTbc = (Symbol('T1'), 0.0)\nTcb = (-Symbol('T1'), 0.0)\n\nbody_a = Body('A')\nbody_a.set('m', ma)\nbody_a.add_force('T2', Tab)\nbody_a.add_force('Fra', Fra)\nbody_a.add_force('Wa', Wa)\n\nbody_b = Body('B')\nbody_b.set('m', mb)\nbody_b.add_force('T1', Tbc)\nbody_b.add_force('T2', Tba)\nbody_b.add_force('Frb', Frb)\n\nbody_c = Body('C')\nbody_c.set('m', mc)\nbody_c.add_force('Wc', Wc)\nbody_c.add_force('T1', Tcb)\n\nuniverse = Universe()\nuniverse.add_body(body_a)\nuniverse.add_body(body_b)\nuniverse.add_body(body_c)\n\neq_a = universe.newton_equation('A').get_equation('x')\neq_b = universe.newton_equation('B').get_equation('x')\neq_c = universe.newton_equation('C').get_equation('x')\n\nunknowns = ['T1', 'T2', 'a_x']\n\nsystem = System()\nsystem.add_equation(eq_a)\nsystem.add_equation(eq_b)\nsystem.add_equation(eq_c)\n\nT1, T2, a_x = system.solve(unknowns)\n```\n\n> [!TIP]\n> **Solution:** `T1[0] = 13.54 N, T2[0] = 7.59 N, a_x[0] = 0.79 m/s2`\n\n#### <a id=\"sec-example-d3\"></a>3.1.3. Example D-3\n\nIn the system shown in the figure, the three masses are mA = 1 kg, mB = 2 kg, and mC = 1.5 kg. If the coefficient of friction is \ud835\udf07 = 0.223, calculate the acceleration of the system when it is released.\n\n![System of three masses](https://github.com/girdeux31/easyPhysi/blob/main/tests/ref/system_dynamics.png?raw=true)\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.drivers.system import System\nfrom easyphysi.utils import magnitude\n\ng = 9.81\nmu = 0.223\nalpha = math.radians(30)\nma = 1\nmb = 2\nmc = 1.5\n\nFra = (-mu*ma*g*math.cos(alpha), 0.0)\nFrb = (-mu*mb*g, 0.0)\nWa = (-ma*g*math.sin(alpha), -ma*g*math.cos(alpha))\nWc = (mc*g, 0.0)\n\nTab = (Symbol('T2'), 0.0)\nTba = (-Symbol('T2'), 0.0)\nTbc = (Symbol('T1'), 0.0)\nTcb = (-Symbol('T1'), 0.0)\n\nbody = Body('body')\nbody.set('m', ma+mb+mc)\nbody.add_force('T2', Tab)\nbody.add_force('Fra', Fra)\nbody.add_force('Wa', Wa)\nbody.add_force('T1', Tbc)\nbody.add_force('T2', Tba)\nbody.add_force('Frb', Frb)\nbody.add_force('Wc', Wc)\nbody.add_force('T1', Tcb)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\na_x, a_y = universe.newton_equation('body').solve(['a_x', 'a_y'])\na = magnitude((a_x[0], a_y[0]))\n```\n\n> [!TIP]\n> **Solution:** `a = 2.05 m/s2`\n\n### <a id=\"sec-example-energy-conservation\"></a>3.2. Energy conservation\n\n#### <a id=\"sec-example-ec0\"></a>3.2.0. Example EC-0\n\n[Problem 15.a](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)\n\nFrom the top of an inclined plane of 2 m in length and 30\u00ba of slope, a 500 g body is allowed to slide with an initial velocity of 1 m/s. Assuming that there is no friction during the journey, with what speed does it reach the base of the plane?\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\n\nm = 1.0\nv0 = 1.0\nalpha = math.radians(30)\nlength = 2.0\ng = 9.81\nh0 = length*math.sin(alpha)\nhf = 0.0\nvf = Symbol('vf')\n\nEp0 = m*g*h0\nEk0 = 1/2*m*v0**2\nEpf = -m*g*hf\nEkf = -1/2*m*vf**2\n\nbody = Body('body')\n\nbody.add_energy('Ep0', Ep0)\nbody.add_energy('Ek0', Ek0)\nbody.add_energy('Epf', Epf)\nbody.add_energy('Ekf', Ekf)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\nvf = universe.energy_conservation_equation('body').solve('vf')\n```\n\n> [!TIP]\n> **Solution:** `vf[0] = 4.54 m/s`\n\n#### <a id=\"sec-example-ec1\"></a>3.2.1. Example EC-1\n\n[Problem: 15.a](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)\n\nFrom the top of an inclined plane of 2 m in length and 30\u00ba of slope, a 500 g body is allowed to slide with an initial velocity of 1 m/s. Assuming that there is no friction during the journey, plot the final velocity as a function of the initial velocity.\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\n\nfile = 'vf_f_v0.png'\n\nm = 1.0\nv0 = Symbol('v0')\nalpha = math.radians(30)\nlength = 2.0\ng = 9.81\nh0 = length*math.sin(alpha)\nhf = 0.0\nvf = Symbol('vf')\n\nEp0 = m*g*h0\nEk0 = 1/2*m*v0**2\nEpf = -m*g*hf\nEkf = -1/2*m*vf**2\n\nbody = Body('body')\n\nbody.add_energy('Ep0', Ep0)\nbody.add_energy('Ek0', Ek0)\nbody.add_energy('Epf', Epf)\nbody.add_energy('Ekf', Ekf)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\nuniverse.energy_conservation_equation('body').plot('vf', 'v0', [0, 4], points=200, path=file, show=False)\n```\n\n**Solution:**\n\n![Plot of final velocity as a function of initial velocity](https://github.com/girdeux31/easyPhysi/blob/main/tests/ref/vf_f_v0.png?raw=true)\n\n#### <a id=\"sec-example-ec2\"></a>3.2.2. Example EC-2\n\n[Problem 15.b](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)\n\nIf upon reaching the flat surface, it collides with a spring of constant k = 200 N/m, what distance will the spring compress?\n\n```\nimport math\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\n\nm = 0.5\nk = 200.0\nv0 = 1.0\nalpha = math.radians(30)\nlength = 2.0\ng = 9.81\nh0 = length*math.sin(alpha)\nhf = 0.0\nvf = 0.0\ndx = Symbol('dx')\n\nEp0 = m*g*h0\nEk0 = 1/2*m*v0**2\nEpf = -m*g*hf\nEkf = -1/2*m*vf**2\nEpe = -1/2*k*dx**2\n\nbody = Body('body')\n\nbody.add_energy('Ep0', Ep0)\nbody.add_energy('Ek0', Ek0)\nbody.add_energy('Epf', Epf)\nbody.add_energy('Ekf', Ekf)\nbody.add_energy('Epe', Epe)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\ndx = universe.energy_conservation_equation('body').solve('dx')\n```\n\n> [!TIP]\n> **Solution:** `dx[0] = 0.227 m`\n\n#### <a id=\"sec-example-ec3\"></a>3.2.3. Example EC-3\n\n[Problem 20.c](https://fq.iespm.es/documentos/rafael_artacho/1_bachillerato/15._problemas_trabajo_y_energia_mecanica.pdf)\n\nA 3 kg block situated at a height of 4 m is allowed to slide down a smooth, frictionless curved ramp. When it reaches the ground, it travels 10 m on a rough horizontal surface until it stops. Calculate the coefficient of friction with the horizontal surface.\n\n```\nfrom sympy import Symbol\n\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\n\nm = 3.0\nhc = 0.0\nhb = 0.0\nvc = 0.0\nvb = 8.86\nx = 10.0\ng = 9.81\nmu = Symbol('mu')\n\nEpb = m*g*hb\nEkb = 1/2*m*vb**2\nEpc = -m*g*hc\nEkc = -1/2*m*vc**2\nWfr = -mu*m*g*x\n\nbody = Body('body')\n\nbody.add_energy('Epb', Epb)\nbody.add_energy('Ekb', Ekb)\nbody.add_energy('Epa', Epc)\nbody.add_energy('Eka', Ekc)\nbody.add_energy('Wfr', Wfr)\n\nuniverse = Universe()\nuniverse.add_body(body)\n\nmu = universe.energy_conservation_equation('body').solve('mu')\n```\n\n> [!TIP]\n> **Solution:** `mu[0] = 0.40`\n\n### <a id=\"sec-example-gravitational-field\"></a>3.3. Gravitational field\n\n#### <a id=\"sec-example-gf0\"></a>3.3.0. Example GF-0\n\n[Problem B1.a 2019 junio](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F2-PAU-Gravitacion.pdf)\n\nA point mass A, MA = 3 kg, is located on the xy-plane, at the origin of coordinates. If a point mass B, MB = 5 kg, is placed at point (2, -2) m, determine the force exerted by mass A on mass B.\n\n```\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.utils import magnitude\n\nbody_a = Body('A')\nbody_a.set('m', 3)\nbody_a.set('p', (0, 0))\n\nbody_b = Body('B')\nbody_b.set('m', 5)\nbody_b.set('p', (2, -2))\n\nuniverse = Universe()\nuniverse.add_body(body_a)\nuniverse.add_body(body_b)\n\nFg_x, Fg_y = universe.gravitational_force_equation('B').solve(['Fg_x', 'Fg_y'])\nFg = magnitude((Fg_x[0], Fg_y[0]))\n```\n\n> [!TIP]\n> **Solution:** `Fg = 1.25E-10 N`\n\n#### <a id=\"sec-example-gf1\"></a>3.3.1. Example GF-1\n\n[Problem B1.b 2019 junio](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F2-PAU-Gravitacion.pdf)\n\nA point mass A, MA = 3 kg, is located on the xy-plane, at the origin of coordinates. If a point mass B, MB = 5 kg, is placed at point (2, -2) m, determine the work required to move mass B from point (2, -2) m to point (2, 0) m due to the gravitational field created by mass A.\n\n```\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\n\npa = (0, 0)\npb_0 = (2, -2)\npb_1 = (2, 0)\n\nbody_a = Body('A')\nbody_a.set('m', 3)\nbody_a.set('p', pa)\n\nbody_b = Body('B')\nbody_b.set('m', 5)\n\nuniverse = Universe()\nuniverse.add_body(body_a)\nuniverse.add_body(body_b)\n\nbody_b.set('p', pb_0)\n\nUg_0 = universe.gravitational_potential_energy_equation('B').solve('Ug')\n\nbody_b.set('p', pb_1)\n\nUg_1 = universe.gravitational_potential_energy_equation('B').solve('Ug')\n\nW = Ug_0[0] - Ug_1[0] # W = -AEp = Ug_0 - Ug_1\n```\n\n> [!TIP]\n> **Solution:** `W = 1.47E-10 J`\n\n#### <a id=\"sec-example-gf2\"></a>3.3.2. Example GF-2\n\n[Problem A1.a 2019 junio](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F2-PAU-Gravitacion.pdf)\n\nA point mass m1 = 5 kg is located at the point (4, 3) m. Determine the intensity of the gravitational field created by mass m1 at the origin of coordinates.\n\n```\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.utils import magnitude\n\nbody_a = Body('A')\nbody_a.set('m', 5)\nbody_a.set('p', (4, 3))\npoint = (0, 0)\n\nuniverse = Universe()\nuniverse.add_body(body_a)\n\ng_x, g_y = universe.gravitational_field_intensity_equation(point).solve(['gg_x', 'gg_y'])\ng = magnitude((g_x[0], g_y[0]))\n```\n\n> [!TIP]\n> **Solution:** `g = 1.33E-11 m/s2`\n\n### <a id=\"sec-example-electrical-field\"></a>3.4. Electrical field\n\n#### <a id=\"sec-example-ef0\"></a>3.4.0. Example EF-0\n\n[Problem A3.a 2021 junio coincidentes](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F4.1-PAU-CampoEl%C3%A9ctrico.pdf)\n\nAt the vertices of a square with a side of 2 m and centered at the origin of coordinates, four electric charges are placed as shown in the figure. Obtain the electric field created by the charges at the center of the square.\n\n```\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\nfrom easyphysi.utils import magnitude\n\npoint = (0, 0)\n\nbody_1 = Body('1')\nbody_1.set('q', 5E-9)\nbody_1.set('p', (-1, +1))\n\nbody_2 = Body('2')\nbody_2.set('q', 5E-9)\nbody_2.set('p', (+1, +1))\n\nbody_3 = Body('3')\nbody_3.set('q', 3E-9)\nbody_3.set('p', (+1, -1))\n\nbody_4 = Body('4')\nbody_4.set('q', 3E-9)\nbody_4.set('p', (-1, -1))\n\nuniverse = Universe()\nuniverse.add_body(body_1)\nuniverse.add_body(body_2)\nuniverse.add_body(body_3)\nuniverse.add_body(body_4)\n\nEe_x, Ee_y = universe.electrical_field_intensity_equation(point).solve(['Ee_x', 'Ee_y'])\nEe = magnitude((Ee_x[0], Ee_y[0]))\n```\n\n> [!TIP]\n> **Solution:** `Ee = 12.72 N/C`\n\n#### <a id=\"sec-example-ef1\"></a>3.4.1. Example EF-1\n\n[Problem A3.b 2021 junio coincidentes](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F4.1-PAU-CampoEl%C3%A9ctrico.pdf)\n\nAt the vertices of a square with a side of 2 m and centered at the origin of coordinates, four electric charges are placed as shown in the figure. If an electron is launched from the center of the square with a velocity v = 3E4 j m/s, obtain the work done by the electric field when the electron leaves the square through the midpoint of the top side.\n\n```\nfrom easyphysi.drivers.body import Body, electron\nfrom easyphysi.drivers.universe import Universe\n\npoint_0 = (0, 0)\npoint_1 = (0, 1)\n\nbody_1 = Body('1')\nbody_1.set('q', 5E-9)\nbody_1.set('p', (-1, +1))\n\nbody_2 = Body('2')\nbody_2.set('q', 5E-9)\nbody_2.set('p', (+1, +1))\n\nbody_3 = Body('3')\nbody_3.set('q', 3E-9)\nbody_3.set('p', (+1, -1))\n\nbody_4 = Body('4')\nbody_4.set('q', 3E-9)\nbody_4.set('p', (-1, -1))\n\nuniverse = Universe()\nuniverse.add_body(body_1)\nuniverse.add_body(body_2)\nuniverse.add_body(body_3)\nuniverse.add_body(body_4)\nuniverse.add_body(electron)\n\nelectron.set('p', point_0)\n\nUe_0 = universe.electrical_potential_energy_equation('electron').solve('Ue')\n\nelectron.set('p', point_1)\n\nUe_1 = universe.electrical_potential_energy_equation('electron').solve('Ue')\n\nW = Ue_0[0] - Ue_1[0] # W = -AUe = Ue_0 - Ue_1\n```\n\n> [!TIP]\n> **Solution:** `W = 1.97E-18 J`\n\n#### <a id=\"sec-example-ef2\"></a>3.4.2. Example EF-2\n\n[Problem A3.b 2023 modelo](https://gitlab.com/fiquipedia/drive.fiquipedia/-/raw/main/content/home/recursos/recursospau/ficherospaufisicaporbloques/F4.1-PAU-CampoEl%C3%A9ctrico.pdf)\n\nA hollow spherical shell with a radius of 3 cm and centered at the origin of coordinates is charged with a uniform surface charge density \u03c3 = 2 \u00b5C/m2. Obtain the work done by the electric field to move a particle with a charge of 1 nC from the point (0, 2, 0) m to the point (3, 0, 0) m.\n\n```\nfrom easyphysi.drivers.body import Body\nfrom easyphysi.drivers.universe import Universe\n\npoint_0 = (0, 2, 0)\npoint_1 = (3, 0, 0)\n\nsphere = Body('sphere', dimensions=3)\nsphere.set('q', 22.62E-9)\nsphere.set('p', (0, 0, 0))\n\npoint = Body('point', dimensions=3)\npoint.set('q', 1E-9)\n\nuniverse = Universe(dimensions=3)\nuniverse.add_body(sphere)\nuniverse.add_body(point)\n\npoint.set('p', point_0)\n\nUe_0 = universe.electrical_potential_energy_equation('point').solve('Ue')\n\npoint.set('p', point_1)\n\nUe_1 = universe.electrical_potential_energy_equation('point').solve('Ue')\n\nW = Ue_0[0] - Ue_1[0] # W = -AEp = Ue_0 - Ue_1\n```\n\n> [!TIP]\n> **Solution:** `W = 3.393E-8 J`\n\n## <a id=\"sec-limitations-bugs\"></a>4. Limitations and bugs\n\n### <a id=\"sec-limitations\"></a>4.0. Limitations\n\n* Trigonometric functions are not able to handle symbols or expressions (for example `math.sin`, `math.cos` or `math.atan2`). Therefore, position unknown (`p`) cannot be solved for the following equations (this error is shown: `TypeError: Cannot convert expression to float`):\n - electrical_field_intensity_equation\n - electrical_force_equation\n - gravitational_field_intensity_equation\n - gravitational_force_equation\n* For the same reason, when defining forces for `newton_equation` with `add_force` method, the angle cannot be set as un unknown as it is usually inside `math.sin` or `math.cos` functions. Fortunately, since the algebraic formula that defines each force is set by the user, arbitrary unknowns can be set instead of `math.sin(alpha)` or `math.cos(alpha)`. Then, easily get the angle with `math.asin` or `math.acos`.\n\n> [!TIP]\n> [Example](#sec-example-d1) uses this workaround to solve the unknown angle in a dynamics problem.\n\n### <a id=\"sec-bugs\"></a>4.1. Bugs\n\nContact the main author if you discover any bug, see [Section](#sec-contact).\n\n## <a id=\"sec-changelog\"></a>5. Changelog\n\nMain changes:\n\n* 25/06/23 - Initial idea\n* 21/12/23 - v1.0.0 first stable version\n* 22/12/23 - v1.0.1 minor changes in README and examples\n\n## <a id=\"sec-licence\"></a>6. License\n\nThis project includes GPL-3.0 License. The GPL-3.0 is a free software license that enforces the copyleft principle, requiring any modifications or derivatives to be distributed under the same terms. It mandates source code availability, compatibility with other open-source licenses, and prohibits additional restrictions. The license promotes equal user rights and addresses patent issues.\n\n## <a id=\"sec-contact\"></a>7. Contact\n\nFeel free to contact mesado31@gmail.com for any suggestion or bug.\n",
"bugtrack_url": null,
"license": "",
"summary": "Physics library to solve pre-universitary physics problems",
"version": "1.0.1",
"project_urls": {
"Homepage": "https://github.com/girdeux31/easyPhysi"
},
"split_keywords": [
"{physics",
"pre-university",
"bachiller",
"uarm",
"kinematics",
"dynamics",
"energy conservation",
"gravitational field",
"electrical field}"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "c26e06b170bb9d325eba7b3ea409c73a850b58f3954c8069d1c70c0bf0cd0a7a",
"md5": "73e2fe1be2b6743233cba359002dfe6b",
"sha256": "e0955c9f868eaafb431104d3421385b21d2fa9fdc38353a3914d1065efd9f5e2"
},
"downloads": -1,
"filename": "easyphysi-1.0.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "73e2fe1be2b6743233cba359002dfe6b",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 41815,
"upload_time": "2023-12-22T17:27:24",
"upload_time_iso_8601": "2023-12-22T17:27:24.939468Z",
"url": "https://files.pythonhosted.org/packages/c2/6e/06b170bb9d325eba7b3ea409c73a850b58f3954c8069d1c70c0bf0cd0a7a/easyphysi-1.0.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "82dda7a94ac865b555e792799083cb9dc33d376ae590d5788675edc25f89adc5",
"md5": "e8ab44dccf70aaae13546b4e66d6bb46",
"sha256": "2325a34f053177f9341017620c4e677f302ec20d59f3222b6fdb3715439c6f9b"
},
"downloads": -1,
"filename": "easyphysi-1.0.1.tar.gz",
"has_sig": false,
"md5_digest": "e8ab44dccf70aaae13546b4e66d6bb46",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 56143,
"upload_time": "2023-12-22T17:27:26",
"upload_time_iso_8601": "2023-12-22T17:27:26.561174Z",
"url": "https://files.pythonhosted.org/packages/82/dd/a7a94ac865b555e792799083cb9dc33d376ae590d5788675edc25f89adc5/easyphysi-1.0.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-22 17:27:26",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "girdeux31",
"github_project": "easyPhysi",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [],
"lcname": "easyphysi"
}