module PhysicsCalculator

Constants

ACCELERATION_GRAVITY

acceleration due to gravity on Earth’s surface (m/s^2)

ACCELERATION_GRAVITY_
BOLTZMANN

Boltzmann constant

C

Aliases for convenience

CHARGE_ELEMENTARY

elementary charge (C)

ENERGY_BINDING

energy of ground state of electron in hydrogen atom (Joules)

FINE_STRUCTURE

fine structure constant (dimensionless)

G
GRAVITATIONAL

gravitational constant ((N*m^2)/kg^2))

H
I
MASS_EARTH

mass of the Earth (kg)

MASS_ELECTRON

electron rest mass (kg)

MASS_MOON

mass of the Moon (kg)

MASS_NEUTRON

neutron rest mass (kg)

MASS_PROTON

proton rest mass (kg)

MASS_SUN

mass of the Sun (kg)

PERMEABILITY

vacuum permeability ((V*s)/(A*m))

PERMITTIVITY

vacuum permittivity (F/m)

PLANCK

planck’s constant (J*s)

PLANCK_REDUCED

reduced planck’s constant

RYDBERG

Rydberg constant (1/m)

SPEED_LIGHT

speed of light in a vacuum (m/s)

VERSION
X_
Y_
Z_

Public Instance Methods

angular_momentum_(axis_, position_, mass, velocity_) click to toggle source

angular momentum from momentum mass*velocity_ around axis_ (vector in J * s)

# File lib/physics_calculator.rb, line 159
def angular_momentum_(axis_, position_, mass, velocity_)
  (position_ - axis_).cross_product_(momentum_(mass,velocity_))
end
angular_momentum_rigid_(moment_inertia, angular_velocity_) click to toggle source

angular momentum of rotating rigid body with moment_inertia rotating at angular_velocity_ (vector in J * s)

# File lib/physics_calculator.rb, line 164
def angular_momentum_rigid_(moment_inertia, angular_velocity_)
  moment_inertia * angular_velocity_
end
capacitance_parallel(capacitance1, capacitance2) click to toggle source

equivalent capacitance of capacitance1 and capacitance2 in parallel (scalar in Farads)

# File lib/physics_calculator.rb, line 304
def capacitance_parallel(capacitance1, capacitance2)
  capacitance1+capacitance2
end
capacitance_series(capacitance1, capacitance2) click to toggle source

equivalent capacitance of capacitance1 and capacitance2 in series (scalar in Farads)

# File lib/physics_calculator.rb, line 299
def capacitance_series(capacitance1, capacitance2)
  Float(capacitance1*capacitance2)/(capacitance1+capacitance2)
end
eigenstate_infinite_well(n, width, position) click to toggle source

eigenstate of particle in one dimensional infinite square well potential from 0 to width with mass and position (scalar dimensionless)

# File lib/physics_calculator.rb, line 235
def eigenstate_infinite_well(n, width, position)
  sqrt(2.0 / width) * sin((n * PI * position) / width)
end
eigenstate_qho(n, mass, frequency, position) click to toggle source

one dimensional quantum harmonic oscillator nth eigenstate for particle with mass, frequency, and position (scalar dimensionless)

# File lib/physics_calculator.rb, line 224
def eigenstate_qho(n, mass, frequency, position)
  xi = Math.sqrt((mass*frequency) / H)*position
  (((mass*frequency)/(PI*H))**0.25)*(((2**n)*Math.gamma(n+1))**0.5)*hermite_polynomial(n, xi)*Math.exp((-xi**2) / 2)
end
electric_field_point_charge_(charge, charge_position_, position_) click to toggle source

electric field at position_ due to point charge at charge_position_ (vector in N / C)

# File lib/physics_calculator.rb, line 269
def electric_field_point_charge_(charge, charge_position_, position_)
  (((1/(4*PI*PERMITTIVITY))*charge)/(position_.distance(charge_position_)**2))*position_.unit_(charge_position_)
