Struct ohsl::complex::Complex

source ·
pub struct Complex<T> {
    pub real: T,
    pub imag: T,
}

Fields§

§real: T

Real part of the complex number

§imag: T

Imaginary part of the complex number

Implementations§

source§

impl Complex<f64>

source

pub fn sqrt(&self) -> Complex<f64>

Return the square root of a complex number ( sqrt(z) )

source

pub fn pow(&self, w: &Complex<f64>) -> Complex<f64>

Return the complex number z raised to the power of a complex number w ( z^w )

source

pub fn powf(&self, x: f64) -> Complex<f64>

Return complex number z raised to the power of a real number x ( z^x )

source

pub fn exp(&self) -> Complex<f64>

Return the complex exponential of the complex number z ( exp(z) )

source

pub fn ln(&self) -> Complex<f64>

Return the complex logarithm of the complex number z ( ln(z) )

source

pub fn log(&self, b: Complex<f64>) -> Complex<f64>

Return the complex base-b logarithm of the complex number z ( log_b(z) )

source

pub fn polar(r: f64, theta: f64) -> Complex<f64>

Create a new complex number with magnitude r and phase angle theta

source§

impl Complex<f64>

source

pub fn sin(&self) -> Complex<f64>

Return the sin of a complex number z ( sin(z) )

source

pub fn cos(&self) -> Complex<f64>

Return the cos of a complex number z ( cos(z) )

source

pub fn tan(&self) -> Complex<f64>

Return the tan of a complex number z ( tan(z) )

source

pub fn sec(&self) -> Complex<f64>

Return the sec of a complex number z ( sec(z) )

source

pub fn csc(&self) -> Complex<f64>

Return the csc of a complex number z ( csc(z) )

source

pub fn cot(&self) -> Complex<f64>

Return the cot of a complex number z ( cot(z) )

source

pub fn asin(&self) -> Complex<f64>

Return the inverse sin of a complex number z ( asin(z) )

source

pub fn acos(&self) -> Complex<f64>

Return the inverse cos of a complex number z ( acos(z) )

source

pub fn atan(&self) -> Complex<f64>

Return the inverse tan of a complex number z ( atan(z) )

source

pub fn asec(&self) -> Complex<f64>

Return the inverse sec of a complex number z ( asec(z) )

source

pub fn acsc(&self) -> Complex<f64>

Return the inverse csc of a complex number z ( acsc(z) )

source

pub fn acot(&self) -> Complex<f64>

Return the inverse cot of a complex number z ( acot(z) )

source§

impl Complex<f64>

source

pub fn sinh(&self) -> Complex<f64>

Return the hyperbolic sine of a complex number z ( sinh(z) )

source

pub fn cosh(&self) -> Complex<f64>

Return the hyperbolic cosine of a complex number z ( cosh(z) )

source

pub fn tanh(&self) -> Complex<f64>

Return the hyperbolic tangent of a complex number z ( tanh(z) )

source

pub fn sech(&self) -> Complex<f64>

Return the hyperbolic secant of a complex number z ( sech(z) )

source

pub fn csch(&self) -> Complex<f64>

Return the hyperbolic cosecant of a complex number z ( csch(z) )

source

pub fn coth(&self) -> Complex<f64>

Return the hyperbolic cotangent of a complex number z ( coth(z) )

source

pub fn asinh(&self) -> Complex<f64>

Return the inverse hyperbolic sine of a complex number z ( asinh(z) )

source

pub fn acosh(&self) -> Complex<f64>

Return the inverse hyperbolic cosine of a complex number z ( acosh(z) )

source

pub fn atanh(&self) -> Complex<f64>

Return the inverse hyperbolic tangent of a complex number z ( atanh(z) )

source

pub fn asech(&self) -> Complex<f64>

Return the inverse hyperbolic secant of a complex number z ( asech(z) )

source

pub fn acsch(&self) -> Complex<f64>

Return the inverse hyperbolic cosecant of a complex number z ( acsch(z) )

source

pub fn acoth(&self) -> Complex<f64>

Return the inverse hyperbolic cotangent of a complex number z ( acoth(z) )

source§

impl<T> Complex<T>

source

pub const fn new(real: T, imag: T) -> Self

Create a new complex number ( z = x + iy )

