├── PhysiPy ├── derivations.py ├── Charge.py ├── Mass.py ├── equations.py ├── __init__.py ├── Nlm.py ├── Errors.py ├── Subatomic.py ├── Electricity.py ├── Gravitation.py ├── Mechanics.py ├── Electrostatics.py ├── Waves.py ├── FluidStatePhysics.py ├── SolidStatePhysics.py ├── Thermodynamics.py ├── constants.py ├── Electromagnetism.py └── QuantumMechanics.py ├── MANIFEST.in ├── CHANGELOG.txt ├── requirements.txt ├── dist ├── PhysiPy-1.0.0.tar.gz ├── PhysiPy-2.0.0.tar.gz └── PhysiPy-Python-1.0.0.tar.gz ├── pyproject.toml ├── main.py ├── setup.py ├── LICENSE └── README.md /PhysiPy/derivations.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /MANIFEST.in: -------------------------------------------------------------------------------- 1 | global-include *.txt *.py -------------------------------------------------------------------------------- /CHANGELOG.txt: -------------------------------------------------------------------------------- 1 | 2 | 1.0.0 --> First Release -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | numpy~=1.26.2 2 | setuptools~=57.0.0 -------------------------------------------------------------------------------- /PhysiPy/Charge.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | class Charge: 5 | electron = 1.602 * (math.pow(10, -19)) 6 | -------------------------------------------------------------------------------- /dist/PhysiPy-1.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohankishore/PhysiPy/HEAD/dist/PhysiPy-1.0.0.tar.gz -------------------------------------------------------------------------------- /dist/PhysiPy-2.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohankishore/PhysiPy/HEAD/dist/PhysiPy-2.0.0.tar.gz -------------------------------------------------------------------------------- /dist/PhysiPy-Python-1.0.0.tar.gz: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/rohankishore/PhysiPy/HEAD/dist/PhysiPy-Python-1.0.0.tar.gz -------------------------------------------------------------------------------- /pyproject.toml: -------------------------------------------------------------------------------- 1 | [build-system] 2 | requires = [ 3 | "setuptools>=42", 4 | "wheel", 5 | "numpy" 6 | ] 7 | build-backend = "setuptools.build_meta" -------------------------------------------------------------------------------- /PhysiPy/Mass.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | 4 | class Mass: 5 | electron = 9.1 * (math.pow(10, -31)) 6 | proton = 1.67 * (math.pow(10, -27)) 7 | neutron = 1.67 * (math.pow(10, -27)) 8 | -------------------------------------------------------------------------------- /PhysiPy/equations.py: -------------------------------------------------------------------------------- 1 | from .constants import g 2 | 3 | 4 | def weight(mass): 5 | return mass * g 6 | 7 | 8 | def density(mass, vol): 9 | return mass / vol 10 | 11 | 12 | def volume(length, width, height): 13 | return length * width * height 14 | 15 | 16 | def area(length, width): 17 | return length * width 18 | -------------------------------------------------------------------------------- /PhysiPy/__init__.py: -------------------------------------------------------------------------------- 1 | __all__ = [ 2 | "Charge", 3 | "constants", 4 | "derivations", 5 | "Electricity", 6 | "Electromagnetism", 7 | "Electrostatics", 8 | "Errors", 9 | "equations", 10 | "FluidStatePhysics", 11 | "Gravitation", 12 | "Mass", 13 | "Mechanics", 14 | "Nlm", 15 | "QuantumMechanics", 16 | "SolidStatePhysics", 17 | "Subatomic", 18 | "Thermodynamics", 19 | "Waves" 20 | ] 21 | 22 | 23 | -------------------------------------------------------------------------------- /main.py: -------------------------------------------------------------------------------- 1 | from PhysiPy.Electricity import Electricity 2 | # import math 3 | 4 | 5 | def main(): 6 | print("ran") 7 | 8 | # Setting variables 9 | voltage = 230 10 | resistance = 20 11 | # setting up the class 12 | e = Electricity(voltage=voltage, resistance=resistance) 13 | # retrieving and printing the answer 14 | answer = e.current() 15 | 16 | print(f'{answer:,}') 17 | 18 | 19 | if __name__ == '__main__': 20 | main() 21 | -------------------------------------------------------------------------------- /PhysiPy/Nlm.py: -------------------------------------------------------------------------------- 1 | # from .constants import * 2 | 3 | 4 | class Nlm: 5 | def __init__(self, mass=1, acceleration=1, velocity=1, massofbullet=1, 6 | massofgun=1, initialvelocity=1): 7 | self.mass = mass 8 | self.acceleration = acceleration 9 | self.velocity = velocity 10 | self.massofbullet = massofbullet 11 | self.massofgun = massofgun 12 | self.initialvelocity = initialvelocity 13 | 14 | def force(self): 15 | return self.mass * self.acceleration 16 | 17 | def momentum(self): 18 | return self.mass * self.velocity 19 | 20 | def recoil_velocity(self): 21 | return (self.massofbullet * self.initialvelocity) / self.massofgun 22 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | classifiers = [ 4 | 'Development Status :: 5 - Production/Stable', 5 | 'Intended Audience :: Education', 6 | 'Operating System :: Microsoft :: Windows :: Windows 10', 7 | 'License :: OSI Approved :: MIT License', 8 | 'Programming Language :: Python :: 3' 9 | ] 10 | 11 | setup( 12 | name='PhysiPy', 13 | version='1.0.0', 14 | description='Python Library to Solve Physics Equations', 15 | long_description=open('README.md').read() + '\n\n' + open('CHANGELOG.txt').read(), 16 | url='', 17 | author='Rohan Kishore', 18 | author_email='rohankishore746@gmail.com', 19 | license='MIT', 20 | classifiers=classifiers, 21 | keywords='calculator', 22 | packages=find_packages(), 23 | install_requires=[''] 24 | ) -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Copyright <2023> 2 | 3 | Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: 4 | 5 | The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. 6 | 7 | THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. -------------------------------------------------------------------------------- /PhysiPy/Errors.py: -------------------------------------------------------------------------------- 1 | # from .constants import * 2 | import numpy as np 3 | 4 | 5 | class Errors: 6 | 7 | def __init__(self): 8 | pass 9 | 10 | @staticmethod 11 | def error_muldiv(a, b, c, d): 12 | x = ((a / c) + (b / d)) 13 | return x 14 | 15 | @staticmethod 16 | def error_addsub(a, b): 17 | p = (a + b) 18 | return p 19 | 20 | @staticmethod 21 | def percentage_error(M, E): 22 | print("Percentage Error:", (M / E) * 100, "%") 23 | 24 | @staticmethod 25 | def absolute_error(a, n): 26 | if len(a) == n: 27 | A = np.array(a) 28 | S = np.sum(A) 29 | E = S / n 30 | return E 31 | else: 32 | return ValueError 33 | 34 | @staticmethod 35 | def meanabsolute_error(a, n): 36 | if len(a) == n: 37 | b = [] 38 | for i in a: 39 | b.append(abs(i)) 40 | A = np.array(b) 41 | S = np.sum(A) 42 | M = S / n 43 | return M 44 | else: 45 | print("error try again") 46 | -------------------------------------------------------------------------------- /PhysiPy/Subatomic.py: -------------------------------------------------------------------------------- 1 | # from .constants import * 2 | import math 3 | 4 | 5 | class Subatomic: 6 | def __init__(self, mass=1, mass_parent=1, mass_daughters=1, momentum=1, 7 | atomic_number=1, n=1, initial_amount=1, decay_constant=1, time=1): 8 | self.mass = mass 9 | self.mass_parent = mass_parent 10 | self.mass_daughters = mass_daughters 11 | self.momentum = momentum 12 | self.atomic_number = atomic_number 13 | self.n = n 14 | self.initial_amount = initial_amount 15 | self.decay_constant = decay_constant 16 | self.time = time 17 | 18 | def mass_energy_equivalence(self): 19 | return self.mass * 3e8 ** 2 20 | 21 | def binding_energy(self): 22 | # Energy in electron volts (eV) 23 | return (self.mass_parent - sum(self.mass_daughters)) * 9e16 24 | 25 | def de_broglie_wavelength(self) -> float: 26 | return 6.63e-34 / (self.momentum * self.mass) 27 | 28 | def bohr_radius(self): 29 | # Distance in angstroms (Å) 30 | return 0.529 / self.atomic_number 31 | 32 | def energy_level_hydrogen(self): 33 | # Energy in electron volts (eV) 34 | return -13.6 / (self.n ** 2) 35 | 36 | def radioactive_decay(self): 37 | return self.initial_amount * math.exp(-self.decay_constant * self.time) 38 | 39 | def half_life(self): 40 | return math.log(2) / self.decay_constant 41 | -------------------------------------------------------------------------------- /PhysiPy/Electricity.py: -------------------------------------------------------------------------------- 1 | from .constants import Coulombs_constant 2 | 3 | 4 | class Electricity: 5 | """ 6 | This class is the Electricity Suit. it contains the functions 7 | functions for Electricity calculations. 8 | """ 9 | def __init__(self, voltage=1, current=1, resistance=1, 10 | q1=1, q2=1, r=1) -> None: 11 | self.V = voltage 12 | self.C = current 13 | self.R = resistance 14 | self.k = Coulombs_constant 15 | self.q1 = q1 16 | self.q2 = q2 17 | self.r = r 18 | 19 | def force_electrostatics(self) -> float: 20 | return (self.k * self.q1 * self.q2) / (self.r ** 2) 21 | 22 | def resistance(self) -> float: 23 | if self.C != 0 and self.C is not None: 24 | return self.V / self.C 25 | else: 26 | # Handle division by zero 27 | raise ValueError("Current cannot be zero for resistance calculation.") 28 | 29 | def current(self) -> float: 30 | if self.R != 0 and self.R is not None: 31 | return self.V / self.R 32 | else: 33 | # Handle division by zero 34 | raise ValueError("Resistance cannot be zero for current calculation.") 35 | 36 | def voltage(self) -> float: 37 | return self.C * self.R 38 | 39 | def power(self) -> float: 40 | return self.V * self.C 41 | 42 | def ohms_law(self): 43 | if self.R != 0 and self.R is not None: 44 | return self.V / self.R 45 | else: 46 | # Handle division by zero 47 | raise ValueError("Resistance cannot be zero for ohms law calculation.") 48 | 49 | -------------------------------------------------------------------------------- /PhysiPy/Gravitation.py: -------------------------------------------------------------------------------- 1 | from .constants import g, G, pi 2 | import math 3 | 4 | 5 | class Gravitation: 6 | 7 | def __init__(self, m1=1, m2=1, r=1, M=1, depth=1, area_swept=1, time=1, mass1=1, 8 | mass2=1, mass=1, distance=1, radius=1, 9 | acceleration_due_to_gravity=1, period=1, semi_major_axis=1): 10 | self.m1 = m1 11 | self.m2 = m2 12 | self.r = r 13 | self.M = M 14 | self.depth = depth 15 | self.area_swept = area_swept 16 | self.time = time 17 | self.mass1 = mass1 18 | self.mass2 = mass2 19 | self.mass = mass 20 | self.distance = distance 21 | self.radius = radius 22 | self.acceleration_due_to_gravity = acceleration_due_to_gravity 23 | self.period = period 24 | self.semi_major_axis = semi_major_axis 25 | 26 | def gravity(self): 27 | rsq = self.r * self.r 28 | return G * ((self.m1 * self.m2) / rsq) 29 | 30 | def G_Potential(self): 31 | return (-G * self.M) / self.r 32 | 33 | def g_in_depth(self): 34 | return g * (1 - (self.depth / 6400)) 35 | 36 | def axial_velocity(self): 37 | return self.area_swept / self.time 38 | 39 | def gravitational_force(self): 40 | return G * self.mass1 * self.mass2 / self.distance ** 2 41 | 42 | def gravitational_potential_energy(self): 43 | return -(G * self.mass1 * self.mass2) / self.distance 44 | 45 | def gravitational_field_strength(self): 46 | return G * self.mass / self.distance ** 2 47 | 48 | def escape_velocity(self): 49 | return math.sqrt(2 * G * self.mass / self.radius) 50 | 51 | def orbital_velocity(self): 52 | return math.sqrt(G * self.mass / self.radius) 53 | 54 | def period_of_orbit(self): 55 | return 2 * pi * math.sqrt(self.radius ** 3 / (G * self.mass)) 56 | 57 | def gravitational_potential(self): 58 | return -(G * self.mass) / self.distance 59 | 60 | def weight(self): 61 | return self.mass * self.acceleration_due_to_gravity 62 | 63 | def gravitational_acceleration(self): 64 | return G * self.mass / self.distance ** 2 65 | 66 | def keplers_third_law(self): 67 | return (self.period ** 2) / (self.semi_major_axis ** 3) 68 | -------------------------------------------------------------------------------- /PhysiPy/Mechanics.py: -------------------------------------------------------------------------------- 1 | from .constants import pi 2 | import math 3 | 4 | 5 | class Mechanics: 6 | 7 | def __init__(self, initial_velocity=1, acceleration=1, time=1, final_velocity=1, 8 | mass=1, velocity=1, force=1, displacement=1, angle=0, work=1, 9 | radius=1, period=1, lever_arm=1, angular_displacement=1, 10 | angular_velocity=1): 11 | self.initial_velocity = initial_velocity 12 | self.acceleration = acceleration 13 | self.time = time 14 | self.final_velocity = final_velocity 15 | self.mass = mass 16 | self.velocity = velocity 17 | self.force = force 18 | self.displacement = displacement 19 | self.angle = angle 20 | self.work = work 21 | self.radius = radius 22 | self.period = period 23 | self.lever_arm = lever_arm 24 | self.angular_displacement = angular_displacement 25 | self.angular_velocity = angular_velocity 26 | 27 | def velocity(self): 28 | return self.initial_velocity + self.acceleration * self.time 29 | 30 | def displacement(self): 31 | return self.initial_velocity * self.time + 0.5 * self.acceleration * \ 32 | self.time ** 2 33 | 34 | def acceleration(self): 35 | return (self.final_velocity - self.initial_velocity) / self.time 36 | 37 | def uniform_accelerated_motion(self): 38 | displacement = self.initial_velocity * self.time + 0.5 * self.acceleration * \ 39 | self.time ** 2 40 | final_velocity = self.initial_velocity + self.acceleration * self.time 41 | return displacement, final_velocity 42 | 43 | def force(self): 44 | return self.mass * self.acceleration 45 | 46 | def work(self): 47 | return self.force * self.displacement * math.cos(math.radians(self.angle)) 48 | 49 | def kinetic_energy(self): 50 | return 0.5 * self.mass * self.velocity ** 2 51 | 52 | def potential_energy(self, height, gravitational_field_strength): 53 | return self.mass * height * gravitational_field_strength 54 | 55 | def power(self): 56 | return self.work / self.time 57 | 58 | def momentum(self): 59 | return self.mass * self.velocity 60 | 61 | def impulse(self): 62 | return self.force * self.time 63 | 64 | def circular_velocity(self): 65 | return 2 * pi * self.radius / self.period 66 | 67 | def centripetal_acceleration(self): 68 | return self.velocity ** 2 / self.radius 69 | 70 | def torque(self): 71 | return self.force * self.lever_arm 72 | 73 | def angular_velocity(self): 74 | return self.angular_displacement / self.time 75 | 76 | def angular_acceleration(self): 77 | return self.angular_velocity / self.time 78 | -------------------------------------------------------------------------------- /PhysiPy/Electrostatics.py: -------------------------------------------------------------------------------- 1 | from .constants import Coulombs_constant 2 | 3 | 4 | class Electrostatics: 5 | 6 | def __init__(self, distance=1, charge=1, charge_1=1, charge_2=1, voltage=1, time=1, 7 | current=1, force=1, velocity=1, length=1, charge_enclosed=1, 8 | epsilon_0=1, emf=1, electric_field=1, magnetic_field=1, 9 | resistance=1, charge_carrier_density=1, thickness=1, 10 | cross_sectional_area=1) -> None: 11 | self.distance = distance 12 | self.charge = charge 13 | self.c_1 = charge_1 14 | self.c_2 = charge_2 15 | self.voltage = voltage 16 | self.time = time 17 | self.current = current 18 | self.force = force 19 | self.velocity = velocity 20 | self.length = length 21 | self.charge_enclosed = charge_enclosed 22 | self.epsilon_0 = epsilon_0 23 | self.emf = emf 24 | self.electric_field1 = electric_field 25 | self.magnetic_field1 = magnetic_field 26 | self.r = resistance 27 | self.charge_carrier_density = charge_carrier_density 28 | self.thickness = thickness 29 | self.cross_sectional_area = cross_sectional_area 30 | 31 | def electric_force(self): 32 | return Coulombs_constant * self.c_1 * self.c_2 / self.distance ** 2 33 | 34 | def electric_field(self): 35 | return Coulombs_constant * self.charge / self.distance ** 2 36 | 37 | def electric_potential(self): 38 | return Coulombs_constant * self.charge / self.distance 39 | 40 | def capacitance(self): 41 | return self.charge / self.voltage 42 | 43 | def electric_current(self): 44 | return self.charge / self.time 45 | 46 | def resistance(self): 47 | return self.voltage / self.current 48 | 49 | def ohms_law(self): 50 | return self.voltage / self.current 51 | 52 | def coulombs_law(self): 53 | return self.electric_field1 * self.charge 54 | 55 | def gauss_law(self): 56 | return self.charge_enclosed / self.epsilon_0 57 | 58 | def faradays_law(self): 59 | return self.emf * self.time 60 | 61 | def magnetic_field(self): 62 | return self.force / (self.charge * self.velocity) 63 | 64 | def lorentz_force(self): 65 | return self.charge * self.velocity * self.magnetic_field1 66 | 67 | def hall_voltage(self): 68 | return (self.magnetic_field1 * self.current) / \ 69 | (self.charge_carrier_density * self.thickness) 70 | 71 | def drift_velocity(self): 72 | return self.current / (self.charge * self.charge_carrier_density * 73 | self.cross_sectional_area) 74 | 75 | def resistivity(self): 76 | return self.r * (self.cross_sectional_area / self.length) 77 | 78 | @staticmethod 79 | def series_resistance(*resistances): 80 | return sum(resistances) 81 | 82 | @staticmethod 83 | def parallel_resistance(*resistances): 84 | return 1 / sum(1 / r for r in resistances) 85 | -------------------------------------------------------------------------------- /PhysiPy/Waves.py: -------------------------------------------------------------------------------- 1 | from .constants import pi 2 | import math 3 | 4 | 5 | class Waves: 6 | 7 | def __init__(self, frequency=1, wavelength=1, period=1, power=1, area=1, 8 | sound_power=1, intensity=1, frequency1=1, frequency2=1, 9 | velocity_wave=1, velocity_observer=1, velocity_source=1, 10 | real_depth=1, apparent_depth=1): 11 | self.frequency = frequency 12 | self.wavelength = wavelength 13 | self.period = period 14 | self.power = power 15 | self.area = area 16 | self.sound_power = sound_power 17 | self.intensity = intensity 18 | self.frequency1 = frequency1 19 | self.frequency2 = frequency2 20 | self.velocity_wave = velocity_wave 21 | self.velocity_observer = velocity_observer 22 | self.velocity_source = velocity_source 23 | self.real_depth = real_depth 24 | self.apparent_depth = apparent_depth 25 | 26 | def wave_velocity(self): 27 | return self.frequency * self.wavelength 28 | 29 | def angular_frequency(self): 30 | return 2 * pi * self.frequency 31 | 32 | def wave_period(self): 33 | return 1 / self.frequency 34 | 35 | def wave_number(self): 36 | return 2 * pi / self.wavelength 37 | 38 | def wave_speed(self): 39 | return self.wavelength / self.period 40 | 41 | def longitudinal_wave_speed(self): 42 | return self.frequency * self.wavelength 43 | 44 | def intensity(self): 45 | return self.power / self.area 46 | 47 | def sound_intensity(self): 48 | return self.sound_power / self.area 49 | 50 | def sound_level(self): 51 | return 10 * math.log10(self.intensity / (10 ** -12)) 52 | 53 | def beats_frequency(self): 54 | return abs(self.frequency1 - self.frequency2) 55 | 56 | def beats_period(self): 57 | return 1 / abs(self.frequency1 - self.frequency2) 58 | 59 | def doppler_frequency(self): 60 | return self.frequency * (self.velocity_wave + self.velocity_observer) / \ 61 | (self.velocity_wave - self.velocity_source) 62 | 63 | def doppler_wavelength(self): 64 | return self.wavelength * (self.velocity_wave - self.velocity_source) / \ 65 | (self.velocity_wave + self.velocity_observer) 66 | 67 | def refractive_index(self): 68 | return self.real_depth / self.apparent_depth 69 | 70 | 71 | """ 72 | You have both an instance variable named intensity and a method with the same name (intensity). 73 | This can lead to confusion and potential bugs. Consider renaming either the instance variable or 74 | the method to avoid conflicts. 75 | 76 | python 77 | 78 | def wave_intensity(self): 79 | return self.power / self.area 80 | 81 | def sound_intensity(self): 82 | return self.sound_power / self.area 83 | 84 | Redundant Intensity Method: 85 | You have two methods calculating intensity: wave_intensity and sound_intensity. Since these seem to serve 86 | similar purposes, you might want to consider consolidating them into a single method or providing a clearer 87 | distinction between the two. 88 | 89 | def intensity(self, sound=False): 90 | if sound: 91 | return self.sound_power / self.area 92 | else: 93 | return self.power / self.area 94 | """ 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 |