end
energy_bohr(n) click to toggle source

energy of the nth (n = 1, 2, 3 …) state of the electron in a hydrogen atom according to the Bohr model (scalar in Joules)

# File lib/physics_calculator.rb, line 245
def energy_bohr(n)
  ENERGY_BINDING / n**2
end
energy_infinite_well(n, width, mass) click to toggle source

energy of particle in one dimensional infinite square well potential from 0 to width with mass (scalar in Joules)

# File lib/physics_calculator.rb, line 240
def energy_infinite_well(n, width, mass)
  (n**2 * PI**2 * H**2) / (2 * mass * width**2)
end
energy_kinetic(mass, velocity_) click to toggle source

kinetic energy of mass at velocity_ (scalar in Joules)

# File lib/physics_calculator.rb, line 149
def energy_kinetic(mass, velocity_)
  0.5*mass*(velocity_.r)**2
end
energy_photon(frequency) click to toggle source

energy of a photon with frequency (scalar in Joules)

# File lib/physics_calculator.rb, line 348
def energy_photon(frequency)
  PLANCK*frequency
end
energy_qho(n, frequency) click to toggle source

one dimensional quantum harmonic oscillator nth eigenstate energy for particle with mass, and frequency (scalar in Joules)

# File lib/physics_calculator.rb, line 230
def energy_qho(n, frequency)
  (n + 0.5) * H * frequency
end
energy_rest(mass) click to toggle source

rest energy of mass (scalar in Joules)

# File lib/physics_calculator.rb, line 343
def energy_rest(mass)
  mass*C**2
end
force_coulombs_law_(charge1, position1_, charge2, position2_) click to toggle source

force felt by charge1 at position1_ due to charge2 at position2_

# File lib/physics_calculator.rb, line 264
def force_coulombs_law_(charge1, position1_, charge2, position2_)
  (((1/(4*PI*PERMITTIVITY))*charge1*charge2)/(position1_.distance(position2_)**2))*position1_.unit_(position2_)
end
force_gravity_(mass1, position1_, mass2, position2_) click to toggle source

gravitational force on mass1 at position1_ due to mass2 at position2_ (vector in Newtons)

# File lib/physics_calculator.rb, line 114
def force_gravity_(mass1, position1_, mass2, position2_)
  ((-G * mass1 * mass2) / (position1_.distance(position2_)**2)) * position1_.unit_(position2_)
end
force_lorentz_(charge, velocity_, electric_field_, magnetic_field_) click to toggle source

Lorentz force on particle with charge moving at velocity_ through electric_field_ and magnetic_field_

# File lib/physics_calculator.rb, line 259
def force_lorentz_(charge, velocity_, electric_field_, magnetic_field_)
  charge * (electric_field_ + velocity_.cross_product_(magnetic_field_))
end
force_weight_(mass) click to toggle source

weight of mass at surface of Earth with -Z_ pointing at the center of Earth (vector in Newtons)

# File lib/physics_calculator.rb, line 119
def force_weight_(mass)
  ACCELERATION_GRAVITY_ * mass
end
hermite_polynomial(n, x) click to toggle source

Hermite polynomial of degree n evaluated at x (helper for QHO eigenstates)

# File lib/physics_calculator.rb, line 213
def hermite_polynomial(n, x)
  if n == 0
    1
  elsif n == 1
    2*x
  else
    (2*x*hermite_polynomial(n-1, x) - 2*(n-1)*hermite_polynomial(n-2, x))
  end
end
inductance_parallel(inductance1, inductance2) click to toggle source

equivalent inductance of inductance1 and inductance2 in parallel (scalar in henry)

# File lib/physics_calculator.rb, line 294
def inductance_parallel(inductance1, inductance2)
  Float(inductance1*inductance2)/(inductance1+inductance2)
end
inductance_series(inductance1, inductance2) click to toggle source

equivalent inductance of inductance1 and inductance2 in series (scalar in henry)