Examples found in repository?
examples/complex_numbers.rs (line 12)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    println!("----- Complex numbers -----");

    // Create a new complex number
    let z = Cmplx::new( 1.0, -1.0 );
    println!( "  * z = {}", z );
    println!( "  * Re[z] = {}", z.real );
    println!( "  * Im[z] = {}", z.imag );

    // Take the conjugate
    let zbar = z.conj();
    println!("  * zbar = {}", zbar );

    // Modulus and arguement
    println!( "  * |z| = {}", z.abs() );
    println!( "  * arg(z) = {}", z.arg() );

    // Arithmetic
    let z1 = Complex::<f64>::new( 2.0, 1.0 );
    let z2 = z;
    println!( "  * z1 = {}", z1 );
    println!( "  * z2 = {}", z2 );
    println!( "  * z1 + z2 = {}", z1 + z2 );
    println!( "  * z1 - z2 = {}", z1 - z2 );
    println!( "  * z1 * z2 = {}", z1 * z2 );
    println!( "  * z1 / z2 = {}", z1 / z2 );
    let real: f64 = 2.0;
    println!( "  * z1 + 2 = {}", z1 + real );
    println!( "  * z1 - 2 = {}", z1 - real );
    println!( "  * z1 * 2 = {}", z1 * real );
    println!( "  * z1 / 2 = {}", z1 / real );
    println!( "  * z1 + i = {}", z1 + I );  
    println!( "--- FINISHED ---" );
}
More examples
Hide additional examples
examples/linear_systems.rs (line 26)
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
fn main() {
    println!( "------------------ Linear system ------------------" );
    println!( "  * Solving the linear system Ax = b, for x, where" );
    let mut a = Mat64::new( 3, 3, 0.0 );
    a[0][0] = 1.0; a[0][1] = 1.0; a[0][2] =   1.0;
    a[1][0] = 0.0; a[1][1] = 2.0; a[1][2] =   5.0;
    a[2][0] = 2.0; a[2][1] = 5.0; a[2][2] = - 1.0;
    println!( "  * A ={}", a );
    let b = Vec64::create( vec![ 6.0, -4.0, 27.0 ] ); 
    println!( "  * b^T ={}", b );
    let x = a.clone().solve_basic( b );
    println!( "  * gives the solution vector");
    println!( "  * x^T ={}", x );
    println!( "---------------------------------------------------" );
    println!( "  * Lets solve the complex linear system Cy = d where" );
    let mut c = Matrix::<Cmplx>::new( 2, 2, Cmplx::new( 1.0, 1.0 ) );
    c[0][1] = Cmplx::new( -1.0, 0.0 );
    c[1][0] = Cmplx::new( 1.0, -1.0 );
    println!( "  * C ={}", c );
    let mut d = Vector::<Cmplx>::new( 2, Cmplx::new( 0.0, 1.0 ) );
    d[1] = Cmplx::new( 1.0, 0.0 );
    println!( "  * d^T ={}", d );
    println!( "  * Using LU decomposition we find that ");
    let y = c.clone().solve_lu( d );
    println!( "  * y^T ={}", y );
    println!( "---------------------------------------------------" );
    println!( "  * We may also find the determinant of a matrix" );
    println!( "  * |A| = {}", a.clone().determinant() );
    println!( "  * |C| = {}", c.clone().determinant() ); 
    println!( "  * or the inverse of a matrix" );
    let inverse = a.clone().inverse();
    println!( "  * A^-1 =\n{}", inverse );
    println!( "  * C^-1 =\n{}", c.clone().inverse() );
    println!( "  * We can check this by multiplication" );
    println!( "  * I = A * A^-1 =\n{}", a * inverse );
    println!( "  * which is sufficiently accurate for our purposes.");
    println!( "-------------------- FINISHED ---------------------" );
}
source§

impl<T: Clone + Signed> Complex<T>

source

pub fn conj(&self) -> Self

Return the complex conjugate ( z.conj() = x - iy )

