diff --git a/symplyphysics/definitions/boltzmann_factor_via_state_energy_and_temperature.py b/symplyphysics/definitions/boltzmann_factor_via_state_energy_and_temperature.py index 51447f63e..56b1f9d0d 100644 --- a/symplyphysics/definitions/boltzmann_factor_via_state_energy_and_temperature.py +++ b/symplyphysics/definitions/boltzmann_factor_via_state_energy_and_temperature.py @@ -13,19 +13,17 @@ from sympy import Eq, exp from symplyphysics import ( quantities, - dimensionless, Quantity, validate_input, validate_output, symbols, convert_to_float, - SymbolNew, clone_as_symbol, ) -boltzmann_factor = SymbolNew("f", dimensionless) +boltzmann_factor = symbols.boltzmann_factor """ -Boltzmann factor. +:symbols:`boltzmann_factor`. """ energy_of_state = clone_as_symbol(symbols.energy, display_symbol="E[i]", display_latex="E_i") diff --git a/symplyphysics/definitions/damped_harmonic_oscillator_equation.py b/symplyphysics/definitions/damped_harmonic_oscillator_equation.py index 0404354dc..72e89d61a 100644 --- a/symplyphysics/definitions/damped_harmonic_oscillator_equation.py +++ b/symplyphysics/definitions/damped_harmonic_oscillator_equation.py @@ -22,9 +22,14 @@ :symbols:`time`. """ -displacement = clone_as_function(symbols.position, [time]) +displacement = clone_as_function( + symbols.euclidean_distance, + [time], + display_symbol="x", + display_latex="x", +) """ -Displacement of the oscillating body as a function of time. See :symbols:`position`. +Displacement of the oscillating body as a function of time. See :symbols:`euclidean_distance`. """ undamped_angular_frequency = clone_as_symbol(symbols.angular_frequency, positive=True) @@ -49,7 +54,7 @@ @validate_input( - initial_position_=symbols.distance, + initial_position_=symbols.euclidean_distance, initial_velocity_=symbols.speed, undamped_angular_frequency_=undamped_angular_frequency, damping_ratio_=damping_ratio, diff --git a/symplyphysics/laws/dynamics/period_of_physical_pendulum.py b/symplyphysics/laws/dynamics/period_of_physical_pendulum.py index a1f02ce02..107e671b7 100644 --- a/symplyphysics/laws/dynamics/period_of_physical_pendulum.py +++ b/symplyphysics/laws/dynamics/period_of_physical_pendulum.py @@ -45,9 +45,9 @@ The :symbols:`rotational_inertia` of the pendulum. """ -distance_to_pivot = clone_as_symbol(symbols.distance, positive=True) +distance_to_pivot = clone_as_symbol(symbols.euclidean_distance, positive=True) """ -The :symbols:`distance` between the pivot and the pendulum's center of mass. +The :symbols:`euclidean_distance` between the pivot and the pendulum's center of mass. """ law = Eq( diff --git a/symplyphysics/laws/dynamics/potential_energy_from_deformation.py b/symplyphysics/laws/dynamics/potential_energy_from_deformation.py index e27d64983..1fa02f58b 100644 --- a/symplyphysics/laws/dynamics/potential_energy_from_deformation.py +++ b/symplyphysics/laws/dynamics/potential_energy_from_deformation.py @@ -30,9 +30,9 @@ The spring's :symbols:`stiffness`, or spring constant. """ -displacement = symbols.distance +displacement = symbols.euclidean_distance """ -The displacement of the spring, or the :symbols:`distance` between the initial position +The displacement of the spring, or the :symbols:`euclidean_distance` between the initial position and the rest position. """ diff --git a/symplyphysics/laws/electricity/charge_is_quantized.py b/symplyphysics/laws/electricity/charge_is_quantized.py index 748ecee03..ee204de8f 100644 --- a/symplyphysics/laws/electricity/charge_is_quantized.py +++ b/symplyphysics/laws/electricity/charge_is_quantized.py @@ -11,8 +11,6 @@ from sympy import Eq from symplyphysics import ( - SymbolNew, - dimensionless, Quantity, validate_input, validate_output, @@ -25,9 +23,9 @@ Total :symbols:`charge` of the body. """ -integer_factor = SymbolNew("n", dimensionless) # positive, zero or negative +integer_factor = symbols.whole_number """ -Integer factor of any sign. +:symbols:`whole_number`. """ law = Eq(charge, integer_factor * quantities.elementary_charge) diff --git a/symplyphysics/laws/electricity/circuits/capacitance_is_proportional_to_plate_area.py b/symplyphysics/laws/electricity/circuits/capacitance_is_proportional_to_plate_area.py index b0a426802..06787d59e 100644 --- a/symplyphysics/laws/electricity/circuits/capacitance_is_proportional_to_plate_area.py +++ b/symplyphysics/laws/electricity/circuits/capacitance_is_proportional_to_plate_area.py @@ -34,9 +34,9 @@ :symbols:`area` of the plates. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` between the plates. +:symbols:`euclidean_distance` between the plates. """ law = Eq(capacitance, absolute_permittivity * area / distance) diff --git a/symplyphysics/laws/electricity/circuits/voltage_across_charging_capacitor_in_serial_resistor_capacitor_circuit.py b/symplyphysics/laws/electricity/circuits/voltage_across_charging_capacitor_in_serial_resistor_capacitor_circuit.py index 2d095ca7b..f7f898020 100644 --- a/symplyphysics/laws/electricity/circuits/voltage_across_charging_capacitor_in_serial_resistor_capacitor_circuit.py +++ b/symplyphysics/laws/electricity/circuits/voltage_across_charging_capacitor_in_serial_resistor_capacitor_circuit.py @@ -35,7 +35,7 @@ :symbols:`voltage` across the capacitor. """ -source_voltage = clone_as_symbol(symbols.voltage, display_symbol="V_0", display_latex="V_0") +source_voltage = clone_as_symbol(symbols.voltage, subscript="0") """ :symbols:`voltage` of the source, which is the initial voltage across the resistor. """ diff --git a/symplyphysics/laws/electricity/electric_charge_is_constant_in_isolated_system.py b/symplyphysics/laws/electricity/electric_charge_is_constant_in_isolated_system.py index 829b4a184..cea622db5 100644 --- a/symplyphysics/laws/electricity/electric_charge_is_constant_in_isolated_system.py +++ b/symplyphysics/laws/electricity/electric_charge_is_constant_in_isolated_system.py @@ -9,12 +9,12 @@ from sympy import Eq, solve from symplyphysics import Quantity, validate_input, validate_output, symbols, clone_as_symbol -initial_charge = clone_as_symbol(symbols.charge, display_symbol="q_0", display_latex="q_0") +initial_charge = clone_as_symbol(symbols.charge, subscript="0") """ Initial :symbols:`charge` of the system. """ -final_charge = clone_as_symbol(symbols.charge, display_symbol="q_1", display_latex="q_1") +final_charge = clone_as_symbol(symbols.charge, subscript="1") """ Final :symbols:`charge` of the system. """ diff --git a/symplyphysics/laws/electricity/electric_dipole_moment_is_charge_times_distance.py b/symplyphysics/laws/electricity/electric_dipole_moment_is_charge_times_distance.py index 5700d2e4b..c6d9e6305 100644 --- a/symplyphysics/laws/electricity/electric_dipole_moment_is_charge_times_distance.py +++ b/symplyphysics/laws/electricity/electric_dipole_moment_is_charge_times_distance.py @@ -30,9 +30,9 @@ Magnitude of one the two point :symbols:`charge`-s comprising the system. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` between point charges. +:symbols:`euclidean_distance` between point charges. """ law = Eq(electric_dipole_moment, charge * distance) diff --git a/symplyphysics/laws/electricity/electric_field_due_to_dipole.py b/symplyphysics/laws/electricity/electric_field_due_to_dipole.py index 231d702f5..e501a81cb 100644 --- a/symplyphysics/laws/electricity/electric_field_due_to_dipole.py +++ b/symplyphysics/laws/electricity/electric_field_due_to_dipole.py @@ -40,9 +40,9 @@ :symbols:`electric_dipole_moment`. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` to dipole. +:symbols:`euclidean_distance` to dipole. """ law = Eq(electric_field_strength, diff --git a/symplyphysics/laws/electricity/electric_field_due_to_point_charge.py b/symplyphysics/laws/electricity/electric_field_due_to_point_charge.py index 8a30ef05f..f4dacd47f 100644 --- a/symplyphysics/laws/electricity/electric_field_due_to_point_charge.py +++ b/symplyphysics/laws/electricity/electric_field_due_to_point_charge.py @@ -33,9 +33,9 @@ Value of the point :symbols:`charge`. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` to the charge. +:symbols:`euclidean_distance` to the charge. """ law = Eq(electric_field_strength, diff --git a/symplyphysics/laws/electricity/electric_field_is_force_over_test_charge.py b/symplyphysics/laws/electricity/electric_field_is_force_over_test_charge.py index ac526a916..1a64cf1b6 100644 --- a/symplyphysics/laws/electricity/electric_field_is_force_over_test_charge.py +++ b/symplyphysics/laws/electricity/electric_field_is_force_over_test_charge.py @@ -27,7 +27,7 @@ Projection of the electrostatic :symbols:`force` applied to the test charge. """ -test_charge = clone_as_symbol(symbols.charge, display_symbol="q_0", display_latex="q_0") +test_charge = clone_as_symbol(symbols.charge, subscript="0") """ Value of the test :symbols:`charge`. """ diff --git a/symplyphysics/laws/electricity/electric_field_outside_charged_sphere.py b/symplyphysics/laws/electricity/electric_field_outside_charged_sphere.py index aa28b3027..7b5b0f1e3 100644 --- a/symplyphysics/laws/electricity/electric_field_outside_charged_sphere.py +++ b/symplyphysics/laws/electricity/electric_field_outside_charged_sphere.py @@ -34,9 +34,9 @@ Total :symbols:`charge` of the sphere. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` to the center of the sphere. +:symbols:`euclidean_distance` to the center of the sphere. """ law = Eq(electric_field_strength, charge / (4 * pi * quantities.vacuum_permittivity * distance**2)) diff --git a/symplyphysics/laws/electricity/electromotive_force_induced_in_moving_contour.py b/symplyphysics/laws/electricity/electromotive_force_induced_in_moving_contour.py index 0e35fd1c6..5ab340262 100644 --- a/symplyphysics/laws/electricity/electromotive_force_induced_in_moving_contour.py +++ b/symplyphysics/laws/electricity/electromotive_force_induced_in_moving_contour.py @@ -10,10 +10,7 @@ from sympy import (Eq, Derivative) from symplyphysics import ( - dimensionless, - units, Quantity, - SymbolNew, validate_input, validate_output, symbols, @@ -21,19 +18,19 @@ ) from symplyphysics.core.geometry.line import two_point_function, Point2D -electromotive_force = SymbolNew("E", units.voltage, display_latex="\\mathcal{E}") +electromotive_force = symbols.electromotive_force r""" -Electromotive force induced in the contour. +:symbols:`electromotive_force` induced in the contour. """ -current_turn_count = SymbolNew("N", dimensionless) +current_turn_count = symbols.positive_number """ -Number of turns the current makes around the contour. +Number of turns the current makes around the contour. See :symbols:`positive_number`. """ -time = SymbolNew("t", units.time) +time = symbols.time """ -Time. +:symbols:`time`. """ magnetic_flux = clone_as_function(symbols.magnetic_flux, [time]) diff --git a/symplyphysics/laws/electricity/electromotive_force_induced_in_sinusoidally_rotating_coil.py b/symplyphysics/laws/electricity/electromotive_force_induced_in_sinusoidally_rotating_coil.py deleted file mode 100644 index 795242847..000000000 --- a/symplyphysics/laws/electricity/electromotive_force_induced_in_sinusoidally_rotating_coil.py +++ /dev/null @@ -1,85 +0,0 @@ -r""" -Electromotive force induced in sinusoidally rotating coil -========================================================= - -Suppose a coil is being rotated around the axis that lies in the coil's cross section -(see `Figure `__) -in a magnetic field under the conditions described below. Then an electromotive force will -be induced in the contour of the coil. Its amplitude depends on the number of turns in -the coil, the magnetic flux density, the angular frequency of the coil's rotation and -the area of the coil's contour. - -**Notes:** - -#. The angle :math:`\varphi` between the normal to the coil's contour and the magnetic flux - density is :math:`\varphi \propto \cos(\omega t)`. See `Figure `__. - -**Conditions:** - -#. The magnetic field is uniform. -#. The angular velocity of the coil's rotation is orthogonal to the magnetic field. -#. The area of the coil's contour is constant. -#. The rotation of the coil is uniform. -""" - -from sympy import (Eq, solve, sin) -from symplyphysics import (Quantity, SymbolNew, validate_input, validate_output, dimensionless, - symbols) - -electromotive_force = symbols.electromotive_force -""" -:symbols:`electromotive_force` induced in the coil. -""" - -coil_turn_count = SymbolNew("N", dimensionless) -""" -Number of turns in the coil. -""" - -magnetic_flux_density = symbols.magnetic_flux_density -""" -:symbols:`magnetic_flux_density`. -""" - -contour_area = symbols.area -""" -Cross-sectional :symbols:`area` of the contour enclosed by the coil. -""" - -angular_frequency = symbols.angular_frequency -""" -:symbols:`angular_frequency` of the coil's rotation. -""" - -time = symbols.time -""" -Time. -""" - -law = Eq( - electromotive_force, -1 * coil_turn_count * magnetic_flux_density * contour_area * - angular_frequency * sin(angular_frequency * time)) -""" -:laws:symbol:: - -:laws:latex:: -""" - - -@validate_input(number_turns_=coil_turn_count, - induction_=magnetic_flux_density, - contour_area_=contour_area, - rotation_frequency_=angular_frequency, - time_=time) -@validate_output(electromotive_force) -def calculate_voltage(number_turns_: int, induction_: Quantity, contour_area_: Quantity, - rotation_frequency_: Quantity, time_: Quantity) -> Quantity: - result_expr = solve(law, electromotive_force, dict=True)[0][electromotive_force] - result_expr = result_expr.subs({ - coil_turn_count: number_turns_, - magnetic_flux_density: induction_, - contour_area: contour_area_, - angular_frequency: rotation_frequency_, - time: time_ - }) - return Quantity(result_expr) diff --git a/symplyphysics/laws/electricity/electromotive_force_induced_in_uniformly_rotating_coil.py b/symplyphysics/laws/electricity/electromotive_force_induced_in_uniformly_rotating_coil.py index 7bf179a37..b97434791 100644 --- a/symplyphysics/laws/electricity/electromotive_force_induced_in_uniformly_rotating_coil.py +++ b/symplyphysics/laws/electricity/electromotive_force_induced_in_uniformly_rotating_coil.py @@ -22,74 +22,54 @@ #. The angular speed of the coil's rotation constant. """ -from sympy import (Eq, solve, sin) -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output, dimensionless, - angle_type) +from sympy import Eq, solve, sin +from symplyphysics import Quantity, validate_input, validate_output, symbols from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.electricity import ( electromotive_force_induced_in_moving_contour as _emf_law, magnetic_flux_from_induction_and_area as _magnetic_flux_law, ) from symplyphysics.laws.kinematics import ( - angular_position_via_constant_angular_speed_and_time as _angle_law,) + angular_position_via_constant_angular_speed_and_time as _angle_law, +) -electromotive_force = Symbol("electromotive_force", units.voltage) +electromotive_force = symbols.electromotive_force r""" -Electromotive force induced in the coil. - -Symbol: - :code:`E` - -Latex: - :math:`\mathcal{E}` +:symbols:`electromotive_force` induced in the coil. """ -coil_turn_count = Symbol("coil_turn_count", dimensionless) +coil_turn_count = symbols.positive_number """ -Number of turns in the coil. - -Symbol: - :code:`N` +Number of turns in the coil. See :symbols:`positive_number`. """ -magnetic_flux_density = Symbol("magnetic_flux_density", units.magnetic_density) +magnetic_flux_density = symbols.magnetic_flux_density """ -Magnetic flux density. - -Symbol: - :code:`B` +:symbols:`magnetic_flux_density`. """ -contour_area = Symbol("contour_area", units.area) +contour_area = symbols.area """ -Cross-sectional area of the contour enclosed by the coil. - -Symbol: - :code:`A` +Cross-sectional :symbols:`area` of the contour enclosed by the coil. """ -angular_frequency = Symbol("angular_frequency", angle_type / units.time) +angular_frequency = symbols.angular_frequency r""" -Angular frequency of the coil's rotation. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +:symbols:`angular_frequency` of the coil's rotation. """ -time = Symbol("time", units.time) +time = symbols.time +""" +:symbols:`time`. +""" law = Eq( electromotive_force, -1 * coil_turn_count * magnetic_flux_density * contour_area * angular_frequency * sin(angular_frequency * time)) -r""" -:code:`E = -1 * N * B * A * w * sin(w * t)` +""" +:laws:symbol:: -Latex: - .. math:: - \mathcal{E} = -N B A \omega \sin(\omega t) +:laws:latex:: """ # Derive law diff --git a/symplyphysics/laws/electricity/electrostatic_force_via_charges_and_distance.py b/symplyphysics/laws/electricity/electrostatic_force_via_charges_and_distance.py index 0d6966e8c..13c846c2a 100644 --- a/symplyphysics/laws/electricity/electrostatic_force_via_charges_and_distance.py +++ b/symplyphysics/laws/electricity/electrostatic_force_via_charges_and_distance.py @@ -30,9 +30,9 @@ Second :symbols:`charge`. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` between the charges. +:symbols:`euclidean_distance` between the charges. """ law = Eq( diff --git a/symplyphysics/laws/electricity/electrostatic_potential_due_to_point_charge.py b/symplyphysics/laws/electricity/electrostatic_potential_due_to_point_charge.py index bfc7154d0..0a2f5d874 100644 --- a/symplyphysics/laws/electricity/electrostatic_potential_due_to_point_charge.py +++ b/symplyphysics/laws/electricity/electrostatic_potential_due_to_point_charge.py @@ -24,9 +24,9 @@ :symbols:`absolute_permittivity` of the medium. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` to the point charge. +:symbols:`euclidean_distance` to the point charge. """ charge = symbols.charge diff --git a/symplyphysics/laws/electricity/electrostatic_potential_energy_of_two_charges_via_distance.py b/symplyphysics/laws/electricity/electrostatic_potential_energy_of_two_charges_via_distance.py index 2860a07f2..e3dbd08ed 100644 --- a/symplyphysics/laws/electricity/electrostatic_potential_energy_of_two_charges_via_distance.py +++ b/symplyphysics/laws/electricity/electrostatic_potential_energy_of_two_charges_via_distance.py @@ -28,9 +28,9 @@ :symbols:`absolute_permittivity` of the medium. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` between the point charges. +:symbols:`euclidean_distance` between the point charges. """ first_charge = clone_as_symbol(symbols.charge, display_symbol="q_1", display_latex="q_1") diff --git a/symplyphysics/laws/electricity/inductance_is_magnetic_flux_over_current.py b/symplyphysics/laws/electricity/inductance_is_magnetic_flux_over_current.py index 0714e63c7..9952f6f89 100644 --- a/symplyphysics/laws/electricity/inductance_is_magnetic_flux_over_current.py +++ b/symplyphysics/laws/electricity/inductance_is_magnetic_flux_over_current.py @@ -8,27 +8,21 @@ """ from sympy import Eq -from symplyphysics import ( - SymbolNew, - units, - Quantity, - validate_input, - validate_output, -) +from symplyphysics import Quantity, validate_input, validate_output, symbols -inductance = SymbolNew("L", units.inductance) +inductance = symbols.inductance """ -Inductance. +:symbols:`inductance`. """ -magnetic_flux = SymbolNew("Phi_B", units.magnetic_flux, display_latex="\\Phi_B") +magnetic_flux = symbols.magnetic_flux """ -Magnetic flux due to the component. +:symbols:`magnetic_flux` due to the component. """ -current = SymbolNew("I", units.current) +current = symbols.current """ -Current flowing through the circuit. +:symbols:`current` flowing through the circuit. """ law = Eq(inductance, magnetic_flux / current) diff --git a/symplyphysics/laws/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume.py b/symplyphysics/laws/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume.py index 293ce9b83..83bce5b31 100644 --- a/symplyphysics/laws/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume.py +++ b/symplyphysics/laws/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume.py @@ -1,38 +1,63 @@ -from sympy import (Eq, solve) -from sympy.physics.units import magnetic_constant -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output, dimensionless) +""" +Inductance via number of turns and coil volume +============================================== -# Description -## A solenoid is a cylindrical coil consisting of a large number of turns of wire forming a helical line. -## Inductance of solenoid depends on core material, number of turns per unit length, and volume of core. +The inductance of a coil (a solenoid) can be expressed as a function of the material's +permeability, the number of turns in the coil per unit length and its volume. -## Law is: L = mu * mu0 * n^2 * V, where -## L - inductance, -## mu - relative permeability of the core inside of a solenoid, -## mu0 - magnetic constant, -## n - number of turns per unit length, -## V - volume of solenoid. +.. + TODO rename file +""" -inductance = Symbol("inductance", units.inductance) +from sympy import Eq, solve +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, + SymbolNew, + units, +) -relative_permeability = Symbol("relative_permeability", dimensionless) -number_of_turns_per_length = Symbol("number_of_turns", 1 / units.length) -volume = Symbol("volume", units.volume) +inductance = symbols.inductance +""" +:symbols:`inductance` of the coil. +""" + +absolute_permeability = symbols.absolute_permeability +""" +:symbols:`absolute_permeability` of the inside of the coil. +""" + +specific_coil_turn_count = SymbolNew("n", 1 / units.length) +""" +Number of turns in the coil per unit length. +""" + +volume = symbols.volume +""" +:symbols:`volume` of the coil. +""" law = Eq(inductance, - relative_permeability * magnetic_constant * number_of_turns_per_length**2 * volume) + absolute_permeability * specific_coil_turn_count**2 * volume) +""" +:laws:symbol:: + +:laws:latex:: +""" -@validate_input(relative_permeability_=relative_permeability, - number_of_turns_per_length_=number_of_turns_per_length, +@validate_input(absolute_permeability_=absolute_permeability, + turn_count_=specific_coil_turn_count, volume_=volume) @validate_output(inductance) -def calculate_inductance(relative_permeability_: float, number_of_turns_per_length_: Quantity, +def calculate_inductance(absolute_permeability_: Quantity, turn_count_: Quantity, volume_: Quantity) -> Quantity: result_inductance_expr = solve(law, inductance, dict=True)[0][inductance] result_expr = result_inductance_expr.subs({ - relative_permeability: relative_permeability_, - number_of_turns_per_length: number_of_turns_per_length_, + absolute_permeability: absolute_permeability_, + specific_coil_turn_count: turn_count_, volume: volume_ }) return Quantity(result_expr) diff --git a/symplyphysics/laws/electricity/magnetic_field_of_coil.py b/symplyphysics/laws/electricity/magnetic_field_of_coil.py index b27ec23c7..41a9b6242 100644 --- a/symplyphysics/laws/electricity/magnetic_field_of_coil.py +++ b/symplyphysics/laws/electricity/magnetic_field_of_coil.py @@ -15,9 +15,8 @@ #. The magnetic field is measured near the center of the coil. """ -from sympy import (Eq, solve) -from symplyphysics import (Quantity, SymbolNew, validate_input, validate_output, dimensionless, - symbols, quantities) +from sympy import Eq, solve +from symplyphysics import Quantity, validate_input, validate_output, symbols, quantities magnetic_flux_density = symbols.magnetic_flux_density """ @@ -34,9 +33,9 @@ :symbols:`length` of the coil. """ -coil_turn_count = SymbolNew("N", dimensionless) +coil_turn_count = symbols.positive_number """ -Number of turns in the coil. +Number of turns in the coil. See :symbols:`positive_number`. """ law = Eq(magnetic_flux_density, quantities.vacuum_permeability * current * coil_turn_count / length) diff --git a/symplyphysics/laws/electricity/maximum_moment_of_magnetic_field.py b/symplyphysics/laws/electricity/maximum_moment_of_magnetic_field.py index 10865fb95..eaf44c047 100644 --- a/symplyphysics/laws/electricity/maximum_moment_of_magnetic_field.py +++ b/symplyphysics/laws/electricity/maximum_moment_of_magnetic_field.py @@ -1,34 +1,48 @@ -from sympy import (Eq, solve) -from symplyphysics import ( - units, - Quantity, - Symbol, - validate_input, - validate_output, -) - -# Description -## The magnetic moment is the main physical quantity characterizing the magnetic properties of a substance, -## that is, the ability to create and perceive a magnetic field. - -## Law is: m = I * S, where -## m - magnetic moment, -## I - current, -## S - area of closed contour, which is formed by a closed thin conductor through which current flows. - -# Conditions: -## - Ideally, the conductor itself should be infinitely thin. But a conductor can have -## any shape and size if its dimensions can be neglected relative to the size of the -## closed circuit that it forms. -## - The plane must be flat for this formula to be applicable. If there are several turns -## of the conductor, then the formula will be similar, but still different. - -moment = Symbol("moment", units.current * units.area) - -current = Symbol("current", units.current) -area = Symbol("area", units.area) +""" +Magnetic moment via current and contour area +============================================ + +The **magnetic moment** is the main physical quantity characterizing the magnetic +properties of a substance, that is, the ability to create and perceive a magnetic +field. + +**Conditions:** + +#. Ideally, the conductor itself should be infinitely thin. But a conductor can have + any shape and size if its dimensions can be neglected relative to the size of the + closed circuit that it forms. + +#. The plane must be flat for this formula to be applicable, and the current must + only make one turn around the contour. + +.. + TODO rename file +""" + +from sympy import Eq, solve +from symplyphysics import Quantity, validate_input, validate_output, symbols + +moment = symbols.magnetic_moment +""" +:symbols:`magnetic_moment`. +""" + +current = symbols.current +""" +:symbols:`current` flowing through the contour. +""" + +area = symbols.area +""" +Contour :symbols:`area`. +""" law = Eq(moment, current * area) +""" +:laws:symbol:: + +:laws:latex:: +""" @validate_input(current_=current, area_=area) diff --git a/symplyphysics/laws/electricity/self_induced_electromotive_force_via_time_derivative_of_current.py b/symplyphysics/laws/electricity/self_induced_electromotive_force_via_time_derivative_of_current.py index 0e0fc3487..87cff3725 100644 --- a/symplyphysics/laws/electricity/self_induced_electromotive_force_via_time_derivative_of_current.py +++ b/symplyphysics/laws/electricity/self_induced_electromotive_force_via_time_derivative_of_current.py @@ -23,7 +23,7 @@ electromotive_force = clone_as_function(symbols.electromotive_force, [time]) """ -Self-induced :symbols:`electromotive_force`. +Self-induced :symbols:`electromotive_force` as a function of :attr:`~time`. """ inductance = symbols.inductance @@ -33,7 +33,7 @@ current = clone_as_function(symbols.current, [time]) """ -:symbols:`current` in the circuit. +:symbols:`current` in the circuit as a function of :attr:`~time`. """ law = Eq(electromotive_force(time), -1 * inductance * Derivative(current(time), time)) diff --git a/symplyphysics/laws/electricity/vector/electric_dipole_moment_is_charge_times_displacement.py b/symplyphysics/laws/electricity/vector/electric_dipole_moment_is_charge_times_displacement.py index fa2e67df6..5929dfd35 100644 --- a/symplyphysics/laws/electricity/vector/electric_dipole_moment_is_charge_times_displacement.py +++ b/symplyphysics/laws/electricity/vector/electric_dipole_moment_is_charge_times_displacement.py @@ -12,7 +12,6 @@ """ from symplyphysics import ( - Symbol, units, validate_input, validate_output, @@ -20,14 +19,12 @@ scale_vector, QuantityVector, Vector, + symbols, ) -charge = Symbol("charge", units.charge) +charge = symbols.charge """ -Magnitude of the electric charge of the point charges. - -Symbol: - :code:`q` +Magnitude of the electric :symbols:`charge` of the point charges. """ diff --git a/symplyphysics/laws/electricity/vector/electric_field_is_force_over_test_charge.py b/symplyphysics/laws/electricity/vector/electric_field_is_force_over_test_charge.py index 84adef115..bfb670c8a 100644 --- a/symplyphysics/laws/electricity/vector/electric_field_is_force_over_test_charge.py +++ b/symplyphysics/laws/electricity/vector/electric_field_is_force_over_test_charge.py @@ -10,22 +10,17 @@ Quantity, QuantityVector, scale_vector, - Symbol, units, validate_input, validate_output, Vector, + symbols, + clone_as_symbol, ) -test_charge = Symbol("test_charge", units.charge) -r""" -Value of the test charge. - -Symbol: - :code:`q0` - -Latex: - :math:`q_0` +test_charge = clone_as_symbol(symbols.charge, subscript="0") +""" +Value of the test :symbols:`charge`. """ diff --git a/symplyphysics/laws/electricity/vector/lorentz_force_via_electromagnetic_field.py b/symplyphysics/laws/electricity/vector/lorentz_force_via_electromagnetic_field.py index 14d00ed09..7fd8e2b13 100644 --- a/symplyphysics/laws/electricity/vector/lorentz_force_via_electromagnetic_field.py +++ b/symplyphysics/laws/electricity/vector/lorentz_force_via_electromagnetic_field.py @@ -30,19 +30,16 @@ subtract_cartesian_vectors, cross_cartesian_vectors, vector_magnitude, - Symbol, units, validate_input, validate_output, Vector, + symbols, ) -charge = Symbol("charge", units.charge) +charge = symbols.charge """ -Value of the electric charge of the test particle. - -Symbol: - :code:`q` +Value of the electric :symbols:`charge` of the test particle. """ diff --git a/symplyphysics/laws/electricity/voltage_is_electric_field_times_distance.py b/symplyphysics/laws/electricity/voltage_is_electric_field_times_distance.py index 168a8a55b..9d0d1a420 100644 --- a/symplyphysics/laws/electricity/voltage_is_electric_field_times_distance.py +++ b/symplyphysics/laws/electricity/voltage_is_electric_field_times_distance.py @@ -9,21 +9,26 @@ """ from sympy import Eq -from symplyphysics import (units, Quantity, SymbolNew, validate_input, validate_output) +from symplyphysics import ( + Quantity, + validate_input, + validate_output, + symbols, +) -voltage = SymbolNew("V", units.voltage) +voltage = symbols.voltage """ -Voltage between two points. +:symbols:`voltage` between two points. """ -electric_field_strength = SymbolNew("E", units.voltage / units.length) +electric_field_strength = symbols.electric_field_strength """ -Electric field strength. +:symbols:`electric_field_strength`. """ -distance = SymbolNew("d", units.length) +distance = symbols.euclidean_distance """ -Distance between two points. +:symbols:`euclidean_distance` between two points. """ law = Eq(voltage, electric_field_strength * distance) diff --git a/symplyphysics/laws/electricity/voltage_is_line_integral_of_electric_field.py b/symplyphysics/laws/electricity/voltage_is_line_integral_of_electric_field.py index 721d9b7ed..aa7e9625a 100644 --- a/symplyphysics/laws/electricity/voltage_is_line_integral_of_electric_field.py +++ b/symplyphysics/laws/electricity/voltage_is_line_integral_of_electric_field.py @@ -13,24 +13,23 @@ from sympy import Eq, Integral from symplyphysics import ( - units, Quantity, - SymbolNew, validate_input, validate_output, clone_as_function, + clone_as_symbol, symbols, ) from symplyphysics.core.geometry.line import two_point_function, Point2D -voltage = SymbolNew("V", units.voltage) +voltage = symbols.voltage """ -Voltage between two points. +:symbols:`voltage` between two points. """ -distance = SymbolNew("s", units.length) +distance = symbols.euclidean_distance """ -Distance traveled. +:symbols:`euclidean_distance` traveled. """ electric_field_component = clone_as_function( @@ -43,14 +42,14 @@ See :symbols:`electric_field_strength`. """ -initial_distance = SymbolNew("s_0", units.length) +initial_distance = clone_as_symbol(symbols.distance, subscript="0") """ -Initial distance. +Initial :symbols:`distance`. """ -final_distance = SymbolNew("s_1", units.length) +final_distance = clone_as_symbol(symbols.distance, subscript="1") """ -Final distance. +Final :symbols:`distance`. """ law = Eq( diff --git a/symplyphysics/laws/kinematics/angular_momentum_is_rotational_inertia_times_angular_speed.py b/symplyphysics/laws/kinematics/angular_momentum_is_rotational_inertia_times_angular_speed.py index 4b51298f3..ce52d550f 100644 --- a/symplyphysics/laws/kinematics/angular_momentum_is_rotational_inertia_times_angular_speed.py +++ b/symplyphysics/laws/kinematics/angular_momentum_is_rotational_inertia_times_angular_speed.py @@ -13,49 +13,28 @@ """ from sympy import Eq -from symplyphysics import ( - units, - Quantity, - Symbol, - validate_input, - validate_output, - angle_type, -) +from symplyphysics import Quantity, validate_input, validate_output, symbols -angular_momentum = Symbol("angular_momentum", units.length * units.momentum) +angular_momentum = symbols.angular_momentum """ -Component of the vector of angular momentum parallel to the rotational axis. - -Symbol: - :code:`L` +Component of the vector of :symbols:`angular_momentum` parallel to the rotational axis. """ -rotational_inertia = Symbol("rotational_inertia", units.mass * units.length**2) +rotational_inertia = symbols.rotational_inertia """ -Rotational inertia of the body. - -Symbol: - :code:`I` +:symbols:`rotational_inertia` of the body. """ -angular_speed = Symbol("angular_speed", angle_type / units.time) -r""" -Angular speed of the body. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +angular_speed = symbols.angular_speed +""" +:symbols:`angular_speed` of the body. """ law = Eq(angular_momentum, rotational_inertia * angular_speed) -r""" -:code:`L = I * w` +""" +:laws:symbol:: -Latex: - .. math:: - L = I \omega +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/angular_position_is_arc_length_over_radius.py b/symplyphysics/laws/kinematics/angular_position_is_arc_length_over_radius.py index fee98d228..e5b0f951d 100644 --- a/symplyphysics/laws/kinematics/angular_position_is_arc_length_over_radius.py +++ b/symplyphysics/laws/kinematics/angular_position_is_arc_length_over_radius.py @@ -9,49 +9,28 @@ """ from sympy import Eq -from symplyphysics import ( - units, - Quantity, - Symbol, - validate_input, - validate_output, - angle_type, -) +from symplyphysics import Quantity, validate_input, validate_output, symbols -angular_position = Symbol("angular_position", angle_type) +angular_position = symbols.angular_distance r""" -Angular position of the body. - -Symbol: - :code:`theta` - -Latex: - :math:`\theta` +:symbols:`angular_distance` of the body. """ -arc_length = Symbol("arc_length", units.length) +arc_length = symbols.arc_length """ -Arc length. - -Symbol: - :code:`s` +:symbols:`arc_length` of the curve traced by the body's movement. """ -distance_to_axis = Symbol("distance_to_axis", units.length) +distance_to_axis = symbols.distance_to_axis """ -Distance to rotational axis, or radius of rotation. - -Symbol: - :code:`r` +:symbols:`distance_to_axis` of rotation, or radius of rotation. """ law = Eq(angular_position, arc_length / distance_to_axis) -r""" -:code:`theta = s / r` +""" +:laws:symbol:: -Latex: - .. math:: - \theta = \frac{s}{r} +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/angular_position_via_constant_angular_acceleration_and_time.py b/symplyphysics/laws/kinematics/angular_position_via_constant_angular_acceleration_and_time.py index 3800ff065..7d07559fd 100644 --- a/symplyphysics/laws/kinematics/angular_position_via_constant_angular_acceleration_and_time.py +++ b/symplyphysics/laws/kinematics/angular_position_via_constant_angular_acceleration_and_time.py @@ -10,12 +10,11 @@ from sympy import Eq, solve, dsolve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, - angle_type, + symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.symbols.quantities import scale_factor @@ -24,68 +23,39 @@ angular_speed_is_angular_distance_derivative as angular_velocity_def, ) -final_angular_position = Symbol("final_angular_position", angle_type) -r""" -Angular position at time :math:`t`. - -Symbol: - :code:`theta` - -Latex: - :math:`\theta` +final_angular_position = symbols.angular_distance """ - -initial_angular_position = Symbol("initial_angular_position", angle_type) -r""" -Angular position at :math:`t = 0`. - -Symbol: - :code:`theta_0` - -Latex: - :math:`\theta_0` +:symbols:`angular_distance` at :attr:`~time`. """ -initial_angular_speed = Symbol("initial_angular_speed", angle_type / units.time) -r""" -Angular speed at :math:`t = 0`. - -Symbol: - :code:`w_0` - -Latex: - :math:`\omega_0` +initial_angular_position = clone_as_symbol(symbols.angular_distance, subscript="0") +""" +:symbols:`angular_distance` at :math:`t = 0`. """ -angular_acceleration = Symbol("angular_acceleration", angle_type / units.time**2) -r""" -Constant angular acceleration. - -Symbol: - :code:`alpha` - -Latex: - :math:`\alpha` +initial_angular_speed = clone_as_symbol(symbols.angular_speed, subscript="0") +""" +:symbols:`angular_speed` at :math:`t = 0`. """ -time = Symbol("time", units.time) -r""" -Time at which :math:`\theta` is measured. +angular_acceleration = symbols.angular_acceleration +""" +Constant :symbols:`angular_acceleration`. +""" -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` at which :attr:`~final_angular_position` is measured. """ law = Eq( final_angular_position, initial_angular_position + initial_angular_speed * time + angular_acceleration * time**2 / 2, ) -r""" -:code:`theta = theta_0 + w_0 * t + 1/2 * alpha * t^2` +""" +:laws:symbol:: -Latex: - .. math:: - \theta = \theta_0 + \omega_0 t + \frac{1}{2} \alpha t^2 +:laws:latex:: """ # Derive law from definitions of angular velocity and acceleration @@ -98,7 +68,7 @@ angular_acceleration, ).doit() -_angular_velocity = Symbol("_angular_velocity", angle_type / units.time) +_angular_velocity = symbols.angular_speed _angular_velocity_derived = solve( [ Eq(initial_angular_speed, _angular_velocity_formula.subs(time, 0)), diff --git a/symplyphysics/laws/kinematics/angular_position_via_constant_angular_speed_and_time.py b/symplyphysics/laws/kinematics/angular_position_via_constant_angular_speed_and_time.py index 4d1b8fd1a..f0f8cd95b 100644 --- a/symplyphysics/laws/kinematics/angular_position_via_constant_angular_speed_and_time.py +++ b/symplyphysics/laws/kinematics/angular_position_via_constant_angular_speed_and_time.py @@ -11,67 +11,43 @@ from sympy import Eq, solve, dsolve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, - angle_type, + symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import angular_speed_is_angular_distance_derivative as angular_velocity_def -final_angular_position = Symbol("final_angular_position", angle_type) -r""" -Angular position at time :math:`t`. - -Symbol: - :code:`theta` - -Latex: - :math:`\theta` +final_angular_position = symbols.angular_distance """ - -initial_angular_position = Symbol("initial_angular_position", angle_type) -r""" -Angular position at :math:`t = 0`. - -Symbol: - :code:`theta_0` - -Latex: - :math:`\theta_0` +:symbols:`angular_distance` at :attr:`~time`. """ -angular_speed = Symbol("angular_speed", angle_type / units.time) -r""" -Constant angular speed. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +initial_angular_position = clone_as_symbol(symbols.angular_distance, subscript="0") +""" +:symbols:`angular_distance` at :math:`t = 0`. """ -time = Symbol("time", units.time) -r""" -Time at which :math:`\theta` is measured. +angular_speed = symbols.angular_speed +""" +Constant :symbols:`angular_speed`. +""" -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` at which :attr:`~final_angular_position` is measured. """ law = Eq( final_angular_position, initial_angular_position + angular_speed * time, ) -r""" -:code:`theta = theta_0 + w * t` +""" +:laws:symbol:: -Latex: - .. math:: - \theta = \theta_0 + \omega t +:laws:latex:: """ # Derive law from definition of angular velocity diff --git a/symplyphysics/laws/kinematics/angular_speed_via_constant_angular_acceleration_and_time.py b/symplyphysics/laws/kinematics/angular_speed_via_constant_angular_acceleration_and_time.py index e14003505..3595b64a9 100644 --- a/symplyphysics/laws/kinematics/angular_speed_via_constant_angular_acceleration_and_time.py +++ b/symplyphysics/laws/kinematics/angular_speed_via_constant_angular_acceleration_and_time.py @@ -13,65 +13,41 @@ from sympy import Eq, dsolve, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, - angle_type, + symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import ( angular_acceleration_is_angular_speed_derivative as angular_acceleration_def,) -final_angular_speed = Symbol("final_angular_speed", angle_type / units.time) -r""" -Angular speed at time :math:`t`. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +final_angular_speed = symbols.angular_speed """ - -initial_angular_speed = Symbol("initial_angular_speed", angle_type / units.time) -r""" -Angular speed at :math:`t = 0`. - -Symbol: - :code:`w_0` - -Latex: - :math:`\omega_0` +:symbols:`angular_speed` at :attr:`~time`. """ -angular_acceleration = Symbol("angular_acceleration", angle_type / units.time**2) -r""" -Constant angular acceleration. - -Symbol: - :code:`alpha` - -Latex: - :math:`\alpha` +initial_angular_speed = clone_as_symbol(symbols.angular_speed, subscript="0") +""" +:symbols:`angular_speed` at :math:`t = 0`. """ -time = Symbol("time", units.time) +angular_acceleration = symbols.angular_acceleration r""" -Time at which :math:`\omega` is measured. +Constant :symbols:`angular_acceleration`. +""" -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` at which :attr:`~final_angular_speed` is measured. """ law = Eq(final_angular_speed, initial_angular_speed + angular_acceleration * time) -r""" -:code:`w = w_0 + alpha * t` +""" +:laws:symbol:: -Latex: - .. math:: - \omega = \omega_0 + \alpha t +:laws:latex:: """ # Derive this law from definition of angular acceleration diff --git a/symplyphysics/laws/kinematics/average_angular_speed_is_angular_distance_over_time.py b/symplyphysics/laws/kinematics/average_angular_speed_is_angular_distance_over_time.py index 1229dfd1d..a413c0979 100644 --- a/symplyphysics/laws/kinematics/average_angular_speed_is_angular_distance_over_time.py +++ b/symplyphysics/laws/kinematics/average_angular_speed_is_angular_distance_over_time.py @@ -7,48 +7,35 @@ """ from sympy import (Eq, solve) -from symplyphysics import (angle_type, units, Quantity, Symbol, validate_input, validate_output) +from symplyphysics import (Quantity, validate_input, validate_output, symbols, clone_as_symbol) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.symbols.quantities import scale_factor from symplyphysics.definitions import temporal_frequency_is_number_of_events_per_unit_time as frequency_def -average_angular_speed = Symbol("average_angular_speed", angle_type / units.time) -r""" -Average angular speed of rotation. - -Symbol: - :code:`avg(w)` - -Latex: - :math:`\langle \omega \rangle` +average_angular_speed = clone_as_symbol( + symbols.angular_speed, + display_symbol="avg(w)", + display_latex="\\langle \\omega \\rangle", +) """ - -angular_distance = Symbol("angular_distance", angle_type) -r""" -Total angular distance in radians. - -Symbol: - :code:`theta` - -Latex: - :math:`\theta` +Average :symbols:`angular_speed` of rotation. """ -time = Symbol("time", units.time) +angular_distance = symbols.angular_distance +""" +Total :symbols:`angular_distance` in radians. """ -Time elapsed during rotation. -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` elapsed during rotation. """ law = Eq(average_angular_speed, angular_distance / time) -r""" -:code:`avg(w) = theta / t` +""" +:laws:symbol:: -Latex: - .. math:: - \langle \omega \rangle = \frac{\theta}{t} +:laws:latex:: """ # Derive the same law from temporal frequency definition diff --git a/symplyphysics/laws/kinematics/centripetal_acceleration_via_angular_speed_and_radius.py b/symplyphysics/laws/kinematics/centripetal_acceleration_via_angular_speed_and_radius.py index 252eaf32c..1c8c77d1f 100644 --- a/symplyphysics/laws/kinematics/centripetal_acceleration_via_angular_speed_and_radius.py +++ b/symplyphysics/laws/kinematics/centripetal_acceleration_via_angular_speed_and_radius.py @@ -9,10 +9,7 @@ from symplyphysics import ( clone_as_symbol, symbols, - units, Quantity, - Symbol, - angle_type, validate_input, validate_output, ) @@ -22,39 +19,26 @@ speed_via_angular_speed_and_radius as velocities_law, ) -centripetal_acceleration = clone_as_symbol(symbols.acceleration, - display_symbol="a_n", - display_latex="a_n") +centripetal_acceleration = clone_as_symbol(symbols.acceleration, subscript="n") """ Centripetal, or normal, :symbols:`acceleration`. """ -angular_speed = Symbol("angular_speed", angle_type / units.time) -r""" -Angular speed. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +angular_speed = symbols.angular_speed """ - -radius_of_curvature = Symbol("radius_of_curvature", units.length) +:symbols:`angular_speed`. """ -Instantaneous radius of curvature. -Symbol: - :code:`r` +radius_of_curvature = symbols.radius_of_curvature +""" +Instantaneous :symbols:`radius_of_curvature`. """ law = Eq(centripetal_acceleration, angular_speed**2 * radius_of_curvature) -r""" -:code:`a_n = w^2 * r` +""" +:laws:symbol:: -Latex: - .. math:: - a_n = \omega^2 r +:laws:latex:: """ # Derive law from expression for linear velocity in circular motion diff --git a/symplyphysics/laws/kinematics/centripetal_acceleration_via_linear_speed_and_radius.py b/symplyphysics/laws/kinematics/centripetal_acceleration_via_linear_speed_and_radius.py index 001d31258..1476e16c7 100644 --- a/symplyphysics/laws/kinematics/centripetal_acceleration_via_linear_speed_and_radius.py +++ b/symplyphysics/laws/kinematics/centripetal_acceleration_via_linear_speed_and_radius.py @@ -5,9 +5,17 @@ *Centripetal acceleration* is defined as the change in velocity tangential to the velocity vector. """ -from sympy import (Eq, solve, sin, cos, Derivative, pi) -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, Function, angle_type, - CoordinateSystem, Vector, validate_input, validate_output) +from sympy import Eq, solve, sin, cos, Derivative, pi +from symplyphysics import ( + clone_as_symbol, + symbols, + Quantity, + CoordinateSystem, + Vector, + validate_input, + validate_output, + clone_as_function, +) from symplyphysics.core.expr_comparisons import expr_equals, expr_equals_abs from symplyphysics.core.vectors.arithmetics import dot_vectors from symplyphysics.definitions import speed_is_distance_derivative as velocity_def @@ -16,36 +24,26 @@ from symplyphysics.laws.geometry import planar_projection_is_cosine as projector from symplyphysics.laws.kinematics import speed_via_angular_speed_and_radius as linear_velocity_law -centripetal_acceleration = clone_as_symbol(symbols.acceleration, - display_symbol="a_n", - display_latex="a_n") +centripetal_acceleration = clone_as_symbol(symbols.acceleration, subscript="n") """ Centripetal, or normal, :symbols:`acceleration`. """ -speed = Symbol("speed", units.velocity) +speed = symbols.speed """ -Linear speed. - -Symbol: - :code:`v` +Linear :symbols:`speed`. """ -radius_of_curvature = Symbol("radius_of_curvature", units.length) +radius_of_curvature = symbols.radius_of_curvature """ -Instantaneous radius of curvature. - -Symbol: - :code:`r` +Instantaneous :symbols:`radius_of_curvature`. """ law = Eq(centripetal_acceleration, speed**2 / radius_of_curvature) -r""" -:code:`a_n = v^2 / r` +""" +:laws:symbol:: -Latex: - .. math:: - a_n = \frac{v^2}{r} +:laws:latex:: """ # Derive the same law from acceleration and velocity definitions @@ -53,8 +51,8 @@ ## Let's assume we are having movement in 2-D space. ## Object position is described with it's radius-vector R - the vector from zero coordinates to the object and with angle '_alpha' between X-axis and this radius-vector. -_time = Symbol("_time", units.time) -_alpha = Function("_alpha", angle_type, positive=True) +_time = symbols.time +_alpha = clone_as_function(symbols.angular_distance, [_time]) _cartesian_coordinates = CoordinateSystem() _curve_radius_horisontal = projector.law.rhs.subs({ diff --git a/symplyphysics/laws/kinematics/classical_addition_of_velocities.py b/symplyphysics/laws/kinematics/classical_addition_of_velocities.py index 8fb97a2c1..0cc407105 100644 --- a/symplyphysics/laws/kinematics/classical_addition_of_velocities.py +++ b/symplyphysics/laws/kinematics/classical_addition_of_velocities.py @@ -16,50 +16,36 @@ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, + symbols, + clone_as_symbol, ) -body_speed_in_first_frame = Symbol("body_speed_in_first_frame", units.velocity) +body_speed_in_first_frame = clone_as_symbol(symbols.speed, subscript="OA") """ -Speed of the body in frame :math:`A`. - -Symbol: - :code:`u` +:symbols:`speed` of the body in frame :math:`A`. """ -body_speed_in_second_frame = Symbol("body_speed_in_second_frame", units.velocity) -r""" -Speed of the body in frame :math:`B`. - -Symbol: - :code:`u'` - -Latex: - :math:`u'` +body_speed_in_second_frame = clone_as_symbol(symbols.speed, subscript="OB") """ - -second_frame_speed_in_first_frame = Symbol("second_frame_speed_in_first_frame", units.velocity) +:symbols:`speed` of the body in frame :math:`B`. """ -Speed of frame :math:`B` relative to frame :math:`A`. -Symbol: - :code:`v` +second_frame_speed_in_first_frame = clone_as_symbol(symbols.speed, subscript="BA") +""" +:symbols:`speed` of frame :math:`B` relative to frame :math:`A`. """ law = Eq( body_speed_in_first_frame, body_speed_in_second_frame + second_frame_speed_in_first_frame, ) -r""" -:code:`u = u' + v` +""" +:laws:symbol:: -Latex: - .. math:: - u = u' + v +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/damped_oscillations/damped_angular_frequency.py b/symplyphysics/laws/kinematics/damped_oscillations/damped_angular_frequency.py index 44d432cdd..a823c0b65 100644 --- a/symplyphysics/laws/kinematics/damped_oscillations/damped_angular_frequency.py +++ b/symplyphysics/laws/kinematics/damped_oscillations/damped_angular_frequency.py @@ -14,55 +14,37 @@ from sympy import Eq, sqrt from symplyphysics import ( - units, Quantity, - Symbol, - angle_type, - dimensionless, validate_input, validate_output, + symbols, + clone_as_symbol, ) -damped_angular_frequency = Symbol("damped_angular_frequency", angle_type / units.time) -r""" -Angular frequency of a damped oscillator. - -Symbol: - :code:`w_d` - -Latex: - :math:`\omega_\text{d}` +damped_angular_frequency = clone_as_symbol( + symbols.angular_frequency, + display_symbol="w_d", + display_latex="\\omega_\\text{d}", +) """ - -undamped_angular_frequency = Symbol("undamped_angular_frequency", angle_type / units.time) -r""" -Angular frequency of an undamped oscillator. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +:symbols:`angular_frequency` of a damped oscillator. """ -damping_ratio = Symbol("damping_ratio", dimensionless) -r""" -Damping ratio of the oscillator. - -Symbol: - :code:`zeta` +undamped_angular_frequency = symbols.angular_frequency +""" +:symbols:`angular_frequency` of an undamped oscillator. +""" -Latex: - :math:`\zeta` +damping_ratio = symbols.damping_ratio +""" +:symbols:`damping_ratio` of the oscillator. """ law = Eq(damped_angular_frequency, undamped_angular_frequency * sqrt(1 - damping_ratio**2)) -r""" -:code:`w_d = w * sqrt(1 - zeta^2)` +""" +:laws:symbol:: -Latex: - .. math:: - \omega_\text{d} = \omega \sqrt{1 - \zeta^2} +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/damped_oscillations/damping_ratio_from_decay_constant_and_undamped_frequency.py b/symplyphysics/laws/kinematics/damped_oscillations/damping_ratio_from_decay_constant_and_undamped_frequency.py index f9680cb70..153174143 100644 --- a/symplyphysics/laws/kinematics/damped_oscillations/damping_ratio_from_decay_constant_and_undamped_frequency.py +++ b/symplyphysics/laws/kinematics/damped_oscillations/damping_ratio_from_decay_constant_and_undamped_frequency.py @@ -7,56 +7,28 @@ """ from sympy import Eq -from symplyphysics import ( - units, - Quantity, - Symbol, - angle_type, - dimensionless, - validate_input, - validate_output, -) - -damping_ratio = Symbol("damping_ratio", dimensionless) -r""" -Damping ratio of the oscillator. - -Symbol: - :code:`zeta` +from symplyphysics import Quantity, validate_input, validate_output, symbols -Latex: - :math:`\zeta` +damping_ratio = symbols.damping_ratio +""" +:symbols:`damping_ratio` of the oscillator. """ -exponential_decay_constant = Symbol("exponential_decay_constant", 1 / units.time) -r""" -Exponential decay constant of the oscillator. - -Symbol: - :code:`lambda` - -Latex: - :math:`\lambda` +exponential_decay_constant = symbols.exponential_decay_constant +""" +:symbols:`exponential_decay_constant` of the oscillator. """ -undamped_angular_frequency = Symbol("undamped_angular_frequency", angle_type / units.time) +undamped_angular_frequency = symbols.angular_frequency r""" -Undamped angular frequency of the oscillator. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +Undamped :symbols:`angular_frequency` of the oscillator. """ law = Eq(damping_ratio, exponential_decay_constant / undamped_angular_frequency) -r""" -:code:`zeta = lambda / w` +""" +:laws:symbol:: -Latex: - .. math:: - \zeta = \frac{\lambda}{\omega} +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_critical_damping.py b/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_critical_damping.py index 189bee58b..8b631ccf9 100644 --- a/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_critical_damping.py +++ b/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_critical_damping.py @@ -12,67 +12,41 @@ #. The system is critically damped, i.e. its damping ratio :math:`\zeta = 1`. """ -from sympy import Eq, exp, dsolve, solve, Function as SymFunction, symbols +from sympy import Eq, exp, dsolve, solve from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, - angle_type, + symbols, + clone_as_symbol, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import damped_harmonic_oscillator_equation as damped_eqn -displacement = Symbol("displacement", units.length, real=True) +displacement = symbols.euclidean_distance """ -Displacement from rest, usually a function of time. - -Symbol: - :code:`q` +Displacement from rest, usually a function of time. See :symbols:`euclidean_distance`. """ -time = Symbol("time", units.time, nonnegative=True) -r""" -Time at which :math:`q` is measured. - -Symbol: - :code:`t` +time = symbols.time """ - -undamped_angular_frequency = Symbol("undamped_angular_frequency", - angle_type / units.time, - positive=True) -r""" -Angular frequency of the undamped oscillator. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +:symbols:`time` at which :attr:`~displacement` is measured. """ -initial_position = Symbol("initial_position", units.length, real=True) +undamped_angular_frequency = symbols.angular_frequency """ -Initial position of the oscillator. - -Symbol: - :code:`x0` - -Latex: - :math:`x_0` +:symbols:`angular_frequency` of the undamped oscillator. """ -initial_speed = Symbol("initial_speed", units.velocity, real=True) +initial_position = clone_as_symbol(symbols.position, subscript="0") +""" +Initial :symbols:`position` of the oscillator. """ -Initial speed of the oscillator. - -Symbol: - :code:`v0` -Latex: - :math:`v_0` +initial_speed = clone_as_symbol(symbols.speed, subscript="0") +""" +Initial :symbols:`speed` of the oscillator. """ law = Eq( @@ -80,17 +54,15 @@ exp(-1 * undamped_angular_frequency * time) * (initial_position + (initial_speed + initial_position * undamped_angular_frequency) * time), ) -r""" -:code:`q = exp(-1 * w * t) * (x0 + (v0 + x0 * w) * t)` +""" +:laws:symbol:: -Latex: - .. math:: - q = \exp(- \omega t) (x_0 + (v_0 + x_0 \omega) t) +:laws:latex:: """ # Derive from damped oscillator equation -_displacement = symbols("displacement", real=True, cls=SymFunction) +_displacement = clone_as_function(displacement, [time]) _eqn = damped_eqn.definition.subs(damped_eqn.time, time).subs({ damped_eqn.displacement(time): _displacement(time), diff --git a/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_underdamping.py b/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_underdamping.py index d53fe0960..a319b55e3 100644 --- a/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_underdamping.py +++ b/symplyphysics/laws/kinematics/damped_oscillations/displacement_in_underdamping.py @@ -12,14 +12,15 @@ #. The system is underdamped, i.e. its damping ratio :math:`\zeta < 1`. """ -from sympy import Eq, exp, cos, solve, symbols +from sympy import Eq, exp, cos, solve from symplyphysics import ( units, Quantity, - Symbol, + SymbolNew, validate_input, validate_output, - angle_type, + symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.symbols.quantities import scale_factor @@ -29,83 +30,56 @@ damped_angular_frequency as damped_frequency_law, ) -displacement = Symbol("displacement", units.length, real=True) +displacement = symbols.euclidean_distance """ -Displacement from rest, usually a function of time. - -Symbol: - :code:`q` +Displacement from rest, usually a function of time. See :symbols:`euclidean_distance`. """ -time = Symbol("time", units.time, real=True) -r""" -Time at which :math:`q` is measured. - -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` at which :attr:`~displacement` is measured. """ -scaling_coefficient = Symbol("scaling_coefficient", units.length, real=True) +scaling_coefficient = SymbolNew("a", units.length, real=True) """ Scaling coefficient to be found using initial conditions. - -Symbol: - :code:`a` """ -exponential_decay_constant = Symbol("exponential_decay_constant", 1 / units.time, positive=True) -r""" -Exponential decay constant of the oscillator. - -Symbol: - :code:`lambda` - -Latex: - :math:`\lambda` +exponential_decay_constant = symbols.exponential_decay_constant +""" +:symbols:`exponential_decay_constant` of the oscillator. """ -damped_angular_frequency = Symbol("damped_angular_frequency", - angle_type / units.time, - positive=True) -r""" +damped_angular_frequency = clone_as_symbol( + symbols.angular_frequency, + display_symbol="w_d", + display_latex="\\omega_\\text{d}", +) +""" :doc:`Damped angular frequency ` -of the oscillator. - -Symbol: - :code:`w_d` - -Latex: - :math:`\omega_\text{d}` +of the oscillator. See :symbols:`angular_frequency`. """ -phase_shift = Symbol("phase_shift", angle_type, real=True) -r""" -Phase shift of the oscillations, i.e. the phase at :math:`t = 0`. - -Symbol: - :code:`phi` - -Latex: - :math:`\varphi` +phase_shift = symbols.phase_shift +""" +:symbols:`phase_shift` of the oscillations, i.e. the phase at :math:`t = 0`. """ law = Eq( displacement, scaling_coefficient * exp(-1 * exponential_decay_constant * time) * cos(damped_angular_frequency * time + phase_shift)) -r""" -:code:`q = a * exp(-1 * lambda * t) * cos(w_d * t + phi)` +""" +:laws:symbol:: -Latex: - .. math:: - q = a \exp(-\lambda t) \cos(\omega_\text{d} t + \varphi) +:laws:latex:: """ # Relating to [damped oscillations equation](../../../definitions/damped_harmonic_oscillator_equation.py) ## We will show it is the solution of the aforementioned equation. -_damping_ratio_sym, _undamped_frequency_sym = symbols("damping_ratio undamped_frequency", - positive=True) +_damping_ratio_sym = symbols.damping_ratio +_undamped_frequency_sym = symbols.angular_frequency _decay_eqn = damping_ratio_law.law.subs({ damping_ratio_law.damping_ratio: _damping_ratio_sym, diff --git a/symplyphysics/laws/kinematics/displacement_in_simple_harmonic_motion.py b/symplyphysics/laws/kinematics/displacement_in_simple_harmonic_motion.py index 04ac0ccd7..dbae4acbb 100644 --- a/symplyphysics/laws/kinematics/displacement_in_simple_harmonic_motion.py +++ b/symplyphysics/laws/kinematics/displacement_in_simple_harmonic_motion.py @@ -5,82 +5,69 @@ Any motion that repeats at regular intervals is called periodic, or harmonic, motion. Simple harmonic motion is a particular type of repeated motion that is a sinusoidal function of time. + +**Note:** + +#. This law is also applicable for any physical quantity that changes its value in + a repeating harmonic manner, therefore :symbols:`any_quantity` is used. """ -from sympy import Eq, cos, symbols, dsolve, Function as SymFunction +from sympy import Eq, cos, dsolve from symplyphysics import ( - units, Quantity, - Symbol, - angle_type, validate_input, + symbols, + clone_as_symbol, + clone_as_function, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.core.quantity_decorator import validate_output_same from symplyphysics.core.symbols.quantities import scale_factor from symplyphysics.definitions import harmonic_oscillator_is_second_derivative_equation as harmonic_eqn -displacement = symbols("displacement", real=True) +displacement = clone_as_symbol( + symbols.any_quantity, + display_symbol="q", + display_latex="q", +) """ -Displacement from rest, usually a function of time. - -Symbol: - :code:`q` +Displacement from rest, usually a function of :symbols:`time`. See :symbols:`any_quantity`. """ -amplitude = symbols("amplitude", positive=True) -r""" -The maximum absolute value of the displacement. - -Symbol: - :code:`q_max` - -Latex: - :math:`q_\text{max}` +amplitude = clone_as_symbol( + symbols.any_quantity, + display_symbol="q_max", + display_latex="q_\\text{max}", +) """ - -angular_frequency = Symbol("angular_frequency", angle_type / units.time, positive=True) -r""" -Angular frequency of oscillations. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +The maximum absolute value of the :attr:`~displacement`. See :symbols:`any_quantity`. """ -phase_shift = Symbol("phase_shift", angle_type, real=True) -r""" -Phase shift of oscillations, which is the phase at :math:`t = 0`. - -Symbol: - :code:`phi` - -Latex: - :math:`\varphi` +angular_frequency = clone_as_symbol(symbols.angular_frequency, positive=True) +""" +:symbols:`angular_frequency` of oscillations. """ -time = Symbol("time", units.time, real=True) +phase_shift = symbols.phase_shift +""" +:symbols:`phase_shift` of oscillations, which is the phase at :math:`t = 0`. """ -Time at which :math:`q` is measured. -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` at which :attr:`~displacement` is measured. """ law = Eq(displacement, amplitude * cos(angular_frequency * time + phase_shift)) -r""" -:code:`q = q_max * cos(w * t + phi)` +""" +:laws:symbol:: -Latex: - .. math:: - q = q_\text{max} \cos(\omega t + \varphi) +:laws:latex:: """ # Derive law from [oscillator equation](../../definitions/harmonic_oscillator_is_second_derivative_equation.py) -_displacement = symbols("displacement", cls=SymFunction, real=True) +_displacement = clone_as_function(displacement, [time]) _eqn = harmonic_eqn.definition.replace(harmonic_eqn.displacement, _displacement).subs({ harmonic_eqn.time: time, diff --git a/symplyphysics/laws/kinematics/position_via_constant_acceleration_and_time.py b/symplyphysics/laws/kinematics/position_via_constant_acceleration_and_time.py index 0680e7da5..8e3f241ef 100644 --- a/symplyphysics/laws/kinematics/position_via_constant_acceleration_and_time.py +++ b/symplyphysics/laws/kinematics/position_via_constant_acceleration_and_time.py @@ -9,40 +9,31 @@ #. Acceleration is constant, i.e. :math:`\frac{d a}{d t} = 0.` """ -from sympy import (Eq, solve, dsolve) -from symplyphysics import (symbols, units, Quantity, Symbol, validate_input, validate_output) +from sympy import Eq, solve, dsolve +from symplyphysics import ( + symbols, + Quantity, + validate_input, + validate_output, + clone_as_symbol, +) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import speed_is_distance_derivative as _velocity_definition from symplyphysics.definitions import acceleration_is_speed_derivative as _acceleration_definition -final_position = Symbol("final_position", units.length) +final_position = symbols.position """ -Position at time :math:`t`. - -Symbol: - :code:`x` +:symbols:`position` at :attr:`~time`. """ -initial_position = Symbol("initial_position", units.length) +initial_position = clone_as_symbol(symbols.position, subscript="0") """ -Position at :math:`t = 0`. - -Symbol: - :code:`x0` - -Latex: - :math:`x_0` +:symbols:`position` at :math:`t = 0`. """ -initial_speed = Symbol("initial_speed", units.velocity) +initial_speed = clone_as_symbol(symbols.speed, subscript="0") """ -Speed at :math:`t = 0`. - -Symbol: - :code:`v0` - -Latex: - :math:`v_0` +:symbols:`speed` at :math:`t = 0`. """ acceleration = symbols.acceleration @@ -50,21 +41,16 @@ Constant :symbols:`acceleration`. """ -time = Symbol("time", units.time) +time = symbols.time """ -Time at which :math:`x` is measured. - -Symbol: - :code:`t` +:symbols:`time` at which :attr:`~final_position` is measured. """ law = Eq(final_position, initial_position + initial_speed * time + acceleration * time**2 / 2) -r""" -:code:`x = x0 + v0 * t + (1/2) * a * t^2` +""" +:laws:symbol:: -Latex: - .. math:: - x = x_0 + v_0 t + \frac{1}{2} a t^2 +:laws:latex:: """ # Derive the same law from velocity and acceleration definitions diff --git a/symplyphysics/laws/kinematics/position_via_constant_speed_and_time.py b/symplyphysics/laws/kinematics/position_via_constant_speed_and_time.py index 4130d0f36..7d4559590 100644 --- a/symplyphysics/laws/kinematics/position_via_constant_speed_and_time.py +++ b/symplyphysics/laws/kinematics/position_via_constant_speed_and_time.py @@ -11,52 +11,35 @@ """ from sympy import (Eq, solve, dsolve) -from symplyphysics import (units, Quantity, Symbol, validate_input, validate_output) +from symplyphysics import (Quantity, validate_input, validate_output, symbols, clone_as_symbol) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.definitions import speed_is_distance_derivative as velocity_definition -final_position = Symbol("distance_function", units.length) +final_position = symbols.position """ -Position at time :math:`t`. - -Symbol: - :code:`x` +:symbols:`position` at :attr:`~time`. """ -initial_position = Symbol("initial_position", units.length) +initial_position = clone_as_symbol(symbols.position, subscript="0") """ -Position at :math:`t = 0`. - -Symbol: - :code:`x0` - -Latex: - :math:`x_0` +:symbols:`position` at :math:`t = 0`. """ -speed = Symbol("speed", units.velocity, constant=True) +speed = symbols.speed """ -Constant speed. - -Symbol: - :code:`v` +Constant :symbols:`speed`. """ -time = Symbol("time", units.time) +time = symbols.time """ -Time at which :math:`x` is measured. - -Symbol: - :code:`t` +:symbols:`time` at which :attr:`~final_position` is measured. """ law = Eq(final_position, initial_position + speed * time) -r""" -:code:`x = x0 + v * t` +""" +:laws:symbol:: -Latex: - .. math:: - x = x_0 + v t +:laws:latex:: """ # Derive the same law from velocity definition diff --git a/symplyphysics/laws/kinematics/rotational_inertia/geometries/slab_about_perpendicular_axis_through_center.py b/symplyphysics/laws/kinematics/rotational_inertia/geometries/slab_about_perpendicular_axis_through_center.py index 57601148e..16d5f9a81 100644 --- a/symplyphysics/laws/kinematics/rotational_inertia/geometries/slab_about_perpendicular_axis_through_center.py +++ b/symplyphysics/laws/kinematics/rotational_inertia/geometries/slab_about_perpendicular_axis_through_center.py @@ -11,40 +11,30 @@ from sympy import Eq, sqrt from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, + clone_as_symbol, ) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.kinematics.rotational_inertia import ( rotational_inertia_cartesian_integral as integral_law,) from symplyphysics.definitions import density_from_mass_volume as density_def -rotational_inertia = Symbol("rotational_inertia", units.mass * units.length**2) +rotational_inertia = symbols.rotational_inertia """ -Rotational inertia of the slab. - -Symbol: - :code:`I` +:symbols:`rotational_inertia` of the slab. """ -length = Symbol("length", units.length) +length = clone_as_symbol(symbols.length, subscript="1") """ -Length, or first slab dimension perpendicular to the axis. - -Symbol: - :code:`a` +:symbols:`length`, or first slab dimension perpendicular to the axis. """ -width = Symbol("width", units.length) +width = clone_as_symbol(symbols.length, subscript="2") """ -Width, or second slab dimension perpendicular to the axis. - -Symbol: - :code:`b` +Width, or second slab dimension perpendicular to the axis. See :symbols:`length`. """ mass = symbols.mass @@ -53,12 +43,10 @@ """ law = Eq(rotational_inertia, mass * (length**2 + width**2) / 12) -r""" -:code:`I = 1/12 * m * (a^2 + b^2)` +""" +:laws:symbol:: -Latex: - .. math:: - I = \frac{1}{12} m (a^2 + b^2) +:laws:latex:: """ # Derive this law from the integral definition of rotational inertia in cartesian coordinates. @@ -68,7 +56,7 @@ ## z-axis is parallel to the rotational axis in question (_height of slab) ## x-axis and y-axis are perpendicular to the rotational axis (length and width of slab) -_height = Symbol("_height", units.length) +_height = symbols.height _volume = length * width * _height _density = density_def.definition.rhs.subs({ diff --git a/symplyphysics/laws/kinematics/rotational_inertia/geometries/solid_disk_about_central_axis.py b/symplyphysics/laws/kinematics/rotational_inertia/geometries/solid_disk_about_central_axis.py index 500e22b11..dd01995d9 100644 --- a/symplyphysics/laws/kinematics/rotational_inertia/geometries/solid_disk_about_central_axis.py +++ b/symplyphysics/laws/kinematics/rotational_inertia/geometries/solid_disk_about_central_axis.py @@ -11,9 +11,7 @@ from sympy import Eq, pi from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, @@ -22,20 +20,14 @@ from symplyphysics.laws.kinematics.rotational_inertia import rotational_inertia_cylindrical_integral as integral_law from symplyphysics.definitions import density_from_mass_volume as density_def -rotational_inertia = Symbol("rotational_inertia", units.mass * units.length**2) +rotational_inertia = symbols.rotational_inertia """ -Rotational inertia of the disk. - -Symbol: - :code:`I` +:symbols:`rotational_inertia` of the disk. """ -radius = Symbol("radius", units.length) +radius = symbols.radius """ -Radius of the disk. - -Symbol: - :code:`r` +:symbols:`radius` of the disk. """ mass = symbols.mass @@ -44,17 +36,15 @@ """ law = Eq(rotational_inertia, mass * radius**2 / 2) -r""" -:code:`I = 1/2 * m * r^2` +""" +:laws:symbol:: -Latex: - .. math:: - I = \frac{1}{2} m r^2 +:laws:latex:: """ # Derive law from general integral in cylindrical coordinates -_length = Symbol("_length", units.length) +_length = symbols.length _volume = pi * radius**2 * _length _density = density_def.definition.rhs.subs({ diff --git a/symplyphysics/laws/kinematics/rotational_inertia/geometries/thin_rod_about_axis_through_center_perpendicular_to_length.py b/symplyphysics/laws/kinematics/rotational_inertia/geometries/thin_rod_about_axis_through_center_perpendicular_to_length.py index 952f4bf82..b9f506bfd 100644 --- a/symplyphysics/laws/kinematics/rotational_inertia/geometries/thin_rod_about_axis_through_center_perpendicular_to_length.py +++ b/symplyphysics/laws/kinematics/rotational_inertia/geometries/thin_rod_about_axis_through_center_perpendicular_to_length.py @@ -12,9 +12,7 @@ from sympy import Eq from symplyphysics import ( - units, Quantity, - Symbol, validate_input, validate_output, symbols, @@ -23,20 +21,14 @@ from symplyphysics.laws.kinematics.rotational_inertia.geometries import ( slab_about_perpendicular_axis_through_center as slab_formula) -rotational_inertia = Symbol("rotational_inertia", units.mass * units.length**2) +rotational_inertia = symbols.rotational_inertia """ -Rotational inertia of the rod. - -Symbol: - :code:`I` +:symbols:`rotational_inertia` of the rod. """ -length = Symbol("length", units.length) +length = symbols.length """ -Length of the rod. - -Symbol: - :code:`l` +:symbols:`length` of the rod. """ mass = symbols.mass @@ -45,12 +37,10 @@ """ law = Eq(rotational_inertia, mass * length**2 / 12) -r""" -:code:`I = 1/12 * m * l^2` +""" +:laws:symbol:: -Latex: - .. math:: - I = \frac{1}{12} m l^2 +:laws:latex:: """ # Derive law from formula for a slab rotating about the axis perpendicular to its length and width diff --git a/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_about_axis_and_through_center_of_mass.py b/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_about_axis_and_through_center_of_mass.py index 497933317..e52e0241f 100644 --- a/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_about_axis_and_through_center_of_mass.py +++ b/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_about_axis_and_through_center_of_mass.py @@ -15,33 +15,26 @@ from sympy import Eq from symplyphysics import ( - units, - Symbol, Quantity, validate_input, validate_output, symbols, + clone_as_symbol, ) -rotational_inertia = Symbol("rotational_inertia", units.mass * units.length**2) +rotational_inertia = symbols.rotational_inertia """ -Rotational inertia about some axis. - -Symbol: - :code:`I` +:symbols:`rotational_inertia` about some axis. """ -rotational_inertia_through_com = Symbol("rotational_inertia_through_com", - units.mass * units.length**2) -r""" -Rotational inertia about an axis that is parallel to the given one and passes through +rotational_inertia_through_com = clone_as_symbol( + symbols.rotational_inertia, + display_symbol="I_com", + display_latex="I_\\text{com}", +) +""" +:symbols:`rotational_inertia` about an axis that is parallel to the given one and passes through the center of mass. - -Symbol: - :code:`I_com` - -Latex: - :math:`I_\text{com}` """ mass = symbols.mass @@ -49,24 +42,19 @@ The :symbols:`mass` of the body. """ -distance_between_axes = Symbol("distance_between_axes", units.length) +distance_between_axes = symbols.euclidean_distance """ -Distance between the axes. - -Symbol: - :code:`d` +:symbols:`euclidean_distance` between the axes. """ law = Eq( rotational_inertia, rotational_inertia_through_com + mass * distance_between_axes**2, ) -r""" -:code:`I = I_com + m * d^2` +""" +:laws:symbol:: -Latex: - .. math:: - I = I_\text{com} + m d^2 +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_of_particle.py b/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_of_particle.py index c30c9e956..cce0e6991 100644 --- a/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_of_particle.py +++ b/symplyphysics/laws/kinematics/rotational_inertia/rotational_inertia_of_particle.py @@ -7,29 +7,16 @@ """ from sympy import Eq -from symplyphysics import ( - units, - Quantity, - Symbol, - validate_input, - validate_output, - symbols, -) +from symplyphysics import Quantity, validate_input, validate_output, symbols -rotational_inertia = Symbol("rotational_inertia", units.mass * units.length**2) +rotational_inertia = symbols.rotational_inertia """ -Rotational inertia of the particle. - -Symbol: - :code:`I` +:symbols:`rotational_inertia` of the particle. """ -distance_to_axis = Symbol("distance_to_axis", units.length) +distance_to_axis = symbols.distance_to_axis """ -Distance to axis, or radius of rotation. - -Symbol: - :code:`r` +:symbols:`distance_to_axis`, or radius of rotation. """ mass = symbols.mass @@ -38,12 +25,10 @@ """ law = Eq(rotational_inertia, mass * distance_to_axis**2) -r""" -:code:`I = m * r^2` +""" +:laws:symbol:: -Latex: - .. math:: - I = m r^2 +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/speed_via_angular_speed_and_radius.py b/symplyphysics/laws/kinematics/speed_via_angular_speed_and_radius.py index 0bf2ca1be..1fe508717 100644 --- a/symplyphysics/laws/kinematics/speed_via_angular_speed_and_radius.py +++ b/symplyphysics/laws/kinematics/speed_via_angular_speed_and_radius.py @@ -6,43 +6,29 @@ radius of curvature of the body's path. """ -from sympy import (Eq, solve) -from symplyphysics import (units, Quantity, Symbol, angle_type, validate_input, validate_output) +from sympy import Eq, solve +from symplyphysics import Quantity, validate_input, validate_output, symbols -speed = Symbol("speed", units.velocity) +speed = symbols.speed """ -Linear speed. - -Symbol: - :code:`v` +Linear :symbols:`speed`. """ -angular_speed = Symbol("angular_speed", angle_type / units.time) -r""" -Angular speed. - -Symbol: - :code:`w` - -Latex: - :math:`\omega` +angular_speed = symbols.angular_speed +""" +:symbols:`angular_speed`. """ -radius_of_curvature = Symbol("radius_of_curvature", units.length) -r""" -Instantaneous radius of curvature. - -Symbol: - :code:`r` +radius_of_curvature = symbols.radius_of_curvature +""" +Instantaneous :symbols:`radius_of_curvature`. """ law = Eq(speed, angular_speed * radius_of_curvature) -r""" -:code:`v = w * r` +""" +:laws:symbol:: -Latex: - .. math:: - v = \omega r +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/speed_via_constant_acceleration_and_time.py b/symplyphysics/laws/kinematics/speed_via_constant_acceleration_and_time.py index 61bacf372..3cda1dc34 100644 --- a/symplyphysics/laws/kinematics/speed_via_constant_acceleration_and_time.py +++ b/symplyphysics/laws/kinematics/speed_via_constant_acceleration_and_time.py @@ -11,22 +11,16 @@ """ from sympy import (Eq, solve) -from symplyphysics import (symbols, units, Quantity, Symbol, validate_input, validate_output) +from symplyphysics import (symbols, Quantity, validate_input, validate_output, clone_as_symbol) -final_speed = Symbol("final_speed", units.velocity) -r""" -Speed at time :math:`t`. - -Symbol: - :code:`v` +final_speed = symbols.speed +""" +:symbols:`speed` at :attr:`~time`. """ -time = Symbol("time", units.time) -r""" -Time at which :math:`v` is measured. - -Symbol: - :code:`t` +time = symbols.time +""" +:symbols:`time` at which :attr:`~final_speed` is measured. """ acceleration = symbols.acceleration @@ -34,24 +28,16 @@ Constant :symbols:`acceleration`. """ -initial_speed = Symbol("initial_speed", units.velocity) +initial_speed = clone_as_symbol(symbols.speed, subscript="0") """ -Speed at :math:`t = 0`. - -Symbol: - :code:`v0` - -Latex: - :math:`v_0` +:symbols:`speed` at :math:`t = 0`. """ law = Eq(final_speed, initial_speed + acceleration * time) -r""" -:code:`v = v0 + a * t` +""" +:laws:symbol:: -Latex: - .. math:: - v = v_0 + a t +:laws:latex:: """ diff --git a/symplyphysics/laws/kinematics/tangential_acceleration_via_angular_acceleration_and_radius.py b/symplyphysics/laws/kinematics/tangential_acceleration_via_angular_acceleration_and_radius.py index 15d82c56b..2c9725bca 100644 --- a/symplyphysics/laws/kinematics/tangential_acceleration_via_angular_acceleration_and_radius.py +++ b/symplyphysics/laws/kinematics/tangential_acceleration_via_angular_acceleration_and_radius.py @@ -11,8 +11,14 @@ """ from sympy import Eq, solve, Derivative -from symplyphysics import (clone_as_symbol, symbols, units, Quantity, Symbol, Function, - validate_input, validate_output, angle_type) +from symplyphysics import ( + clone_as_symbol, + symbols, + Quantity, + validate_input, + validate_output, + clone_as_function, +) from symplyphysics.core.expr_comparisons import expr_equals from symplyphysics.laws.kinematics import speed_via_angular_speed_and_radius as linear_velocity_law from symplyphysics.definitions import angular_acceleration_is_angular_speed_derivative as angular_acceleration_def @@ -25,40 +31,29 @@ Tangential :symbols:`acceleration`. """ -angular_acceleration = Symbol("angular_acceleration", angle_type / units.time**2) -r""" -Angular acceleration. - -Symbol: - :code:`alpha` - -Latex: - :math:`\alpha` +angular_acceleration = symbols.angular_acceleration """ - -radius_of_curvature = Symbol("radius_of_curvature", units.length) +:symbols:`angular_acceleration`. """ -Instantaneous radius of curvature. -Symbol: - :code:`r` +radius_of_curvature = symbols.radius_of_curvature +""" +Instantaneous :symbols:`radius_of_curvature`. """ law = Eq(tangential_acceleration, angular_acceleration * radius_of_curvature) -r""" -:code:`a_t = alpha * r` +""" +:laws:symbol:: -Latex: - .. math:: - a_\tau = \alpha r +:laws:latex:: """ # Derive the law from the law of linear velocity in case of a rotating body # Condition: radius of rotation remains constant. -_linear_velocity = Function("_linear_velocity", units.velocity) -_angular_velocity = Function("_angular_velocity", angle_type / units.time) -_time = Symbol("_time", units.time) +_time = symbols.time +_linear_velocity = clone_as_function(symbols.speed, [_time]) +_angular_velocity = clone_as_function(symbols.angular_speed, [_time]) _linear_velocity_law_sub = linear_velocity_law.law.subs({ linear_velocity_law.speed: _linear_velocity(_time), diff --git a/symplyphysics/laws/optics/bragg_diffraction_from_angle_diffraction_order_wavelength.py b/symplyphysics/laws/optics/bragg_diffraction_from_angle_diffraction_order_wavelength.py index 2471cbf00..0ccef767f 100644 --- a/symplyphysics/laws/optics/bragg_diffraction_from_angle_diffraction_order_wavelength.py +++ b/symplyphysics/laws/optics/bragg_diffraction_from_angle_diffraction_order_wavelength.py @@ -24,9 +24,9 @@ symbols, ) -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` between crystal planes, also called the "grating constant" of the crystal. +:symbols:`euclidean_distance` between crystal planes, also called the "grating constant" of the crystal. """ diffraction_order = symbols.positive_number diff --git a/symplyphysics/laws/quantities/fractional_change_is_change_over_initial_value.py b/symplyphysics/laws/quantities/fractional_change_is_change_over_initial_value.py index 98397f992..c41309d63 100644 --- a/symplyphysics/laws/quantities/fractional_change_is_change_over_initial_value.py +++ b/symplyphysics/laws/quantities/fractional_change_is_change_over_initial_value.py @@ -2,56 +2,44 @@ Fractional change is change over initial value ============================================== - +Fractional change of a quantity is defined as ratio of the linear change of the quantity +to the initial value of the quantity. """ -from sympy import Eq, Symbol as SymSymbol +from sympy import Eq from symplyphysics import ( convert_to_float, - dimensionless, Quantity, - Symbol, validate_output, + symbols, + clone_as_symbol, ) from symplyphysics.core.dimensions import assert_equivalent_dimension -fractional_change = Symbol("fractional_change", dimensionless) -r""" -Fractional change of quantity :math:`X` - -Symbol: - :code:`e_X` - -Latex: - :math:`e_X` +fractional_change = clone_as_symbol(symbols.fractional_change, subscript="X") """ - -change = SymSymbol("change") -r""" -Change in the value of the quantity. - -Symbol: - :code:`dX` - -Latex: - :math:`\Delta X` +:symbols:`fractional_change` of quantity :math:`X`. """ -initial_value = SymSymbol("initial_value") +change = clone_as_symbol( + symbols.any_quantity, + display_symbol="Delta(X)", + display_latex="\\Delta X" +) +""" +Change in the value of the quantity. See :symbols:`any_quantity`. """ -Initial value of the quantity. -Symbol: - :code:`X` +initial_value = symbols.any_quantity +""" +Initial value of the quantity. See :symbols:`any_quantity`. """ law = Eq(fractional_change, change / initial_value) -r""" -:code:`e_X = dX / X` +""" +:laws:symbol:: -Latex: - .. math:: - e_X = \frac{\Delta X}{X} +:laws:latex:: """ diff --git a/symplyphysics/laws/quantities/quantity_is_areal_density_times_area.py b/symplyphysics/laws/quantities/quantity_is_areal_density_times_area.py index ceb6a39c0..e8e81c63e 100644 --- a/symplyphysics/laws/quantities/quantity_is_areal_density_times_area.py +++ b/symplyphysics/laws/quantities/quantity_is_areal_density_times_area.py @@ -6,46 +6,41 @@ density* by area. """ -from sympy import Eq, Symbol as SymSymbol +from sympy import Eq from symplyphysics import ( units, Quantity, - SymbolNew, validate_input, + symbols, + clone_as_symbol, ) from symplyphysics.core.dimensions import assert_equivalent_dimension -extensive_quantity = SymSymbol("extensive_quantity") +extensive_quantity = symbols.any_quantity """ -Extensive quantity. - -Symbol: - :code:`X` +Extensive quantity. See :symbols:`any_quantity`. """ -areal_density = SymSymbol("areal_density") +areal_density = clone_as_symbol( + symbols.any_quantity, + display_symbol="sigma_X", + display_latex="\\sigma_X", +) r""" -Intensive area-specific density. - -Symbol: - :code:`sigma_X` - -Latex: - :math:`\sigma_X` +Intensive area-specific density, which has the dimension of :attr:`~extensive_quantity` +divided by :attr:`~area`. See :symbols:`any_quantity`. """ -area = SymbolNew("A", units.area) +area = symbols.area """ -Area. +:symbols:`area`. """ law = Eq(extensive_quantity, areal_density * area) -r""" -:code:`X = sigma_X * A` +""" +:laws:symbol:: -Latex: - .. math:: - X = \sigma_X A +:laws:latex:: """ diff --git a/symplyphysics/laws/quantities/quantity_is_linear_density_times_length.py b/symplyphysics/laws/quantities/quantity_is_linear_density_times_length.py index 5947a803e..c290c4a26 100644 --- a/symplyphysics/laws/quantities/quantity_is_linear_density_times_length.py +++ b/symplyphysics/laws/quantities/quantity_is_linear_density_times_length.py @@ -6,49 +6,41 @@ density* by length. """ -from sympy import Eq, Symbol as SymSymbol +from sympy import Eq from symplyphysics import ( units, Quantity, - Symbol, validate_input, + symbols, + clone_as_symbol, ) from symplyphysics.core.dimensions import assert_equivalent_dimension -extensive_quantity = SymSymbol("extensive_quantity") +extensive_quantity = symbols.any_quantity """ -Extensive quantity - -Symbol: - :code:`X` +Extensive quantity. See :symbols:`any_quantity`. """ -linear_density = SymSymbol("linear_density") -r""" -Intensive linear density - -Symbol: - :code:`lambda_X` - -Latex: - :math:`\lambda_X` +linear_density = clone_as_symbol( + symbols.any_quantity, + display_symbol="lambda_X", + display_latex="\\lambda_X", +) """ - -length = Symbol("length", units.length) +Intensive linear density, which has the dimension of :attr:`~extensive_quantity` +divided by :attr:`~length`. See :symbols:`any_quantity`. """ -Length -Symbol: - :code:`L` +length = symbols.length +""" +:symbols:`length`. """ law = Eq(extensive_quantity, linear_density * length) -r""" -:code:`X = lambda_X * L` +""" +:laws:symbol:: -Latex: - .. math:: - X = \lambda_X L +:laws:latex:: """ diff --git a/symplyphysics/laws/quantities/quantity_is_molar_quantity_times_amount_of_substance.py b/symplyphysics/laws/quantities/quantity_is_molar_quantity_times_amount_of_substance.py index 60fe269e5..0d39eb8d5 100644 --- a/symplyphysics/laws/quantities/quantity_is_molar_quantity_times_amount_of_substance.py +++ b/symplyphysics/laws/quantities/quantity_is_molar_quantity_times_amount_of_substance.py @@ -6,49 +6,41 @@ intensive quantity by the amount of substance. """ -from sympy import Eq, Symbol as SymSymbol +from sympy import Eq from symplyphysics import ( units, Quantity, - Symbol, validate_input, + symbols, + clone_as_symbol, ) from symplyphysics.core.dimensions import assert_equivalent_dimension -extensive_quantity = SymSymbol("extensive_quantity") +extensive_quantity = symbols.any_quantity """ -Extensive property. - -Symbol: - :code:`X` +Extensive property. See :symbols:`any_quantity`. """ -molar_quantity = SymSymbol("molar_quantity") -r""" -Intensive molar quantity. - -Symbol: - :code:`X_m` - -Latex: - :math:`X_m` +molar_quantity = clone_as_symbol( + symbols.any_quantity, + display_symbol="x_m", + display_latex="x_m", +) """ - -amount_of_substance = Symbol("amount_of_substance", units.amount_of_substance) +Intensive molar quantity, which has the dimension of :attr:`~extensive_quantity` +divided by :attr:`~amount_of_substance`. See :symbols:`any_quantity`. """ -Amount of substance. -Symbol: - :code:`n` +amount_of_substance = symbols.amount_of_substance +""" +:symbols:`amount_of_substance`. """ law = Eq(extensive_quantity, molar_quantity * amount_of_substance) -r""" -:code:`X = X_m * n` +""" +:laws:symbol:: -Latex: - .. math:: - X = X_m n +:laws:latex:: """ diff --git a/symplyphysics/laws/quantities/quantity_is_specific_quantity_times_mass.py b/symplyphysics/laws/quantities/quantity_is_specific_quantity_times_mass.py index 3b4e09533..5bf4a5cee 100644 --- a/symplyphysics/laws/quantities/quantity_is_specific_quantity_times_mass.py +++ b/symplyphysics/laws/quantities/quantity_is_specific_quantity_times_mass.py @@ -6,46 +6,41 @@ intensive quantity by the mass. """ -from sympy import Eq, Symbol as SymSymbol +from sympy import Eq from symplyphysics import ( units, Quantity, validate_input, symbols, + clone_as_symbol, ) from symplyphysics.core.dimensions import assert_equivalent_dimension -extensive_quantity = SymSymbol("extensive_quantity") +extensive_quantity = symbols.any_quantity """ -Extensive quantity. - -Symbol: - :code:`X` +Extensive quantity. See :symbols:`any_quantity`. """ -specific_quantity = SymSymbol("specific_quantity") -r""" -Intensive mass-specific quantity. - -Symbol: - :code:`x` +specific_quantity = clone_as_symbol( + symbols.any_quantity, + display_symbol="x", + display_latex="x", +) +""" +Intensive mass-specific quantity, which has the dimension of :attr:`~extensive_quantity` +divided by :attr:`~mass`. See :symbols:`any_quantity`. """ mass = symbols.mass """ :symbols:`mass`. - -Symbol: - :code:`m` """ law = Eq(extensive_quantity, specific_quantity * mass) -r""" -:code:`X = x * m` +""" +:laws:symbol:: -Latex: - .. math:: - X = x m +:laws:latex:: """ diff --git a/symplyphysics/laws/quantities/quantity_is_volumetric_density_times_volume.py b/symplyphysics/laws/quantities/quantity_is_volumetric_density_times_volume.py index a92ea9fff..920b479ae 100644 --- a/symplyphysics/laws/quantities/quantity_is_volumetric_density_times_volume.py +++ b/symplyphysics/laws/quantities/quantity_is_volumetric_density_times_volume.py @@ -6,49 +6,41 @@ density* by volume. """ -from sympy import Eq, Symbol as SymSymbol +from sympy import Eq from symplyphysics import ( units, Quantity, - Symbol, validate_input, + symbols, + clone_as_symbol, ) from symplyphysics.core.dimensions import assert_equivalent_dimension -extensive_quantity = SymSymbol("extensive_quantity") +extensive_quantity = symbols.any_quantity """ -Extensive quantity. - -Symbol: - :code:`X` +Extensive quantity. See :symbols:`any_quantity`. """ -volumetric_density = SymSymbol("volumetric_density") -r""" -Intensive volumetric density. - -Symbol: - :code:`rho_X` - -Latex: - :math:`\rho_X` +volumetric_density = clone_as_symbol( + symbols.any_quantity, + display_symbol="rho_X", + display_latex="\\rho_X", +) """ - -volume = Symbol("volume", units.volume) +Intensive volumetric density, which has the dimension of :attr:`~extensive_quantity` +divided by :attr:`~volume`. See :symbols:`any_quantity`. """ -Volume. -Symbol: - :code:`V` +volume = symbols.volume +""" +:symbols:`volume`. """ law = Eq(extensive_quantity, volumetric_density * volume) -r""" -:code:`X = rho_X * V` +""" +:laws:symbol:: -Latex: - .. math:: - X = \rho_X V +:laws:latex:: """ diff --git a/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py b/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py index 2f6e31e49..774cfb2a3 100644 --- a/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py +++ b/symplyphysics/laws/thermodynamics/compressibility_factor_via_intermolecular_force_potential.py @@ -57,13 +57,13 @@ """ intermolecular_distance = clone_as_symbol( - symbols.distance, + symbols.euclidean_distance, display_symbol="r", display_latex="r", positive=True, ) """ -:symbols:`distance` between gas molecules. +:symbols:`euclidean_distance` between gas molecules. """ intermolecular_force_potential = clone_as_function( diff --git a/symplyphysics/laws/waves/average_power_of_sinusoidal_wave_on_stretched_string.py b/symplyphysics/laws/waves/average_power_of_sinusoidal_wave_on_stretched_string.py index 686e20501..259af4ddd 100644 --- a/symplyphysics/laws/waves/average_power_of_sinusoidal_wave_on_stretched_string.py +++ b/symplyphysics/laws/waves/average_power_of_sinusoidal_wave_on_stretched_string.py @@ -39,9 +39,13 @@ :symbols:`angular_frequency` of the wave. """ -wave_amplitude = clone_as_symbol(symbols.distance, display_symbol="u_max", display_latex="u_\\text{max}") +wave_amplitude = clone_as_symbol( + symbols.euclidean_distance, + display_symbol="u_max", + display_latex="u_\\text{max}", +) """ -Amplitude of the wave. See :symbols:`distance`. +Amplitude of the wave. See :symbols:`euclidean_distance`. """ law = Eq( diff --git a/symplyphysics/laws/waves/intensity_of_sound_wave_via_displacement_amplitude.py b/symplyphysics/laws/waves/intensity_of_sound_wave_via_displacement_amplitude.py index 79f521233..bed0b27a9 100644 --- a/symplyphysics/laws/waves/intensity_of_sound_wave_via_displacement_amplitude.py +++ b/symplyphysics/laws/waves/intensity_of_sound_wave_via_displacement_amplitude.py @@ -38,12 +38,12 @@ """ displacement_amplitude = clone_as_symbol( - symbols.distance, + symbols.euclidean_distance, display_symbol="s_max", display_latex="s_\\text{max}", ) """ -Displacement amplitude of the particles in the medium. See :symbols:`distance`. +Displacement amplitude of the particles in the medium. See :symbols:`euclidean_distance`. """ law = Eq( diff --git a/symplyphysics/laws/waves/phase_shift_between_two_points.py b/symplyphysics/laws/waves/phase_shift_between_two_points.py index b28f93491..3bd44d3fe 100644 --- a/symplyphysics/laws/waves/phase_shift_between_two_points.py +++ b/symplyphysics/laws/waves/phase_shift_between_two_points.py @@ -20,9 +20,9 @@ :symbols:`phase_shift` between the two points. """ -distance = symbols.distance +distance = symbols.euclidean_distance """ -:symbols:`distance` between the two points. +:symbols:`euclidean_distance` between the two points. """ wavelength = symbols.wavelength diff --git a/symplyphysics/laws/waves/pressure_amplitude_in_sound_wave.py b/symplyphysics/laws/waves/pressure_amplitude_in_sound_wave.py index 0ff7c9540..acbf6f427 100644 --- a/symplyphysics/laws/waves/pressure_amplitude_in_sound_wave.py +++ b/symplyphysics/laws/waves/pressure_amplitude_in_sound_wave.py @@ -41,12 +41,12 @@ """ displacement_amplitude = clone_as_symbol( - symbols.distance, + symbols.euclidean_distance, display_symbol="s_max", display_latex="s_\\text{max}", ) """ -Displacement amplitude of particles in the medium. See :symbols:`distance`. +Displacement amplitude of particles in the medium. See :symbols:`euclidean_distance`. """ law = Eq( diff --git a/symplyphysics/symbols/__init__.py b/symplyphysics/symbols/__init__.py index 83a7c9769..50e7b6e2c 100644 --- a/symplyphysics/symbols/__init__.py +++ b/symplyphysics/symbols/__init__.py @@ -34,6 +34,10 @@ "spectral_energy_density", "molar_mass", "probability", + "whole_number", + "any_quantity", + "fractional_change", + "exponential_decay_constant", # chemistry, "mass_fraction", "amount_of_substance", @@ -46,6 +50,7 @@ "force", "speed", "acceleration", + "euclidean_distance", "distance", "distance_to_origin", "distance_to_axis", @@ -96,6 +101,8 @@ "dynamic_viscosity", "diffusion_flux", "degrees_of_freedom", + "angular_momentum", + "arc_length", # electrodynamics "admittance", "electrical_conductance", @@ -124,6 +131,8 @@ "current_density", "relative_permeability", "emissivity", + "magnetic_moment", + "absolute_permeability", # optics "relative_refractive_index", "radiant_exitance", diff --git a/symplyphysics/symbols/basic.py b/symplyphysics/symbols/basic.py index d3f5cb762..0cab1ab64 100644 --- a/symplyphysics/symbols/basic.py +++ b/symplyphysics/symbols/basic.py @@ -7,9 +7,14 @@ from sympy.physics import units from sympy.physics.units.definitions.dimension_definitions import angle as angle_type -from symplyphysics.core.dimensions import dimensionless +from symplyphysics.core.dimensions import dimensionless, any_dimension from symplyphysics.core.symbols.symbols import SymbolNew +any_quantity = SymbolNew("X", any_dimension) +""" +A quantity that can have any dimension. +""" + time = SymbolNew("t", units.time) """ **Time** is a scalar physical quantity operationally defined as the reading of a clock, specifically @@ -64,6 +69,9 @@ radius_of_curvature = SymbolNew("r", units.length) """ **Radius of curvature** is the inverse of curvature and is equal to the distance to the center of curvature. + +.. + TODO are this and distance_to_axis interchangeable? """ density = SymbolNew("rho", units.mass / units.volume, display_latex="\\rho") @@ -112,3 +120,19 @@ """ **Probability** is a measure of an event's likelihood. """ + +fractional_change = SymbolNew("e", dimensionless) +""" +**Fractional change** is linear change divided by initial value of the quantity. +""" + +exponential_decay_constant = SymbolNew("lambda", 1 / units.time, display_latex="\\lambda") +""" +**Exponential decay constant**, also called **rate constant** or **disintegration constant**, is +the rate at which some quantity is decreasing in such a way that its rate of change is proportional +to its current value. + +**Links:** + +#. `Exponential decay `__. +""" diff --git a/symplyphysics/symbols/classical_mechanics.py b/symplyphysics/symbols/classical_mechanics.py index 5a717b8e3..d69df26c2 100644 --- a/symplyphysics/symbols/classical_mechanics.py +++ b/symplyphysics/symbols/classical_mechanics.py @@ -38,9 +38,38 @@ **Position** is defined as the spatial location of an object with respect to a coordinate system. """ -distance = SymbolNew("d", units.length) +euclidean_distance = SymbolNew("d", units.length) +r""" +**Euclidean distance** between two points is the length of the line segment between them. Mathematically, +it can be represented by the following formula: + +.. math:: + d = \sqrt{\left\Vert \mathbf{r}_2 - \mathbf{r}_1 \right\Vert}, + +where :math:`\mathbf{r}_1` is the position vector of the first point, :math:`\mathbf{r}_2` is the position +vector of the second point, and :math:`\left\Vert \cdot \right\Vert` is the Euclidean norm. + +**Notes:** + +#. This symbol can be used for representing **displacement**. In that case, :math:`\mathbf{r}_1` corresponds + to the initial position of the body and :math:`\mathbf{r}_2` to the final position of the body. """ -**Distance** is is a measure of the spatial separation between two points. + +distance = SymbolNew("s", units.length) +r""" +**distance**, or more precisely **total distance traveled**, is the length of the path traced by a moving body. +Mathematically, it can be represented by the following formula: + +.. math:: + s(t) = \int \limits_0^t |\mathbf{v}(\tau)| d\tau, + +where :math:`\mathbf{v}` is the velocity vector of the body as a function of time :math:`t`. It is assumed that +the total distance traveled is zero at zero time. + +**Notes:** + +#. It is sometimes used in the sense of *the length of space between two points*, in which case + :symbols:`euclidean_distance` must be used. """ distance_to_origin = SymbolNew("r", units.length) @@ -75,6 +104,11 @@ **Area** is the size of a region on a two-dimensional surface. """ +arc_length = SymbolNew("s", units.length) +""" +**Arc length** is the distance between two points along a section of a curve. +""" + angular_speed = SymbolNew("w", angle_type / units.time, display_latex="\\omega") """ **Angular speed** is the rate of change of angular distance with respect to time. @@ -322,3 +356,9 @@ of degrees of freedom indicates the smallest number of parameters whose values determine all parameters in the chosen parameterization. """ + +angular_momentum = SymbolNew("L", units.mass * units.length**2 / units.time) +""" +**Angular momentum**, sometimes called **rotational momentum**, is the rotational analog of linear +:symbols:`momentum`. +""" diff --git a/symplyphysics/symbols/electrodynamics.py b/symplyphysics/symbols/electrodynamics.py index 2f5d26bca..213535999 100644 --- a/symplyphysics/symbols/electrodynamics.py +++ b/symplyphysics/symbols/electrodynamics.py @@ -56,6 +56,12 @@ Also see :attr:`~symplyphysics.quantities.vacuum_permittivity`. """ +absolute_permeability = SymbolNew("mu", units.inductance / units.length, display_latex="\\mu") +""" +**Absolute permeability**, also called **permeability**, is the measure of magnetization produced in a material in response to an +applied magnetic field. +""" + relative_permeability = SymbolNew("mu_r", dimensionless, display_latex="\\mu_r") """ **Relative permeability** is the permeability of a medium relative to that of free space. @@ -160,3 +166,15 @@ """ The **emissivity** of the surface of a material is its effectiveness in emitting energy as thermal radiation. """ + +magnetic_moment = SymbolNew("m", units.current * units.area) +""" +**Magnetic (dipole) moment** is a vector physical quantity representing the strength and +the orientation of a system that exerts a magnetic field. The magnetic dipole moment of +an object determines the magnitude of torque the object experiences in a given magnetic +field. + +**Links:** + +#. `Magnetic moment `__. +""" diff --git a/test/docs/printer_code_test.py b/test/docs/printer_code_test.py index 94e199c16..5058b0942 100644 --- a/test/docs/printer_code_test.py +++ b/test/docs/printer_code_test.py @@ -1,7 +1,57 @@ +from collections import namedtuple +from pytest import fixture from sympy import Integral, evaluate, exp, log, pi, sin, sqrt -from symplyphysics import Quantity, SymbolNew, clone_as_symbol, quantities, symbols, clone_as_function, units +from symplyphysics import Quantity, SymbolNew, clone_as_symbol, clone_as_function, units from symplyphysics.docs.printer_code import code_str +Args = namedtuple( + "Args", + [ + "mass", + "temperature", + "boltzmann_constant", + "energy", + "time", + "force", + "speed", + "speed_of_light", + "charge", + "distance", + "vacuum_permittivity", + "intensity", + ], +) + + +@fixture(name="test_args") +def test_args_fixture() -> Args: + mass = SymbolNew("m") + temperature = SymbolNew("T") + boltzmann_constant = Quantity(display_symbol="k_B") + energy = SymbolNew("E") + time = SymbolNew("t") + force = SymbolNew("F") + speed = SymbolNew("v") + speed_of_light = Quantity(display_symbol="c") + charge = SymbolNew("q") + distance = SymbolNew("d") + vacuum_permittivity = Quantity(display_symbol="epsilon_0") + intensity = SymbolNew("I") + return Args( + mass=mass, + temperature=temperature, + boltzmann_constant=boltzmann_constant, + energy=energy, + time=time, + force=force, + speed=speed, + speed_of_light=speed_of_light, + charge=charge, + distance=distance, + vacuum_permittivity=vacuum_permittivity, + intensity=intensity, + ) + def test_add() -> None: a = SymbolNew("a") @@ -94,73 +144,63 @@ def test_mul_with_double_braces() -> None: assert code_str(expr) == "(a + b) * (c + d)" -def test_mul_with_sqrt_and_quantity() -> None: - mass = symbols.mass - temperature = symbols.temperature +def test_mul_with_sqrt_and_quantity(test_args: Args) -> None: with evaluate(False): - expr = sqrt(2 * pi / (mass * quantities.boltzmann_constant * temperature)) + expr = sqrt(2 * pi / (test_args.mass * test_args.boltzmann_constant * test_args.temperature)) assert code_str(expr) == "sqrt(2 * pi / (m * k_B * T))" -def test_mul_minus_one() -> None: - energy_of_state = symbols.energy - temperature = symbols.temperature +def test_mul_minus_one(test_args: Args) -> None: with evaluate(False): - expr = exp(-1 * energy_of_state / (quantities.boltzmann_constant * temperature)) + expr = exp(-1 * test_args.energy / (test_args.boltzmann_constant * test_args.temperature)) assert code_str(expr) == "exp(-E / (k_B * T))" -def test_mul_integral() -> None: - time = symbols.time - time_before = SymbolNew("t_0", display_latex="t_0") - time_after = SymbolNew("t_1", display_latex="t_1") - force = clone_as_function(symbols.force) +def test_mul_integral(test_args: Args) -> None: + time = test_args.time + time_before = clone_as_symbol(time, subscript="0") + time_after = clone_as_symbol(time, subscript="1") + force = clone_as_function(test_args.force) with evaluate(False): expr = Integral(force(time), (time, time_before, time_after)) assert code_str(expr) == "Integral(F(t), (t, t_0, t_1))" -def test_mul_sqrt() -> None: - speed = symbols.speed +def test_mul_sqrt(test_args: Args) -> None: with evaluate(False): - expr = 1 / sqrt(1 - speed**2 / quantities.speed_of_light**2) + expr = 1 / sqrt(1 - test_args.speed**2 / test_args.speed_of_light**2) assert code_str(expr) == "1 / sqrt(1 - v^2 / c^2)" -def test_mul_fraction_and_sin() -> None: - mass = symbols.mass - driving_force_amplitude = symbols.force +def test_mul_fraction_and_sin(test_args: Args) -> None: natural_angular_frequency = SymbolNew("w_0", display_latex="\\omega_0") - time = symbols.time + time = test_args.time with evaluate(False): - expr = (driving_force_amplitude / - (2 * mass * natural_angular_frequency)) * time * sin(natural_angular_frequency * time) + expr = (test_args.force / + (2 * test_args.mass * natural_angular_frequency)) * time * sin(natural_angular_frequency * time) assert code_str(expr) == "F / (2 * m * w_0) * t * sin(w_0 * t)" -def test_fraction_mul_inner_fraction() -> None: - first_charge = clone_as_symbol(symbols.charge, display_symbol="q_1", display_latex="q_1") - second_charge = clone_as_symbol(symbols.charge, display_symbol="q_2", display_latex="q_2") - distance = symbols.distance +def test_fraction_mul_inner_fraction(test_args: Args) -> None: + first_charge = clone_as_symbol(test_args.charge, subscript="1") + second_charge = clone_as_symbol(test_args.charge, subscript="2") with evaluate(False): expr = first_charge * second_charge / (4 * pi * - quantities.vacuum_permittivity) / distance**2 + test_args.vacuum_permittivity) / test_args.distance**2 assert code_str(expr) == "q_1 * q_2 / (4 * pi * epsilon_0) / d^2" -def test_fraction_mul_inner_fraction_with_braces() -> None: - first_charge = clone_as_symbol(symbols.charge, display_symbol="q_1", display_latex="q_1") - second_charge = clone_as_symbol(symbols.charge, display_symbol="q_2", display_latex="q_2") - distance = symbols.distance +def test_fraction_mul_inner_fraction_with_braces(test_args: Args) -> None: + first_charge = clone_as_symbol(test_args.charge, subscript="1") + second_charge = clone_as_symbol(test_args.charge, subscript="2") with evaluate(False): expr = 1 / (4 * pi * - quantities.vacuum_permittivity) * (first_charge * second_charge / distance**2) + test_args.vacuum_permittivity) * (first_charge * second_charge / test_args.distance**2) assert code_str(expr) == "q_1 * q_2 / d^2 / (4 * pi * epsilon_0)" -def test_log10() -> None: - intensity = symbols.intensity +def test_log10(test_args: Args) -> None: reference_intensity = Quantity(1e-12 * units.watt / units.meter**2, display_symbol="I_0") with evaluate(False): - expr = log(intensity / reference_intensity, 10) + expr = log(test_args.intensity / reference_intensity, 10) assert code_str(expr) == "log(I / I_0, 10)" diff --git a/test/docs/printer_latex_test.py b/test/docs/printer_latex_test.py index bd288e0cf..85fc46d36 100644 --- a/test/docs/printer_latex_test.py +++ b/test/docs/printer_latex_test.py @@ -1,7 +1,60 @@ +from collections import namedtuple +from pytest import fixture from sympy import Integral, evaluate, exp, log, pi, sin, sqrt -from symplyphysics import Quantity, SymbolNew, quantities, symbols, clone_as_function, clone_as_symbol, units +from symplyphysics import Quantity, SymbolNew, clone_as_function, clone_as_symbol, units from symplyphysics.docs.printer_latex import latex_str +Args = namedtuple( + "Args", + [ + "mass", + "temperature", + "boltzmann_constant", + "energy", + "time", + "force", + "speed", + "speed_of_light", + "charge", + "distance", + "vacuum_permittivity", + "electric_dipole_moment", + "intensity", + ], +) + + +@fixture(name="test_args") +def test_args_fixture() -> Args: + mass = SymbolNew("m") + temperature = SymbolNew("T") + boltzmann_constant = Quantity(display_latex="k_\\text{B}") + energy = SymbolNew("E") + time = SymbolNew("t") + force = SymbolNew("F") + speed = SymbolNew("v") + speed_of_light = Quantity(display_symbol="c") + charge = SymbolNew("q") + distance = SymbolNew("d") + vacuum_permittivity = Quantity(display_latex="\\varepsilon_0") + electric_dipole_moment = SymbolNew("p") + intensity = SymbolNew("I") + return Args( + mass=mass, + temperature=temperature, + boltzmann_constant=boltzmann_constant, + energy=energy, + time=time, + force=force, + speed=speed, + speed_of_light=speed_of_light, + charge=charge, + distance=distance, + vacuum_permittivity=vacuum_permittivity, + electric_dipole_moment=electric_dipole_moment, + intensity=intensity, + ) + def test_add() -> None: a = SymbolNew("a") @@ -94,72 +147,61 @@ def test_mul_with_double_braces() -> None: assert latex_str(expr) == "\\left(a + b\\right) \\left(c + d\\right)" -def test_mul_with_sqrt_and_quantity() -> None: - mass = symbols.mass - temperature = symbols.temperature +def test_mul_with_sqrt_and_quantity(test_args: Args) -> None: with evaluate(False): - expr = sqrt(2 * pi / (mass * quantities.boltzmann_constant * temperature)) + expr = sqrt(2 * pi / (test_args.mass * test_args.boltzmann_constant * test_args.temperature)) assert latex_str(expr) == "\\sqrt{\\frac{2 \\pi}{m k_\\text{B} T}}" -def test_mul_minus_one() -> None: - energy_of_state = symbols.energy - temperature = symbols.temperature +def test_mul_minus_one(test_args: Args) -> None: with evaluate(False): - expr = exp(-1 * energy_of_state / (quantities.boltzmann_constant * temperature)) + expr = exp(-1 * test_args.energy / (test_args.boltzmann_constant * test_args.temperature)) assert latex_str(expr) == "\\exp{\\left(- \\frac{E}{k_\\text{B} T} \\right)}" -def test_mul_integral() -> None: - time = symbols.time - time_before = SymbolNew("t_0", display_latex="t_0") - time_after = SymbolNew("t_1", display_latex="t_1") - force = clone_as_function(symbols.force, display_symbol="F(t)") +def test_mul_integral(test_args: Args) -> None: + time = test_args.time + time_before = clone_as_symbol(time, subscript="0") + time_after = clone_as_symbol(time, subscript="1") + force = clone_as_function(test_args.force) with evaluate(False): expr = Integral(force(time), (time, time_before, time_after)) assert latex_str(expr) == "\\int\\limits_{t_{0}}^{t_{1}} F{\\left(t \\right)}\\, dt" -def test_mul_sqrt() -> None: - speed = symbols.speed +def test_mul_sqrt(test_args: Args) -> None: with evaluate(False): - expr = 1 / sqrt(1 - speed**2 / quantities.speed_of_light**2) + expr = 1 / sqrt(1 - test_args.speed**2 / test_args.speed_of_light**2) assert latex_str(expr) == "\\frac{1}{\\sqrt{1 - \\frac{v^{2}}{c^{2}}}}" -def test_mul_fraction_and_sin() -> None: - mass = symbols.mass - driving_force_amplitude = symbols.force +def test_mul_fraction_and_sin(test_args: Args) -> None: natural_angular_frequency = SymbolNew("w_0", display_latex="\\omega_0") - time = symbols.time + time = test_args.time with evaluate(False): - expr = (driving_force_amplitude / - (2 * mass * natural_angular_frequency)) * time * sin(natural_angular_frequency * time) + expr = (test_args.force / + (2 * test_args.mass * natural_angular_frequency)) * time * sin(natural_angular_frequency * time) assert latex_str(expr) == "\\frac{F}{2 m \\omega_{0}} t \\sin{\\left(\\omega_{0} t \\right)}" -def test_fraction_mul_inner_fraction() -> None: - first_charge = clone_as_symbol(symbols.charge, display_symbol="q_1", display_latex="q_1") - second_charge = clone_as_symbol(symbols.charge, display_symbol="q_2", display_latex="q_2") - distance = symbols.distance +def test_fraction_mul_inner_fraction(test_args: Args) -> None: + first_charge = clone_as_symbol(test_args.charge, subscript="1") + second_charge = clone_as_symbol(test_args.charge, subscript="2") with evaluate(False): expr = first_charge * second_charge / (4 * pi * - quantities.vacuum_permittivity) / distance**2 + test_args.vacuum_permittivity) / test_args.distance**2 assert latex_str(expr) == "\\frac{q_{1} q_{2}}{4 \\pi \\varepsilon_0} \\frac{1}{d^{2}}" -def test_fraction_mul_fraction() -> None: - electric_dipole_moment = symbols.electric_dipole_moment - distance = symbols.distance +def test_fraction_mul_fraction(test_args: Args) -> None: with evaluate(False): - expr = 1 / (2 * pi * quantities.vacuum_permittivity) * (electric_dipole_moment / - distance**3) + expr = 1 / (2 * pi * test_args.vacuum_permittivity) * (test_args.electric_dipole_moment / + test_args.distance**3) assert latex_str(expr) == "\\frac{1}{2 \\pi \\varepsilon_0} \\frac{p}{d^{3}}" -def test_log10() -> None: - intensity = symbols.intensity +def test_log10(test_args: Args) -> None: reference_intensity = Quantity(1e-12 * units.watt / units.meter**2, display_symbol="I_0") with evaluate(False): - expr = log(intensity / reference_intensity, 10) + expr = log(test_args.intensity / reference_intensity, 10) assert latex_str(expr) == "\\log_{10} \\left( \\frac{I}{I_0} \\right)" diff --git a/test/electricity/electromotive_force_induced_in_sinusoidally_rotating_coil_test.py b/test/electricity/electromotive_force_induced_in_sinusoidally_rotating_coil_test.py deleted file mode 100644 index 331328583..000000000 --- a/test/electricity/electromotive_force_induced_in_sinusoidally_rotating_coil_test.py +++ /dev/null @@ -1,81 +0,0 @@ -from collections import namedtuple -from pytest import fixture, raises -from sympy import pi -from symplyphysics import (assert_equal, units, Quantity, errors) -from symplyphysics.laws.electricity import electromotive_force_induced_in_sinusoidally_rotating_coil as electromotive_force_law - -# Description -## In a homogeneous magnetostatic field with an induction equal to 0.1 tesla, a frame containing 1000 turns -## rotates uniformly with a frequency of 2 * pi * 10 radian per second. The area of the frame is 150 [centimeter^2], -## the time is 8.3e-3 second. Then the voltage value will be -46.95 volt. -## https://remote.misis.ru/courses/168/pages/13-dot-7-primiery-rieshieniia-zadach - -Args = namedtuple("Args", - ["number_turns", "induction", "contour_area", "rotation_frequency", "time"]) - - -@fixture(name="test_args") -def test_args_fixture() -> Args: - number_turns = 1000 - induction = Quantity(0.1 * units.tesla) - contour_area = Quantity(150 * units.centimeter**2) - rotation_frequency = Quantity(2 * pi * 10 * units.radian / units.second) - time = Quantity(8.3e-3 * units.second) - return Args(number_turns=number_turns, - induction=induction, - contour_area=contour_area, - rotation_frequency=rotation_frequency, - time=time) - - -def test_basic_voltage(test_args: Args) -> None: - result = electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, - test_args.contour_area, test_args.rotation_frequency, test_args.time) - assert_equal(result, -46.95 * units.volt) - - -def test_bad_number_turns(test_args: Args) -> None: - number_turns = Quantity(1 * units.coulomb) - with raises(errors.UnitsError): - electromotive_force_law.calculate_voltage(number_turns, test_args.induction, - test_args.contour_area, test_args.rotation_frequency, test_args.time) - - -def test_bad_induction(test_args: Args) -> None: - induction = Quantity(1 * units.coulomb) - with raises(errors.UnitsError): - electromotive_force_law.calculate_voltage(test_args.number_turns, induction, - test_args.contour_area, test_args.rotation_frequency, test_args.time) - with raises(TypeError): - electromotive_force_law.calculate_voltage(test_args.number_turns, 100, - test_args.contour_area, test_args.rotation_frequency, test_args.time) - - -def test_bad_contour_area(test_args: Args) -> None: - contour_area = Quantity(1 * units.coulomb) - with raises(errors.UnitsError): - electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, - contour_area, test_args.rotation_frequency, test_args.time) - with raises(TypeError): - electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, 100, - test_args.rotation_frequency, test_args.time) - - -def test_bad_rotation_frequency(test_args: Args) -> None: - rotation_frequency = Quantity(1 * units.coulomb) - with raises(errors.UnitsError): - electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, - test_args.contour_area, rotation_frequency, test_args.time) - with raises(TypeError): - electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, - test_args.contour_area, 100, test_args.time) - - -def test_bad_time(test_args: Args) -> None: - time = Quantity(1 * units.coulomb) - with raises(errors.UnitsError): - electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, - test_args.contour_area, test_args.rotation_frequency, time) - with raises(TypeError): - electromotive_force_law.calculate_voltage(test_args.number_turns, test_args.induction, - test_args.contour_area, test_args.rotation_frequency, 100) diff --git a/test/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume_test.py b/test/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume_test.py index f95c3ea27..703134b1e 100644 --- a/test/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume_test.py +++ b/test/electricity/inductance_of_solenoid_depends_on_permeability_number_of_turns_volume_test.py @@ -6,6 +6,7 @@ units, Quantity, prefixes, + quantities, ) from symplyphysics.laws.electricity import inductance_of_solenoid_depends_on_permeability_number_of_turns_volume as inductance_law @@ -14,46 +15,49 @@ ## and volume of solenoid is 0.1 [meter^3]. Then the inductance of the solenoid is 125.6 microhenry. ## https://physics.icalculator.com/self-inductance-calculator.html -Args = namedtuple("Args", ["relative_permeability", "number_of_turns", "volume"]) +Args = namedtuple("Args", ["absolute_permeability", "number_of_turns", "volume"]) @fixture(name="test_args") def test_args_fixture() -> Args: - relative_permeability = 10 + absolute_permeability = 10 + absolute_permeability = Quantity(quantities.vacuum_permeability * absolute_permeability) number_of_turns = Quantity(10 * (1 / units.meter)) volume = Quantity(0.1 * units.meter**3) - return Args(relative_permeability=relative_permeability, + return Args(absolute_permeability=absolute_permeability, number_of_turns=number_of_turns, volume=volume) def test_basic_inductance(test_args: Args) -> None: - result = inductance_law.calculate_inductance(test_args.relative_permeability, + result = inductance_law.calculate_inductance(test_args.absolute_permeability, test_args.number_of_turns, test_args.volume) assert_equal(result, 125.6 * prefixes.micro * units.henry) -def test_bad_relative_permeability(test_args: Args) -> None: - relative_permeability = Quantity(1 * units.meter) +def test_bad_absolute_permeability(test_args: Args) -> None: + absolute_permeability = Quantity(1 * units.meter) with raises(errors.UnitsError): - inductance_law.calculate_inductance(relative_permeability, test_args.number_of_turns, + inductance_law.calculate_inductance(absolute_permeability, test_args.number_of_turns, test_args.volume) + with raises(TypeError): + inductance_law.calculate_inductance(100, test_args.number_of_turns, test_args.volume) def test_bad_number_of_turns(test_args: Args) -> None: number_of_turns = Quantity(1 * units.meter) with raises(errors.UnitsError): - inductance_law.calculate_inductance(test_args.relative_permeability, number_of_turns, + inductance_law.calculate_inductance(test_args.absolute_permeability, number_of_turns, test_args.volume) with raises(TypeError): - inductance_law.calculate_inductance(test_args.relative_permeability, 100, test_args.volume) + inductance_law.calculate_inductance(test_args.absolute_permeability, 100, test_args.volume) def test_bad_volume(test_args: Args) -> None: volume = Quantity(1 * units.meter) with raises(errors.UnitsError): - inductance_law.calculate_inductance(test_args.relative_permeability, + inductance_law.calculate_inductance(test_args.absolute_permeability, test_args.number_of_turns, volume) with raises(TypeError): - inductance_law.calculate_inductance(test_args.relative_permeability, + inductance_law.calculate_inductance(test_args.absolute_permeability, test_args.number_of_turns, 100)