# File lib/physics_calculator.rb, line 289
def inductance_series(inductance1, inductance2)
  inductance1+inductance2
end
length_contraction(length, speed) click to toggle source

length contraction for an object with length moving at speed (scalar in meters)

# File lib/physics_calculator.rb, line 328
def length_contraction(length, speed)
  length / lorentz_factor(speed)
end
lorentz_factor(speed) click to toggle source

lorentz factor for object moving at velocity (scalar dimensionless)

# File lib/physics_calculator.rb, line 318
def lorentz_factor(speed)
  (1.0 / (Math.sqrt(1.0-(speed/C)**2)))
end
magnetic_field_point_charge_(charge, charge_position_, charge_velocity_, position_) click to toggle source

magnetic field at position_ due to point charge at charge_position_ moving at charge_velocity_ (vector in Teslas)

# File lib/physics_calculator.rb, line 274
def magnetic_field_point_charge_(charge, charge_position_, charge_velocity_, position_)
  (PERMEABILITY*charge)/(4*PI*position_.distance(charge_position_)**2)*charge_velocity_.cross_product_(position_.unit_(charge_position_))
end
mass_reduced(mass1, mass2) click to toggle source

reduced mass of mass1 and mass2 (scalar in kilograms)

# File lib/physics_calculator.rb, line 169
def mass_reduced(mass1, mass2)
  (Float(mass1*mass2))/(mass1 + mass2)
end
mass_relativistic(mass, speed) click to toggle source

relativistic mass of an object moving at speed (scalar in kilograms)

# File lib/physics_calculator.rb, line 333
def mass_relativistic(mass, speed)
  lorentz_factor(speed)*mass
end
moment_inertia_2_point_mass(mass1, mass2, distance) click to toggle source

moment of inertia of mass1 and mass2 at distance away from axis of rotation (scalar in kg * m^2)

# File lib/physics_calculator.rb, line 184
def moment_inertia_2_point_mass(mass1, mass2, distance)
  mass_reduced(mass1, mass2)*distance**2
end
moment_inertia_ball(mass, radius) click to toggle source

moment of inertia of solid ball with radius and mass rotating about center of mass (scalar in kg * m^2)

# File lib/physics_calculator.rb, line 199
def moment_inertia_ball(mass, radius)
  (2*mass*radius**2) / 5.0
end
moment_inertia_parallel_axis(moment_inertia_cm, mass, axis_distance) click to toggle source

moment of inertia using parallel axis theorem using mass with moment_inertia_cm with axis_distance between the center of mass and axis of rotation (scalar in kg * m^2)

# File lib/physics_calculator.rb, line 174
def moment_inertia_parallel_axis(moment_inertia_cm, mass, axis_distance)
  moment_inertia_cm + mass*axis_distance**2
end
moment_inertia_point_mass(mass, distance) click to toggle source

moment of inertia of mass at distance away from axis of rotation (scalar in kg * m^2)

# File lib/physics_calculator.rb, line 179
def moment_inertia_point_mass(mass, distance)
  mass * distance**2
end
moment_inertia_rod(mass, length) click to toggle source

moment of inertia of rod with length and mass rotating about center of mass (scalar in kg * m^2)

# File lib/physics_calculator.rb, line 189
def moment_inertia_rod(mass, length)
  (mass*length**2) / 12.0
end
moment_inertia_sphere(mass, radius) click to toggle source

moment of inertia of hollow sphere with radius and mass rotating about center of mass (scalar in kg * m^2)

# File lib/physics_calculator.rb, line 194
def moment_inertia_sphere(mass, radius)
  (2*mass*radius**2) / 3.0
end
momentum_(mass, velocity_) click to toggle source

linear momentum of mass at velocity_ (vector in kg * m^2)

# File lib/physics_calculator.rb, line 144
def momentum_(mass, velocity_)
  mass * velocity_
end
momentum_photon(frequency) click to toggle source