PhysiPy

2 | 3 |

Physics Equation Solver and Constants for Python

4 | 5 |
6 | 7 | ![License](https://img.shields.io/badge/Install-PyPI-blue) 8 | ![License](https://img.shields.io/badge/License-MIT-yellow) 9 | ![Demo](https://img.shields.io/badge/Fiverr-Hire-green) 10 |
11 | 12 | PhysiPy is a powerful and versatile Python library designed to streamline physics calculations and provide easy access to a vast collection of essential physical constants. Whether you are a student, researcher, or an enthusiast seeking to explore the intricacies of the physical world, PhysiPy is an indispensable tool for your scientific endeavors. 13 | 14 | With PhysiPy, you can effortlessly perform complex physics computations without the need for extensive manual coding. The library encompasses a wide range of formulas and equations spanning various branches of physics, including mechanics, electromagnetism, thermodynamics, quantum mechanics, and more. From simple kinematic equations to intricate quantum mechanical wavefunctions, PhysiPy has you covered, simplifying the process of implementing these calculations into your code. 15 | 16 | One of the key features of PhysiPy is its extensive collection of physical constants. It contains hundreds of well-documented and up-to-date constants that are crucial for numerous calculations and experiments. These constants encompass fundamental values such as the speed of light, Planck's constant, elementary charge, Avogadro's number, and many more. By having this wealth of constants readily available, PhysiPy eliminates the need to search for and manually input these values, ensuring accuracy and efficiency in your calculations. 17 | 18 |
19 | 20 |
21 | 22 | PhysiPy API is currently in development by [Vikram Samak](https://github.com/vikramsamak) and can be found [here](https://github.com/vikramsamak/PhsiPy-Api) 23 |
24 | 25 |
26 | 27 |

⬇️ Installation

28 | 29 |
30 | 31 | ```bash 32 | pip install PhysiPy-Python 33 | ``` 34 | 35 |
36 | 37 |

You can also install it via the given .targz file. Here are the steps:

38 | 39 |
40 | 41 | - Download the `PhysiPy-1.0.0.tar.gz` file from the `dist` folder in the repository 42 | - Now, copy the path of the downloaded `.tar.gz` file 43 | - Open Terminal and type in the following command: 44 | ` pip install ` 45 | 46 |
47 | 48 |

⭐ Features in a Glance

49 | 50 | - Over 100 pre-defined Physics Equations (Just substitute the values inside function) 51 | - Over 150+ constants (including Boltzmann Constant, Gravitational Constants, and much more) 52 | - Extremely quick since its uses Numpy 53 | 54 |
55 | 56 |

🧑🏻‍💻 Demo Snippets

57 | 58 |
59 | 60 | ```python 61 | # to calculate resistance 62 | 63 | import PhysiPy.Electricity as ec 64 | 65 | a = ec.resistance(25, 10) 66 | print(a) 67 | 68 | >> 2.5 69 | ``` 70 | 71 |
72 | 73 | ```python 74 | # to calculate gravitational potential 75 | 76 | import PhysiPy.Gravitation as gr 77 | 78 | a = gr.gravitational_acceleration(25, 1200) 79 | print(a) 80 | 81 | >> 1.1586944444444442e^-15 82 | ``` 83 | 84 |

❣️ Used by:

85 | 86 | - [Out-of-the-Box-Astronautics-LLC](https://github.com/Out-of-the-Box-Astronautics-LLC/) for their [Lunar Lander project](https://github.com/Out-of-the-Box-Astronautics-LLC/StrongBox) 87 | -------------------------------------------------------------------------------- /PhysiPy/FluidStatePhysics.py: -------------------------------------------------------------------------------- 1 | from .constants import pi, speed_of_sound, gas_constant 2 | import math 3 | 4 | 5 | class FluidStatePhysics: 6 | 7 | def __init__(self, density=1, acceleration_due_to_gravity=1, height=1, 8 | surface_tension_coefficient=1, contact_angle=1, radius_of_curvature=1, 9 | static_pressure=1, dynamic_pressure=1, gravitational_acceleration=1, 10 | flow_rate=1, viscosity=1, length=1, radius=1, surface_tension=1, 11 | velocity=1, drag_force=1, particle_radius=1, volume_change=1, 12 | initial_volume=1, pressure_change=1, initial_pressure=1, 13 | final_pressure=1, final_volume=1, initial_temperature=1, 14 | final_temperature=1, initial_moles=1, final_moles=1, pressure=1, 15 | v=1, temperature=1): 16 | self.density = density 17 | self.acceleration_due_to_gravity = acceleration_due_to_gravity 18 | self.height = height 19 | self.surface_tension_coefficient = surface_tension_coefficient 20 | self.contact_angle = contact_angle 21 | self.radius_of_curvature = radius_of_curvature 22 | self.static_pressure = static_pressure 23 | self.dynamic_pressure = dynamic_pressure 24 | self.gravitational_acceleration = gravitational_acceleration 25 | self.flow_rate = flow_rate 26 | self.viscosity = viscosity 27 | self.length = length 28 | self.radius = radius 29 | self.surface_tension = surface_tension 30 | self.velocity = velocity 31 | self.drag_force = drag_force 32 | self.particle_radius = particle_radius 33 | self.volume_change = volume_change 34 | self.initial_volume = initial_volume 35 | self.pressure_change = pressure_change 36 | self.initial_pressure = initial_pressure 37 | self.final_pressure = final_pressure 38 | self.final_volume = final_volume 39 | self.initial_temperature = initial_temperature 40 | self.final_temperature = final_temperature 41 | self.initial_moles = initial_moles 42 | self.final_moles = final_moles 43 | self.pressure = pressure 44 | self.v = v 45 | self.temperature = temperature 46 | 47 | def hydrostatic_pressure(self): 48 | return self.density * self.acceleration_due_to_gravity * self.height 49 | 50 | def surface_tension(self): 51 | return self.surface_tension_coefficient * math.cos(self.contact_angle) / \ 52 | self.radius_of_curvature 53 | 54 | def capillary_pressure(self): 55 | return 2 * self.surface_tension / self.radius_of_curvature 56 | 57 | def bernoullis_equation(self): 58 | return self.static_pressure + self.dynamic_pressure + self.density * \ 59 | self.gravitational_acceleration * self.height 60 | 61 | def poiseuilles_law(self): 62 | return (pi * self.radius ** 4 * self.flow_rate) / \ 63 | (8 * self.viscosity * self.length) 64 | 65 | def reynolds_number(self): 66 | return (self.density * self.velocity * self.length) / self.viscosity 67 | 68 | def stokes_law(self): 69 | return (6 * pi * self.viscosity * self.particle_radius) / self.drag_force 70 | 71 | def mach_number(self): 72 | return self.velocity / speed_of_sound 73 | 74 | def compressibility_factor(self): 75 | return self.volume_change / (self.initial_volume * self.pressure_change) 76 | 77 | def boyles_law(self): 78 | return (self.initial_pressure * self.initial_volume) / \ 79 | (self.final_pressure * self.final_volume) 80 | 81 | def charles_law(self): 82 | return (self.initial_volume * self.final_temperature) / \ 83 | (self.final_volume * self.initial_temperature) 84 | 85 | def gaylussacs_law(self): 86 | return (self.initial_pressure * self.final_temperature) / \ 87 | (self.final_pressure * self.initial_temperature) 88 | 89 | def avogadros_law(self): 90 | return (self.initial_volume * self.final_moles) / \ 91 | (self.final_volume * self.initial_moles) 92 | 93 | def ideal_gas_law(self): 94 | return (self.pressure * self.v) / (gas_constant * self.temperature) 95 | -------------------------------------------------------------------------------- /PhysiPy/SolidStatePhysics.py: -------------------------------------------------------------------------------- 1 | from .constants import plancks_constant, Coulombs_constant, boltzmann_constant 2 | import math 3 | from .Mass import Mass 4 | from .Charge import Charge 5 | 6 | 7 | class SolidStatePhysics: 8 | 9 | def __init__(self, resistance=1, cross_sectional_area=1, length=1, hall_voltage=1, 10 | current=1, magnetic_field=1, thickness=1, hall_coefficient=1, 11 | electron_charge=1, electron_density=1, work_function=1, fermi_energy=1, 12 | temperature=1, kinetic_energy=1, potential_energy=1, 13 | intrinsic_fermi_level=1, donor_density=1, acceptor_density=1, 14 | potential_difference=1, power_output=1, light_power_input=1, 15 | material_density=1, specific_heat_capacity=1, temperature_change=1, 16 | stress=1, strain=1, transverse_strain=1, longitudinal_strain=1, 17 | heat_flux=1, temperature_gradient=1, critical_field=1, 18 | hamiltonian_operator=1): 19 | self.r = resistance 20 | self.cross_sectional_area = cross_sectional_area 21 | self.length = length 22 | self.hall_voltage = hall_voltage 23 | self.C = current 24 | self.magnetic_field = magnetic_field 25 | self.thickness = thickness 26 | self.hall_coefficient = hall_coefficient 27 | self.electron_charge = electron_charge 28 | self.electron_density = electron_density 29 | self.work_function = work_function 30 | self.fermi_energy = fermi_energy 31 | self.temperature = temperature 32 | self.kinetic_energy = kinetic_energy 33 | self.potential_energy = potential_energy 34 | self.intrinsic_fermi_level = intrinsic_fermi_level 35 | self.donor_density = donor_density 36 | self.acceptor_density = acceptor_density 37 | self.potential_difference = potential_difference 38 | self.power_output = power_output 39 | self.light_power_input = light_power_input 40 | self.material_density = material_density 41 | self.specific_heat_capacity = specific_heat_capacity 42 | self.temperature_change = temperature_change 43 | self.stress = stress 44 | self.strain = strain 45 | self.transverse_strain = transverse_strain 46 | self.longitudinal_strain = longitudinal_strain 47 | self.heat_flux = heat_flux 48 | self.temperature_gradient = temperature_gradient 49 | self.critical_field = critical_field 50 | self.hamiltonian_operator = hamiltonian_operator 51 | 52 | def electrical_resistivity(self): 53 | return self.r * (self.cross_sectional_area / self.length) 54 | 55 | def hall_effect(self): 56 | return (self.hall_voltage * self.thickness) / (self.C * self.magnetic_field) 57 | 58 | def electron_mobility(self): 59 | return self.hall_coefficient / (self.electron_charge * self.electron_density) 60 | 61 | def fermi_energy(self): 62 | return (self.electron_density * (plancks_constant ** 2)) / \ 63 | (2 * Mass.electron) + self.work_function 64 | 65 | def band_gap(self): 66 | return 2 * boltzmann_constant * self.temperature * math.log(2) - \ 67 | self.fermi_energy 68 | 69 | def energy_band(self): 70 | return self.kinetic_energy + self.potential_energy 71 | 72 | def energy_band_conduction(self): 73 | return self.fermi_energy - self.intrinsic_fermi_level 74 | 75 | def intrinsic_carrier_concentration(self): 76 | return ((self.donor_density * self.acceptor_density) ** 0.5) * \ 77 | math.exp(-(self.fermi_energy - self.intrinsic_fermi_level) / 78 | (2 * boltzmann_constant * self.temperature)) 79 | 80 | def depletion_layer_width(self): 81 | return math.sqrt((2 * Coulombs_constant * self.potential_difference) / ( 82 | Charge.electron * self.electron_density)) / (2 * self.fermi_energy) 83 | 84 | def solar_cell_efficiency(self): 85 | return (self.power_output / self.light_power_input) * 100 86 | 87 | def energy_density(self): 88 | return self.material_density * self.specific_heat_capacity * \ 89 | self.temperature_change 90 | 91 | def youngs_modulus(self): 92 | return self.stress / self.strain 93 | 94 | def poisson_ratio(self): 95 | return -self.transverse_strain / self.longitudinal_strain 96 | 97 | def thermal_conductivity(self): 98 | return self.heat_flux * self.thickness / (self.temperature_gradient * 99 | self.cross_sectional_area) 100 | 101 | def superconductivity_critical_temperature(self): 102 | return (self.critical_field ** 2) * ( 103 | Coulombs_constant / (2 * Mass.electron * Charge.electron)) 104 | 105 | def superconductivity_coherence_length(self): 106 | return (plancks_constant / (2 * math.pi)) * ((3 * Coulombs_constant * 107 | (self.hamiltonian_operator ** 2)) / (2 * Mass.electron * 108 | self.fermi_energy)) ** 0.5 109 | -------------------------------------------------------------------------------- /PhysiPy/Thermodynamics.py: -------------------------------------------------------------------------------- 1 | from .constants import boltzmann_constant, stefan_boltzmann_constant 2 | import math 3 | 4 | 5 | class Thermodynamics: 6 | 7 | def __init__(self, celsius=1, kelvin=1, heat_added=1, work_done=1, 8 | change_in_internal_energy=1, pressure=1, volume=1, temperature=1, 9 | change_in_length=1, original_length=1, change_in_temperature=1, 10 | thermal_conductivity=1, area=1, temperature_difference=1, thickness=1, 11 | molar_mass=1, gamma=1, mass=1, heat_transfer=1, temperature_change=1, 12 | temperature_hot=1, temperature_cold=1, heat_rejected=1, 13 | volume_initial=1, volume_final=1, heat_transfer_coefficient=1, 14 | emissivity=1, temperature1=1, temperature2=1, temperature_reservoir=1, 15 | reversible_entropy_change=1): 16 | self.celsius = celsius 17 | self.kelvin = kelvin 18 | self.heat_added = heat_added 19 | self.heat_rejected = heat_rejected 20 | self.work_done = work_done 21 | self.change_in_internal_energy = change_in_internal_energy 22 | self.pressure = pressure 23 | self.volume = volume 24 | self.temperature = temperature 25 | self.change_in_length = change_in_length 26 | self.original_length = original_length 27 | self.change_in_temperature = change_in_temperature 28 | self.thermal_conductivity = thermal_conductivity 29 | self.area = area 30 | self.temperature_difference = temperature_difference 31 | self.thickness = thickness 32 | self.molar_mass = molar_mass 33 | self.gamma = gamma 34 | self.mass = mass 35 | self.heat_transfer = heat_transfer 36 | self.temperature_change = temperature_change 37 | self.temperature_hot = temperature_hot 38 | self.temperature_cold = temperature_cold 39 | self.volume_initial = volume_initial 40 | self.volume_final = volume_final 41 | self.heat_transfer_coefficient = heat_transfer_coefficient 42 | self.emissivity = emissivity 43 | self.temperature1 = temperature1 44 | self.temperature2 = temperature2 45 | self.temperature_reservoir = temperature_reservoir 46 | self.reversible_entropy_change = reversible_entropy_change 47 | 48 | def convert_celsius_to_kelvin(self) -> float: 49 | """Convert temperature from Celsius to Kelvin.""" 50 | return self.celsius + 273.15 51 | 52 | def convert_kelvin_to_celsius(self) -> float: 53 | """Convert temperature from Kelvin to Celsius.""" 54 | return self.kelvin - 273.15 55 | 56 | def ideal_gas_law(self) -> float: 57 | return (self.pressure * self.volume) / (boltzmann_constant * self.temperature) 58 | 59 | def thermal_expansion_coefficient(self) -> float: 60 | return self.change_in_length / (self.original_length * 61 | self.change_in_temperature) 62 | 63 | def heat_transfer_conduction(self) -> float: 64 | return (self.thermal_conductivity * self.area * self.temperature_difference) / \ 65 | self.thickness 66 | 67 | def heat_transfer_convection(self) -> float: 68 | return self.heat_transfer_coefficient * self.area * self.temperature_difference 69 | 70 | def heat_transfer_radiation(self) -> float: 71 | return self.emissivity * stefan_boltzmann_constant * self.area * \ 72 | (self.temperature1 ** 4 - self.temperature2 ** 4) 73 | 74 | def is_first_law_satisfied(self) -> bool: 75 | return self.first_law_thermodynamics() == self.change_in_internal_energy 76 | 77 | def first_law_thermodynamics(self) -> float: 78 | return self.heat_added + self.work_done 79 | 80 | def efficiency_carnot(self) -> float: 81 | return 1 - self.temperature_cold / self.temperature_hot 82 | 83 | def efficiency_heat_engine(self) -> float: 84 | return (self.heat_added - self.heat_rejected) / self.heat_added 85 | 86 | def entropy_change(self) -> float: 87 | return self.heat_transfer / self.temperature 88 | 89 | def entropy_change_irreversible(self) -> float: 90 | return self.heat_transfer / self.temperature_reservoir 91 | 92 | def entropy_change_adiabatic(self) -> float: 93 | return self.reversible_entropy_change - self.heat_transfer / \ 94 | self.temperature_reservoir 95 | 96 | def entropy_change_phase(self) -> float: 97 | return self.heat_transfer / self.temperature 98 | 99 | def work_done_by_ideal_gas(self) -> float: 100 | return self.pressure * (self.volume_final - self.volume_initial) 101 | 102 | def root_mean_square_speed(self) -> float: 103 | return math.sqrt((3 * boltzmann_constant * self.temperature) / self.molar_mass) 104 | 105 | def average_kinetic_energy(self) -> float: 106 | return (3 / 2) * boltzmann_constant * self.temperature 107 | 108 | def average_kinetic_energy_with_molar_mass(self) -> float: 109 | return (3 / 2) * boltzmann_constant * self.molar_mass * self.temperature 110 | 111 | def speed_of_sound(self) -> float: 112 | return math.sqrt(self.gamma * boltzmann_constant * self.temperature / 113 | self.molar_mass) 114 | 115 | def specific_heat_capacity(self) -> float: 116 | return self.heat_transfer / (self.mass * self.temperature_change) 117 | 118 | def latent_heat(self) -> float: 119 | return self.heat_transfer / self.mass 120 | -------------------------------------------------------------------------------- /PhysiPy/constants.py: -------------------------------------------------------------------------------- 1 | import math 2 | 3 | """ 4 | All the Constants related to Physics. Please note that some values might be slightly rounded off 5 | This will include constants that you may use in high school, or in Engineering, or even in Research 6 | purposes. 7 | """ 8 | 9 | algebraic_e_constant = 1.2267420107203532440737592638312 10 | apery_constant = 1.2020569031595942853997381615114499 11 | aperys_constant = 1.20205690315959428539973816151 12 | archimedes_constant = 3.1415926535897932384626433832795029 13 | archimedes_gamma_constant = 0.7052302 14 | arithmetic_geometric_mean = 1.22674201072035324407375926383 15 | avogadros_number = 6.02214076 * (math.pow(10, 23)) 16 | baker_constant = 0.83537042199356152457307680379 17 | bernstein_constant = 0.28016949902386913303 18 | bernstein_khinchin_constant = 0.5 19 | bohr_radius = 0.0529 20 | boltzmann_constant = 1.38064 * (math.pow(10, -23)) 21 | brickman_constant = 0.66016181584686957392781211001455577 22 | bronze_ratio = (1 + math.sqrt(5)) / 2 23 | bronze_ratio_squared = bronze_ratio ** 2 24 | bruns_constant = 1.902160582 25 | cahens_constant = 0.6434105463 26 | carlson_levin_constant = 1.7084245511 27 | catalan_constant = 0.915965594177219015054603514 28 | catalans_constant = 0.9159655941772190150546035149323841107741493742816721342664983151681 29 | compton_wavelength = 2.42 * (math.pow(10, -12)) 30 | conway_chambers_constant = 1.303577269034296391257099112152551890730702504659404875754861390628550 31 | conway_constant = 1.30357726903429639125709911215 32 | copeland_erdos_constant = 0.2357111317192329318812 33 | cos_constant = 0.739085133215 34 | Coulombs_constant = 8.9875e9 35 | e = 2.718281828459045 36 | earth_radius = 6.371 * (math.pow(10, 6)) 37 | electron_mass = 9.10938356 * (math.pow(10, -31)) 38 | elementary_charge = 1.602176634 * (math.pow(10, -19)) 39 | epsilon0 = 8.854187817 * (math.pow(10, -12)) 40 | erdos_borwein_constant = 1.6066951524152917637833015231909246 41 | euler_constant = 0.577215664901532860606512090082 42 | euler_gamma_constant = 0.57721566490153286060651209008240243 43 | euler_mascheroni_constant = 0.57721566490153286060651209 44 | euler_mascheroni_squared = euler_mascheroni_constant ** 2 45 | faraday_constant = 96485 46 | feigenbaum_constant_alpha = 2.5029078750958928222839028732182158 47 | feigenbaum_constant_delta = 4.66920160910299067185320382 48 | finestructure_constant = 0.007297351 49 | G = 6.67408 * (math.pow(10, -11)) 50 | g = 9.8 51 | gamma_constant = 0.57721566490153286060651209008240243 52 | gas_constant = 8.31446261815324 53 | gelfond_schneider_constant = 2.6651441426902251886502972498731 54 | gelfonds_constant = 23.1406926327792690057290863679 55 | glaisher_constant = 1.28242712910062263687534256887 56 | glaisher_kinkelin_constant = 1.28242712910062263687534256887 57 | glaisher_meissel_constant = 1.2824271291006226368753425688772935 58 | glivenko_cantelli_constant = 0.5 59 | golden_ratio = (1 + math.sqrt(5)) / 2 60 | golden_ratio_squared = golden_ratio ** 2 61 | gompertz_constant = 0.596347362323194074341078499369 62 | hafner_sarnak_mccurley_constant = 0.35323637185499598454 63 | heronian_mean = 0.8760246 64 | isoperimetric_constant = 3.54490770181103 65 | kepler_bouwkamp_constant = 1.8540746773013719188198983295688709 66 | khinchin_constant = 2.68545200106530644530971483548 67 | khinchin_constant_squared = khinchin_constant ** 2 68 | khinchin_levy_constant = 2.6854520010653064453097148354817957 69 | komornik_constant = 0.9899494937 70 | komornik_loridan_constant = 0.874464368 71 | komornik_lynd_constant = 1.78723165028901 72 | landau_constant = 0.5 73 | landau_ramanujan_constant = 0.76422365358922066299069873125 74 | landau_ramunjan_constant = 0.76422365358922066299069873125 75 | lebesgue_constant = 0.6316275 76 | levy_constant = 3.27582291872181115978768188284 77 | lindemann_constant = 2.7182818284590452353602874713526624 78 | liouville_constant = 0.110001000000000000000001000000000001 79 | liouville_number = 0.110001000000000000000001000000000001 80 | liouville_sine_constant = 1.317925323 81 | lucas_lehmer_constant = 4.66920160910299067185320382 82 | lyapunov_constant = 0.935 83 | meissel_mertens_constant = 0.2614972128476427837554268 84 | mertens_constant = 0.26149721284764278375542683861 85 | mertens_second_constant = 0.56714329040978387299996866 86 | mills_constant = 1.30637788386308069046861449260 87 | mills_ratio = 1.3063778838630806904686144926026057 88 | minkowski_constant = 0.5 89 | neper_constant = 2.7182818284590452353602874713526624 90 | neutron_mass = 1.674927471 * (math.pow(10, -27)) 91 | omega_constant = 0.56714329040978387299996866221 92 | perrin_constant = 2.905264780 93 | pi = 3.141592653589793 94 | pi_squared = pi ** 2 95 | plancks_constant = 6.62607015 * (math.pow(10, -34)) 96 | plank_length = 1.616229 * (math.pow(10, -35)) 97 | plastic_constant = 1.324717957244746025960908854 98 | plastic_constant_squared = plastic_constant ** 2 99 | plastic_number = (1 + math.sqrt(5)) / 2 100 | plastic_ratio = (1 + math.sqrt(17)) / 2 101 | plastic_ratio_squared = plastic_ratio ** 2 102 | proton_mass = 1.672621898 * (math.pow(10, -27)) 103 | ramanujan_soldner_constant = 1.4513692348833810502839684858920274 104 | random_gaussian_constant = 0.3989422804014327 105 | robins_constant = 0.187859 106 | sierpinski_carpet_constant = 1.78723165028901 107 | sierpinski_constant = 2.58498175957925321706589358738 108 | sierpinski_sieve_constant = 2.996161 109 | sierpinski_sieve_constant_2 = 2.996161 110 | sierpinski_triangle_constant = 2.45 111 | silver_ratio = (1 + math.sqrt(2)) / 2 112 | silver_ratio_squared = silver_ratio ** 2 113 | sinh_constant = 1.258718 114 | smarandache_constant = 0.991869 115 | sophomore_lothar_constant = 0.6617071822552510210673752 116 | speed_of_light = 3 * (math.pow(10, 8)) 117 | speed_of_sound = 330 118 | speed_of_sound_air = 343 119 | stefan_boltzmann_constant = 5.670374419 * (math.pow(10, -8)) 120 | thomson_crosssection = 6.6524 * (math.pow(10, -29)) 121 | thue_constant = 0.5 122 | thue_morse_constant = 0.412454033640171141183775 123 | tritrophic_constant = 1.46557123187676802666489597912 124 | twin_prime_constant = 0.660161815846869573927812110014 125 | viswanath_constant = 1.13198824879433485854393999994 126 | vonklitzing_constant = 25812.80745 127 | -------------------------------------------------------------------------------- /PhysiPy/Electromagnetism.py: -------------------------------------------------------------------------------- 1 | from .constants import pi, epsilon0, vonklitzing_constant, plancks_constant, \ 2 | compton_wavelength 3 | from .constants import finestructure_constant, Coulombs_constant, elementary_charge, \ 4 | speed_of_light 5 | import math 6 | import numpy as np 7 | from .Mass import Mass 8 | 9 | 10 | class Electromagnetism: 11 | 12 | def __init__(self, current=1, voltage=1, resistance=1, area=1, length=1, distance=1, 13 | charge=1, force=1, magnetic_flux=1, initial_wavelength=1, 14 | scattering_angle=1, magnetic_flux_density=1, magnetic_field_strength=1, 15 | velocity=1, charge_density=1, electron_density=1, induced_emf=1, 16 | time=1, number_of_turns=1, inductance=1, current_rate_of_change=1, 17 | charge1=1, charge2=1, principal_quantum_number=1, momentum=1, 18 | fermi_level=1, mass=1, elementary_charge1=1, change_in_magnetic_flux=1, 19 | magnetic_field=1, gravitational_field_strength=1, mu0=1, n1=1, n2=1, 20 | angle_of_incidence=1, hv=1, threshold_frequency=1, work_function=1, 21 | stopping_potential=1, initial_quantity=1, decay_constant=1, 22 | mass_defect=1, final_quantity=1) -> None: 23 | self.current = current 24 | self.voltage = voltage 25 | self.resistance = resistance 26 | self.area = area 27 | self.length = length 28 | self.distance = distance 29 | self.charge = charge 30 | self.force = force 31 | self.magnetic_flux = magnetic_flux 32 | self.initial_wavelength = initial_wavelength 33 | self.scattering_angle = scattering_angle 34 | self.magnetic_flux_density = magnetic_flux_density 35 | self.magnetic_field_strength = magnetic_field_strength 36 | self.velocity = velocity 37 | self.charge_density = charge_density 38 | self.electron_density = electron_density 39 | self.induced_emf = induced_emf 40 | self.time = time 41 | self.number_of_turns = number_of_turns 42 | self.inductance = inductance 43 | self.current_rate_of_change = current_rate_of_change 44 | self.charge1 = charge1 45 | self.charge2 = charge2 46 | self.principal_quantum_number = principal_quantum_number 47 | self.momentum = momentum 48 | self.fermi_level = fermi_level 49 | self.mass = mass 50 | self.elementary_charge1 = elementary_charge1 51 | self.change_in_magnetic_flux = change_in_magnetic_flux 52 | self.magnetic_field = magnetic_field 53 | self.gravitational_field_strength = gravitational_field_strength 54 | self.mu0 = mu0 55 | self.n1 = n1 56 | self.n2 = n2 57 | self.angle_of_incidence = angle_of_incidence 58 | self.hv = hv 59 | self.threshold_frequency = threshold_frequency 60 | self.work_function = work_function 61 | self.stopping_potential = stopping_potential 62 | self.initial_quantity = initial_quantity 63 | self.decay_constant = decay_constant 64 | self.mass_defect = mass_defect 65 | self.final_quantity = final_quantity 66 | 67 | def resistivity(self): 68 | return (self.resistance * self.area) / self.length 69 | 70 | def electric_field(self): 71 | return self.voltage / self.distance 72 | 73 | def electric_potential_energy(self): 74 | return self.charge * self.voltage 75 | 76 | def magnetic_field_strength(self): 77 | return self.force / (self.length * self.current) 78 | 79 | def magnetic_flux_density(self): 80 | return self.magnetic_flux / self.area 81 | 82 | def magnetic_flux(self): 83 | return self.magnetic_flux_density * self.area 84 | 85 | def magnetic_force(self): 86 | return self.magnetic_field_strength * self.length * self.current 87 | 88 | def lorentz_force(self): 89 | return self.charge * self.magnetic_field_strength * self.velocity 90 | 91 | def hall_voltage(self): 92 | return (self.magnetic_field_strength * self.current) / (self.charge_density * 93 | self.electron_density) 94 | 95 | def faradays_law(self): 96 | return self.induced_emf * self.time / self.number_of_turns 97 | 98 | def self_inductance(self): 99 | return self.inductance * self.current_rate_of_change 100 | 101 | def mutual_inductance(self): 102 | return self.induced_emf / self.current_rate_of_change 103 | 104 | def coulombs_law(self): 105 | return (1 / (4 * pi * epsilon0)) * ((self.charge1 * self.charge2) / 106 | self.distance ** 2) 107 | 108 | def capacitance(self): 109 | return self.charge / self.voltage 110 | 111 | def electric_field_strength(self): 112 | return (1 / (4 * pi * epsilon0)) * (self.charge / self.distance ** 2) 113 | 114 | def electric_flux_density(self): 115 | return self.charge / self.area 116 | 117 | def magnetic_flux_quantum(self): 118 | return self.magnetic_flux / (vonklitzing_constant / (2 * pi)) 119 | 120 | def de_broglie_wavelength(self): 121 | return plancks_constant / self.momentum 122 | 123 | def compton_wavelength_change(self): 124 | return self.initial_wavelength - \ 125 | (compton_wavelength * (1 - math.cos(self.scattering_angle))) 126 | 127 | def bohr_orbit_radius(self): 128 | return (finestructure_constant ** 2) * (Coulombs_constant * 129 | (plancks_constant ** 2)) / ((pi * elementary_charge ** 2) * 130 | (self.principal_quantum_number ** 2) * (speed_of_light ** 2)) 131 | 132 | def fermi_energy(self): 133 | return self.fermi_level * elementary_charge 134 | 135 | def de_broglie_wavelength_matter_wave(self): 136 | return plancks_constant / (self.mass * self.velocity ) 137 | 138 | def number_of_ions(self): 139 | return self.charge / self.elementary_charge1 140 | 141 | def acceleration_due_to_gravity(self): 142 | return self.gravitational_field_strength * self.mass 143 | 144 | def magnetic_field_inside_a_solenoid(self): 145 | return (self.mu0 * self.number_of_turns * self.current) / self.length 146 | 147 | def magnetic_field_around_a_wire(self, radius): 148 | return (self.mu0 * self.current) / (2 * pi * radius) 149 | 150 | def induced_emf(self): 151 | return -self.change_in_magnetic_flux / self.time 152 | 153 | def maxwell_equation(self): 154 | return np.cross(self.magnetic_field, self.magnetic_flux_density) - \ 155 | Coulombs_constant * self.magnetic_field 156 | 157 | def snells_law(self): 158 | return (self.n1 * math.sin(self.angle_of_incidence)) / self.n2 159 | 160 | def critical_angle(self): 161 | return math.asin(self.n2 / self.n1) 162 | 163 | def photoelectric_effect_work_function(self): 164 | return self.hv - self.threshold_frequency 165 | 166 | def photoelectric_effect_max_velocity(self): 167 | return math.sqrt((2 * elementary_charge * 168 | (self.stopping_potential - self.work_function)) / Mass.electron) 169 | 170 | def decay_law(self): 171 | return self.initial_quantity * math.exp(-self.decay_constant * self.time) 172 | 173 | def half_life(self): 174 | return math.log(2) / self.decay_constant 175 | 176 | def nuclear_binding_energy(self): 177 | return self.mass_defect * speed_of_light ** 2 178 | 179 | def radioactive_decay(self): 180 | return -self.initial_quantity * math.log(self.final_quantity / 181 | self.initial_quantity) / self.time 182 | 183 | def einstein_mass_energy_equivalence(self): 184 | return self.mass * speed_of_light ** 2 185 | 186 | def coulomb_law(self): 187 | return (1 / (4 * pi * epsilon0)) * ((self.charge1 * self.charge2) / 188 | self.distance ** 2) 189 | -------------------------------------------------------------------------------- /PhysiPy/QuantumMechanics.py: -------------------------------------------------------------------------------- 1 | from .constants import Coulombs_constant, plancks_constant, speed_of_light 2 | from .constants import elementary_charge, pi, boltzmann_constant 3 | import math 4 | from .Mass import Mass 5 | from .Charge import Charge 6 | 7 | 8 | class QuantumMechanics: 9 | 10 | def __init__(self, frequency=1, temperature=1, wave_function=1, 11 | position_uncertainty=1, momentum_uncertainty=1, 12 | hamiltonian_operator=1, energy=1, energy_barrier=1, particle_mass=1, 13 | particle_energy=1, fermi_level=1, chemical_potential=1, 14 | wavelength=1, momentum=1, lifetime=1, principal_quantum_number=1, 15 | number_of_quanta=1, time=1, rydberg_constant=1, atomic_number=1, 16 | principal_quantum_number_initial=1, principal_quantum_number_final=1, 17 | frequency_emitted=1, frequency_absorbed=1, velocity=1, 18 | magnetic_moment=1, g_factor=1, bohr_magneton=1, nuclear_magneton=1, 19 | half_life=1, initial_quantity=1, decay_constant=1): 20 | self.frequency = frequency 21 | self.temperature = temperature 22 | self.wave_function = wave_function 23 | self.position_uncertainty = position_uncertainty 24 | self.momentum_uncertainty = momentum_uncertainty 25 | self.hamiltonian_operator = hamiltonian_operator 26 | self.energy = energy 27 | self.energy_barrier = energy_barrier 28 | self.particle_mass = particle_mass 29 | self.particle_energy = particle_energy 30 | self.fermi_level = fermi_level 31 | self.chemical_potential = chemical_potential 32 | self.wavelength = wavelength 33 | self.momentum = momentum 34 | self.lifetime = lifetime 35 | self.principal_quantum_number = principal_quantum_number 36 | self.number_of_quanta = number_of_quanta 37 | self.time = time 38 | self.rydberg_constant= rydberg_constant 39 | self.atomic_number = atomic_number 40 | self.principal_quantum_number_initial = principal_quantum_number_initial 41 | self.principal_quantum_number_final = principal_quantum_number_final 42 | self.frequency_emitted = frequency_emitted 43 | self.frequency_absorbed = frequency_absorbed 44 | self.velocity = velocity 45 | self.magnetic_moment = magnetic_moment 46 | self.g_factor = g_factor 47 | self.bohr_magneton = bohr_magneton 48 | self.nuclear_magneton = nuclear_magneton 49 | self.half_life = half_life 50 | self.initial_quantity = initial_quantity 51 | self.decay_constant = decay_constant 52 | 53 | def uncertainty_principle(self): 54 | return self.position_uncertainty * self.momentum_uncertainty >= \ 55 | plancks_constant / (4 * pi) 56 | 57 | def satisfy_schrodingers_equation(self) -> bool: 58 | return self.hamiltonian_operator * self.wave_function == self.energy * \ 59 | self.wave_function 60 | 61 | def probability_density(self): 62 | return (self.wave_function.conjugate() * self.wave_function).real 63 | 64 | def tunneling_probability(self): 65 | return math.exp((-2 * math.sqrt(2 * self.particle_mass * self.energy_barrier) / 66 | plancks_constant) * math.sqrt(self.particle_energy - 67 | self.energy_barrier)) 68 | 69 | def black_body_radiation_intensity(self): 70 | return (2 * plancks_constant * self.frequency ** 3) / ( 71 | speed_of_light ** 2 * (math.exp((plancks_constant * self.frequency) / 72 | (boltzmann_constant * self.temperature)) - 1)) 73 | 74 | def black_body_radiation_power(self): 75 | return (2 * pi ** 5 * boltzmann_constant ** 4 * self.temperature ** 4) / \ 76 | (15 * plancks_constant ** 3 * speed_of_light ** 2) 77 | 78 | def fermi_dirac_distribution(self): 79 | return 1 / (math.exp((self.energy - self.fermi_level) / (boltzmann_constant * 80 | self.temperature)) + 1) 81 | 82 | def bose_einstein_distribution(self): 83 | return 1 / (math.exp((self.energy - self.chemical_potential) / 84 | (boltzmann_constant * self.temperature)) - 1) 85 | 86 | def exhibits_wave_particle_duality(self) -> bool: 87 | return self.wavelength * self.momentum == plancks_constant 88 | 89 | def heisenberg_uncertainty_energy_lifetime(self): 90 | return self.energy * self.lifetime >= plancks_constant / (4 * pi) 91 | 92 | def satisfies_heisenberg_uncertainty_position_momentum(self) -> bool: 93 | return self.position_uncertainty * self.momentum_uncertainty >= \ 94 | plancks_constant / 2 95 | 96 | def atomic_orbital_radius(self): 97 | return (4 * pi * Coulombs_constant * (plancks_constant ** 2) * ( 98 | self.principal_quantum_number ** 2)) / (Mass.electron * 99 | (elementary_charge ** 2)) 100 | 101 | def fine_structure_constant(self): 102 | return (elementary_charge ** 2) / (4 * pi * Coulombs_constant * 103 | plancks_constant * speed_of_light) 104 | 105 | def de_broglie_wavelength_photon(self): 106 | return speed_of_light / self.frequency 107 | 108 | def de_broglie_wavelength_particle(self): 109 | return plancks_constant / self.momentum 110 | 111 | def plank_distribution_radiation(self): 112 | return (2 * plancks_constant * (self.energy ** 3)) / (speed_of_light ** 2 * 113 | (math.exp((plancks_constant * self.energy) / (boltzmann_constant * 114 | self.temperature)) - 1)) 115 | 116 | def plank_distribution(self): 117 | return (2 * self.energy ** 2) / ( 118 | (plancks_constant ** 3) * (speed_of_light ** 2) * 119 | (math.exp(self.energy / (boltzmann_constant * self.temperature)) - 1)) 120 | 121 | def plank_law_intensity(self): 122 | return (2 * plancks_constant * self.frequency ** 3) / ( 123 | speed_of_light ** 2 * (math.exp((plancks_constant * self.frequency) / 124 | (boltzmann_constant * self.temperature)) - 1)) 125 | 126 | def plank_law_power(self): 127 | return (2 * pi * (boltzmann_constant ** 4) * self.temperature ** 4) / \ 128 | (15 * (plancks_constant ** 3) * (speed_of_light ** 2)) 129 | 130 | def follows_einstein_light_quanta(self) -> bool: 131 | return self.energy == plancks_constant * self.frequency 132 | 133 | def einstein_light_intensity(self): 134 | return self.number_of_quanta / self.time 135 | 136 | def atomic_spectra(self): 137 | return (self.rydberg_constant * self.atomic_number ** 2) * ( 138 | (1 / self.principal_quantum_number_final ** 2) - 139 | (1 / self.principal_quantum_number_initial ** 2)) 140 | 141 | def has_absorption_spectrum(self) -> bool: 142 | return (self.frequency_absorbed - self.frequency_emitted) / \ 143 | self.frequency_emitted == self.velocity / speed_of_light 144 | 145 | def has_emission_spectrum(self) -> bool: 146 | return (self.frequency_absorbed - self.frequency_emitted) / \ 147 | self.frequency_absorbed == self.velocity / speed_of_light 148 | 149 | def electron_smath_pin_magnetic_moment(self): 150 | return self.magnetic_moment / (Charge.electron * Mass.electron) 151 | 152 | def electron_g_factor(self): 153 | return self.g_factor * self.bohr_magneton 154 | 155 | def atomic_nucleus_g_factor(self): 156 | return self.g_factor * self.nuclear_magneton 157 | 158 | def nuclear_decay_constant(self): 159 | return math.log(2) / self.half_life 160 | 161 | def nuclear_decay(self): 162 | return self.initial_quantity * math.exp(-self.decay_constant * self.time) 163 | --------------------------------------------------------------------------------