Crates.io | croot |
lib.rs | croot |
version | 0.3.3 |
source | src |
created_at | 2023-04-21 21:56:39.706029 |
updated_at | 2023-05-14 22:57:33.684783 |
description | A crate for finding real and complex roots |
homepage | |
repository | https://github.com/Ross-Morgan/croot/ |
max_upload_size | |
id | 845678 |
size | 11,382 |
A Rust library for finding complex and principal roots of real and complex values;
Any number, real or complex, has n nth-roots.
For example, there are 4 values for the 4th-root of 1
Usually, we ignore all but the principal root; that with the largest real component
The principal 4th-root of 1 is 1
, but the others are [-1, i, -i]
Results in examples have been rounded to 5 decimal places
The root with the largest real, and positive imaginary component
For finding the principal root of a real value, we use principal_root
principal_root(1.0, 4); // 1.0
principal_root(-1.0, 4); // 0.707107 + 0.707107i
For finding the principal root of a complex value, we use complex_principal_root
let c1 = Complex64::new(3.0, 4.0); // 3 + 4i
let c2 = Complex64::new(10.0, 2.0); // 10 + 2i
complex_principal_root(c1, 3) // 1.62894 + 0.52017
complex_principal_root(c1, 3) // 2.16387 + 0.14259
n values which when raised to the nth-power, give the original value
For finding all roots of a real value, we use root
root(1.0, 2); // [1.0, -1.0]
root(1.0, 4); // [1.0, -1.0, i, -i]
root(81.0, 4); // [3.0, -3.0, 3i, -3i]
For finding all roots of a complex number, we use complex_root
let c1 = Complex64::new(3.0, 4.0) // 3 + 4i
let c2 = Complex64::new(10.0, 2.0) // 10 + 2i
complex_root(c1, 3) // [1.6289 + 0.5202i, -1.2650 + 1.1506i, -0.3640 - 1.6708i]
complex_root(c2, 3) // [2.1639 + 0.14259, -1.2054 + 1.8027i, -0.9585 - 1.9453i]
The nth-roots of unity are the nth-roots of 1
The nth-roots of 1
can be found with roots_of_unity
roots_of_unity(3); // [1, -0.5 + 0.8660i, -0.5 - 0.8660i]
roots_of_unity(4); // [1, i, -1, -i]