momentum of a photon with frequency (scalar in kg * m / s)

# File lib/physics_calculator.rb, line 353
def momentum_photon(frequency)
  energy_photon(frequency)/C
end
momentum_relativistic(mass, speed) click to toggle source

relativistic momentum of an object with mass moving at speed (scalar in kg * m / s)

# File lib/physics_calculator.rb, line 338
def momentum_relativistic(mass, speed)
  lorentz_factor(speed) * mass * speed
end
position_constant_acceleration_(position0_, velocity0_, acceleration_, time) click to toggle source

position of object under constant acceleration_ at time given initial conditions position0_ and velocity0_ (vector in meters)

# File lib/physics_calculator.rb, line 124
def position_constant_acceleration_(position0_, velocity0_, acceleration_, time)
  0.5*acceleration_*time**2 + velocity0_ * time + position0_
end
position_gravity_acceleration_(position0_, velocity0_, time) click to toggle source

position of object under acceleration due to gravity at time given initial conditions position0_ and velocity0_ (vector in meters)

# File lib/physics_calculator.rb, line 134
def position_gravity_acceleration_(position0_, velocity0_, time)
  position_constant_acceleration_(position0_, velocity0_, ACCELERATION_GRAVITY_, time)
end
resistance_parallel(resistance1, resistance2) click to toggle source

equivalent resistance of resistance1 and resistance2 in parallel (scalar in ohms)

# File lib/physics_calculator.rb, line 284
def resistance_parallel(resistance1, resistance2)
  Float(resistance1*resistance2)/(resistance1+resistance2)
end
resistance_series(resistance1, resistance2) click to toggle source

equivalent resistance of resistance1 and resistance2 in series (scalar in ohms)

# File lib/physics_calculator.rb, line 279
def resistance_series(resistance1, resistance2)
  resistance1+resistance2
end
time_dilation(time_interval, speed) click to toggle source

time dilation for an object moving at velocity over time_interval (scalar in seconds)

# File lib/physics_calculator.rb, line 323
def time_dilation(time_interval, speed)
  lorentz_factor(speed)*time_interval
end
torque_(axis_, position_, force_) click to toggle source

torque from applying f_ at position_ around axis_ (vector in N * m)

# File lib/physics_calculator.rb, line 154
def torque_(axis_, position_, force_)
  (position_ - axis_).cross_product_(force_)
end
velocity_constant_acceleration_(velocity0_, acceleration_, time) click to toggle source

velocity of object under constant acceleration_ at time given initial condition velocity0_ (vector in m / s)

# File lib/physics_calculator.rb, line 129
def velocity_constant_acceleration_(velocity0_, acceleration_, time)
  velocity0_ + acceleration_ * time
end
velocity_gravity_acceleration_(velocity0_, time) click to toggle source

velocity of object under acceleration due to gravity at time given initial condition velocity0_ (vector in m / s)

# File lib/physics_calculator.rb, line 139
def velocity_gravity_acceleration_(velocity0_, time)
  velocity_constant_acceleration_(velocity0_, ACCELERATION_GRAVITY_, time)
end
voltage_ohm_law(current, resistance) click to toggle source

voltage due to current across resistance (scalar in Volts)

# File lib/physics_calculator.rb, line 309
def voltage_ohm_law(current, resistance)
  current*resistance
end
wavelength_de_broglie(momentum) click to toggle source

de Broglie wavelength for a particle with momentum (scalar in meters)

# File lib/physics_calculator.rb, line 208
def wavelength_de_broglie(momentum)
  PLANCK / momentum
end
wavelength_rydberg(n_initial, n_final) click to toggle source

wavelength of light emitted in transition of electron from n_initial state to n_final state according to the Rydberg formula (scalar in meters)

# File lib/physics_calculator.rb, line 250
def wavelength_rydberg(n_initial, n_final)
  1.0 / (RYDBERG*(1.0 / (n_final**2) - 1.0 / (n_initial**2))).abs
end