Examples found in repository?
examples/complex_numbers.rs (line 18)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    println!("----- Complex numbers -----");

    // Create a new complex number
    let z = Cmplx::new( 1.0, -1.0 );
    println!( "  * z = {}", z );
    println!( "  * Re[z] = {}", z.real );
    println!( "  * Im[z] = {}", z.imag );

    // Take the conjugate
    let zbar = z.conj();
    println!("  * zbar = {}", zbar );

    // Modulus and arguement
    println!( "  * |z| = {}", z.abs() );
    println!( "  * arg(z) = {}", z.arg() );

    // Arithmetic
    let z1 = Complex::<f64>::new( 2.0, 1.0 );
    let z2 = z;
    println!( "  * z1 = {}", z1 );
    println!( "  * z2 = {}", z2 );
    println!( "  * z1 + z2 = {}", z1 + z2 );
    println!( "  * z1 - z2 = {}", z1 - z2 );
    println!( "  * z1 * z2 = {}", z1 * z2 );
    println!( "  * z1 / z2 = {}", z1 / z2 );
    let real: f64 = 2.0;
    println!( "  * z1 + 2 = {}", z1 + real );
    println!( "  * z1 - 2 = {}", z1 - real );
    println!( "  * z1 * 2 = {}", z1 * real );
    println!( "  * z1 / 2 = {}", z1 / real );
    println!( "  * z1 + i = {}", z1 + I );  
    println!( "--- FINISHED ---" );
}
source§

impl<T: Clone + Number> Complex<T>

source

pub fn abs_sqr(&self) -> T

Return the absolute value squared ( |z|^2 = z * z.conj() )

source§

impl Complex<f64>

source

pub fn abs(&self) -> f64

Return the absolute value ( |z| = sqrt( z * z.conj() ) )

Examples found in repository?
examples/complex_numbers.rs (line 22)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    println!("----- Complex numbers -----");

    // Create a new complex number
    let z = Cmplx::new( 1.0, -1.0 );
    println!( "  * z = {}", z );
    println!( "  * Re[z] = {}", z.real );
    println!( "  * Im[z] = {}", z.imag );

    // Take the conjugate
    let zbar = z.conj();
    println!("  * zbar = {}", zbar );

    // Modulus and arguement
    println!( "  * |z| = {}", z.abs() );
    println!( "  * arg(z) = {}", z.arg() );

    // Arithmetic
    let z1 = Complex::<f64>::new( 2.0, 1.0 );
    let z2 = z;
    println!( "  * z1 = {}", z1 );
    println!( "  * z2 = {}", z2 );
    println!( "  * z1 + z2 = {}", z1 + z2 );
    println!( "  * z1 - z2 = {}", z1 - z2 );
    println!( "  * z1 * z2 = {}", z1 * z2 );
    println!( "  * z1 / z2 = {}", z1 / z2 );
    let real: f64 = 2.0;
    println!( "  * z1 + 2 = {}", z1 + real );
    println!( "  * z1 - 2 = {}", z1 - real );
    println!( "  * z1 * 2 = {}", z1 * real );
    println!( "  * z1 / 2 = {}", z1 / real );
    println!( "  * z1 + i = {}", z1 + I );  
    println!( "--- FINISHED ---" );
}
source§

impl Complex<f64>

source

pub fn arg(&self) -> f64

Return the phase angle in radians

Examples found in repository?
examples/complex_numbers.rs (line 23)
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
fn main() {
    println!("----- Complex numbers -----");

    // Create a new complex number
    let z = Cmplx::new( 1.0, -1.0 );
    println!( "  * z = {}", z );
    println!( "  * Re[z] = {}", z.real );
    println!( "  * Im[z] = {}", z.imag );

    // Take the conjugate
    let zbar = z.conj();
    println!("  * zbar = {}", zbar );

    // Modulus and arguement
    println!( "  * |z| = {}", z.abs() );
    println!( "  * arg(z) = {}", z.arg() );

    // Arithmetic
    let z1 = Complex::<f64>::new( 2.0, 1.0 );
    let z2 = z;
    println!( "  * z1 = {}", z1 );
    println!( "  * z2 = {}", z2 );
    println!( "  * z1 + z2 = {}", z1 + z2 );
    println!( "  * z1 - z2 = {}", z1 - z2 );
    println!( "  * z1 * z2 = {}", z1 * z2 );
    println!( "  * z1 / z2 = {}", z1 / z2 );
    let real: f64 = 2.0;
    println!( "  * z1 + 2 = {}", z1 + real );
    println!( "  * z1 - 2 = {}", z1 - real );
    println!( "  * z1 * 2 = {}", z1 * real );
    println!( "  * z1 / 2 = {}", z1 / real );
    println!( "  * z1 + i = {}", z1 + I );  
    println!( "--- FINISHED ---" );
}

