Skip to content

Commit

Permalink
electronics: Add ind reactance
Browse files Browse the repository at this point in the history
  • Loading branch information
XuShaohua committed Aug 14, 2023
1 parent b42d55a commit d73d378
Show file tree
Hide file tree
Showing 2 changed files with 51 additions and 0 deletions.
50 changes: 50 additions & 0 deletions electronics/src/ind_reactance.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
// Copyright (c) 2023 Xu Shaohua <shaohua@biofan.org>. All rights reserved.
// Use of this source is governed by General Public License that can be found
// in the LICENSE file.

//! [Inductive reactance](https://en.wikipedia.org/wiki/Electrical_reactance#Inductive_reactance)

use std::f64::consts::PI;

/// inductance with units in Henries
/// frequency with units in Hertz
/// reactance with units in Ohms
#[must_use]
pub fn get_inductance(frequency: f64, reactance: f64) -> f64 {
debug_assert!(frequency > 0.0);
debug_assert!(reactance > 0.0);
reactance / (2.0 * PI * frequency)
}

#[must_use]
pub fn get_frequency(inductance: f64, reactance: f64) -> f64 {
debug_assert!(inductance > 0.0);
debug_assert!(reactance > 0.0);
reactance / (2.0 * PI * inductance)
}

#[must_use]
pub fn get_reactance(inductance: f64, frequency: f64) -> f64 {
debug_assert!(inductance > 0.0);
debug_assert!(frequency > 0.0);
2.0 * PI * frequency * inductance
}

#[cfg(test)]
mod tests {
use super::{get_frequency, get_inductance, get_reactance};
#[test]
fn test_get_inductance() {
assert_eq!(get_inductance(10e3, 50.0), 0.0007957747154594767);
}

#[test]
fn test_get_frequency() {
assert_eq!(get_frequency(35e-3, 50.0), 227.36420441699332);
}

#[test]
fn test_get_reactance() {
assert_eq!(get_reactance(35e-6, 1e3), 0.2199114857512855);
}
}
1 change: 1 addition & 0 deletions electronics/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ pub mod carrier_concentration;
pub mod electric_conductivity;
pub mod electric_power;
pub mod electrical_impedance;
pub mod ind_reactance;
pub mod ohms_law;
pub mod resistor_equivalence;
pub mod resonant_frequency;

0 comments on commit d73d378

Please sign in to comment.