Real-World Examples#

Quantium shines when applied to real-world scientific, engineering, and even everyday problems.

1. Physics: Kinetic Energy#

Quantium supports derived physical quantities automatically. For instance, you can compute kinetic energy.

\[E_k = \frac{1}{2}mv^2\]
from quantium import u

mass = 2 * u.kg
velocity = 3 * u.m / u.s

energy = 0.5 * mass * velocity**2
print(energy)

Quantium recognizes that kg * (m/s)^2 equals Joules (J).

Output:

9.0 J

2. Physics: Potential Energy#

Units are fully preserved through complex mathematical expressions, like calculating gravitational potential energy.

\[E_g = mgh\]
from quantium import u

h = 12 * u.m
g = 9.81 * (u.m / u.s**2)
m = 70 * u.kg

potential_energy = m * g * h
print(potential_energy)
print(potential_energy.to(u.kJ)) # Convert to kilojoules

Output:

8240.4 J
8.2404 kJ

3. Electrical Engineering: Ohm’s Law#

Let’s compute electrical resistance from voltage and current using Ohm’s Law.

\[V = IR\]
from quantium import u

voltage = 12 * u.V
current = 2 * u.A

resistance = voltage / current
print(resistance)

Quantium automatically simplifies V / A into Ohms (Ω).

Output:

6.0 Ω

4. Healthcare: Medical Dosage#

Unit safety is critical in medicine. Imagine a drug dose specified as 15 mg per kg of body weight.

from quantium import u

patient_mass = 75 * u.kg
dose_rate = 15 * (u.mg / u.kg)

required_dose = patient_mass * dose_rate
print(required_dose)

# You can also convert to a different mass unit, like grams
print(required_dose.to(u.g))

Output:

1125.0 mg
1.125 g

Quantium prevents a user from, for example, accidentally multiplying by a mass in pounds without conversion, or by patient height, which would raise a ValueError.

5. Mechanical Engineering: Pressure#

Calculating pressure involves multiple derived units. Let’s find the pressure exerted by a 100 Newton force on a 25 cm² area.

\[P = \frac{F}{A}\]
from quantium import u

force = 100 * u.N
area = 25 * u.cm**2

pressure = force / area

# Auto detects Pa symbol and scale i.e. kPa
print(pressure)

# In standard si unit
print(pressure.si)

# Convert to a different scale
print(pressure.to('uPa'))

Output:

40 kPa
40000 Pa
40000000000 µPa