Trait Implementations§

source§

impl<T: Number> Add<T> for Complex<T>

source§

fn add(self, plus: T) -> Self::Output

Add a complex number to a real number ( a + ib ) + c = ( a + c ) + ib

§

type Output = Complex<T>

The resulting type after applying the + operator.
source§

impl<T: Clone + Number> Add for Complex<T>

source§

fn add(self, plus: Self) -> Self::Output

Add two complex numbers together ( binary + ) ( a + ib ) + ( c + id ) = ( a + c ) + i( b + d )

§

type Output = Complex<T>

The resulting type after applying the + operator.
source§

impl<T: Number> AddAssign<T> for Complex<T>

source§

fn add_assign(&mut self, rhs: T)

Add a real number to a mutable complex variable and assign the result to that variable ( += )

source§

impl<T: Number> AddAssign for Complex<T>

source§

fn add_assign(&mut self, rhs: Self)

Add a complex number to a mutable complex variable and assign the result to that variable ( += )

source§

impl<T: Clone> Clone for Complex<T>

source§

fn clone(&self) -> Self

Clone the complex number

1.0.0 · source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
source§

impl<T> Debug for Complex<T>where T: Debug,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format the output ( z = x + iy = ( x, y ) )

source§

impl<T> Display for Complex<T>where T: Display,

source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Format the output ( z = x + iy = ( x, y ) )

source§

impl<T: Clone + Number> Div<T> for Complex<T>

source§

fn div(self, scalar: T) -> Self::Output

Divide a complex number by a real scalar ( a + ib ) / r = (a/r) + i(b/r)

§

type Output = Complex<T>

The resulting type after applying the / operator.
source§

impl<T: Clone + Number> Div for Complex<T>

source§

fn div(self, divisor: Self) -> Self::Output

Divide one complex number by another ( binary / ) ( a + ib ) / ( c + id ) = [( ac + bd ) + i( bc - ad )] / ( c^2 + d^2 )

§

type Output = Complex<T>

The resulting type after applying the / operator.
source§

impl<T: Clone + Number> DivAssign<T> for Complex<T>

source§

fn div_assign(&mut self, rhs: T)

Divide a mutable complex variable by a real number and assign the result to that variable ( /= )

source§

impl<T: Clone + Number> DivAssign for Complex<T>

source§

fn div_assign(&mut self, rhs: Self)

Divide a mutable complex variable by a complex number and assign the result to that variable ( *= )

source§

impl<T: Clone + Number> Mul<T> for Complex<T>

source§

fn mul(self, scalar: T) -> Self::Output

Multiply a complex number by a real scalar ( a + ib ) * r = (ar) + i(br)

§

type Output = Complex<T>

The resulting type after applying the * operator.
source§

impl<T: Clone + Number> Mul for Complex<T>

source§

fn mul(self, times: Self) -> Self::Output

Multiply two complex numbers together ( binary * ) ( a + ib ) * ( c + id ) = ( ac - bd ) + i( ad + bc )

§

type Output = Complex<T>

The resulting type after applying the * operator.
source§

impl<T: Clone + Number> MulAssign<T> for Complex<T>

source§

fn mul_assign(&mut self, rhs: T)

Multiply a mutable complex variable by a real number and assign the result to that variable ( *= )

source§

impl<T: Clone + Number> MulAssign for Complex<T>

source§

fn mul_assign(&mut self, rhs: Self)

Multipy a mutable complex variable by a complex number and assign the result to that variable ( *= )

source§

impl<T: Clone + Signed> Neg for Complex<T>

source§

fn neg(self) -> Self::Output

Return the unary negation ( unary - )

  • ( a + ib ) = -a - ib
§

type Output = Complex<T>

The resulting type after applying the - operator.
source§

impl<T: Clone + Number> One for Complex<T>

source§

fn one() -> Self

Return the multiplicative identity z = 1 + 0i

source§

impl<T: Clone + Number> PartialEq for Complex<T>

source§

fn eq(&self, other: &Complex<T>) -> bool

Implement trait for equality

1.0.0 · source§

fn ne(&self, other: &Rhs) -> bool

This method tests for !=. The default implementation is almost always sufficient, and should not be overridden without very good reason.
source§

impl<T: Clone + Number + PartialOrd> PartialOrd for Complex<T>

source§

fn partial_cmp(&self, other: &Complex<T>) -> Option<Ordering>

Implement trait for ordering

1.0.0 · source§

fn lt(&self, other: &Rhs) -> bool

This method tests less than (for self and other) and is used by the < operator. Read more
1.0.0 · source§

fn le(&self, other: &Rhs) -> bool

This method tests less than or equal to (for self and other) and is used by the <= operator. Read more
1.0.0 · source§

fn gt(&self, other: &Rhs) -> bool

This method tests greater than (for self and other) and is used by the > operator. Read more
1.0.0 · source§

fn ge(&self, other: &Rhs) -> bool

This method tests greater than or equal to (for self and other) and is used by the >= operator. Read more
source§

impl Signed for Complex<f64>

source§

fn abs(&self) -> Self

source§

impl<T: Number> Sub<T> for Complex<T>

source§

fn sub(self, minus: T) -> Self::Output

Subtract a real number from a complex number ( a + ib ) - c = ( a - c ) + ib

§

type Output = Complex<T>

The resulting type after applying the - operator.
source§

impl<T: Clone + Number> Sub for Complex<T>

source§

fn sub(self, minus: Self) -> Self::Output

Subtract one complex number from another ( binary - ) ( a + ib ) - ( c + id ) = ( a - c ) + i( b - d )

§

type Output = Complex<T>

The resulting type after applying the - operator.
source§

impl<T: Number> SubAssign<T> for Complex<T>

source§

fn sub_assign(&mut self, rhs: T)

Subtract a real number from a mutable complex variable and assign the result to that variable ( += )

source§

impl<T: Number> SubAssign for Complex<T>

source§

fn sub_assign(&mut self, rhs: Self)

Subtract a complex number from a mutable complex variable and assign the result to that variable ( -= )

source§

impl<T: Clone + Number> Zero for Complex<T>

source§

fn zero() -> Self

Return the additive identity z = 0 + 0i

source§

impl Copy for Complex<f64>

source§

impl<T: Number + Clone> Number for Complex<T>

Auto Trait Implementations§

§

impl<T> RefUnwindSafe for Complex<T>where T: RefUnwindSafe,

§

impl<T> Send for Complex<T>where T: Send,

§

impl<T> Sync for Complex<T>where T: Sync,

§

impl<T> Unpin for Complex<T>where T: Unpin,

§

impl<T> UnwindSafe for Complex<T>where T: UnwindSafe,

Blanket Implementations§

source§

impl<T> Any for Twhere T: 'static + ?Sized,

source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
source§

impl<T> Borrow<T> for Twhere T: ?Sized,

source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
source§

impl<T> BorrowMut<T> for Twhere T: ?Sized,

source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
source§

impl<T> From<T> for T

source§

fn from(t: T) -> T

Returns the argument unchanged.

source§

impl<T, U> Into<U> for Twhere U: From<T>,

source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

source§

impl<T> ToOwned for Twhere T: Clone,

§

type Owned = T

The resulting type after obtaining ownership.
source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. Read more
source§

impl<T> ToString for Twhere T: Display + ?Sized,

source§

default fn to_string(&self) -> String

Converts the given value to a String. Read more
source§

impl<T, U> TryFrom<U> for Twhere U: Into<T>,

§

type Error = Infallible

The type returned in the event of a conversion error.
source§

fn try_from(value: U) -> Result<T, <T as TryFrom<U>>::Error>

Performs the conversion.
source§

impl<T, U> TryInto<U> for Twhere U: TryFrom<T>,

§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.
§

impl<V, T> VZip<V> for Twhere V: MultiLane<T>,

§

fn vzip(self) -> V

source§

impl<T, Rhs> AssignOperations<Rhs> for Twhere T: AddAssign<Rhs> + SubAssign<Rhs> + MulAssign<Rhs> + DivAssign<Rhs>,

source§

impl<T, Rhs, Output> Operations<Rhs, Output> for Twhere T: Sub<Rhs, Output = Output> + Mul<Rhs, Output = Output> + Div<Rhs, Output = Output> + Add<Rhs, Output = Output>,