Skip to content

Commit

Permalink
Merge branch '35-support-complex-number' into dev (#35)
Browse files Browse the repository at this point in the history
  • Loading branch information
Axect committed Oct 4, 2024
2 parents 0eea0a4 + af74daa commit ff880f2
Show file tree
Hide file tree
Showing 14 changed files with 3,218 additions and 178 deletions.
26 changes: 21 additions & 5 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,14 @@ categories = ["science"]
readme = "README.md"
documentation = "https://axect.github.io/Peroxide_Doc"
keywords = ["Numeric", "Science", "Dataframe", "Plot", "LinearAlgebra"]
exclude = ["example_data/", "src/bin/", "benches/", "example/", "test_data/", "peroxide-ad2"]
exclude = [
"example_data/",
"src/bin/",
"benches/",
"example/",
"test_data/",
"peroxide-ad2",
]

[badges]
travis-ci = { repository = "axect/peroxide" }
Expand All @@ -32,17 +39,26 @@ anyhow = "1.0"
paste = "1.0"
#num-complex = "0.3"
netcdf = { version = "0.7", optional = true, default-features = false }
pyo3 = { version = "0.22", optional = true, features = ["auto-initialize", "gil-refs"] }
pyo3 = { version = "0.22", optional = true, features = [
"auto-initialize",
"gil-refs",
] }
blas = { version = "0.22", optional = true }
lapack = { version = "0.19", optional = true }
serde = { version = "1.0", features = ["derive"], optional = true }
json = { version = "0.12", optional = true }
arrow2 = { version = "0.18", features = ["io_parquet", "io_parquet_compression"], optional = true }
arrow2 = { version = "0.18", features = [
"io_parquet",
"io_parquet_compression",
], optional = true }
num-complex = { version = "0.4", optional = true }
lambert_w = { version = "0.4.0", default-features = false, features = ["24bits", "50bits"] }
lambert_w = { version = "0.4.0", default-features = false, features = [
"24bits",
"50bits",
] }

[package.metadata.docs.rs]
rustdoc-args = [ "--html-in-header", "katex-header.html", "--cfg", "docsrs"]
rustdoc-args = ["--html-in-header", "katex-header.html", "--cfg", "docsrs"]

[features]
default = []
Expand Down
53 changes: 53 additions & 0 deletions src/complex/integral.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
use crate::complex::C64;
use crate::numerical::integral::{GKIntegrable, GLKIntegrable, NCIntegrable};
use crate::structure::polynomial::{lagrange_polynomial, Calculus, Polynomial};

// Newton Cotes Quadrature for Complex Functions of one Real Variable
impl NCIntegrable for C64 {
type NodeY = (Vec<f64>, Vec<f64>);
type NCPolynomial = (Polynomial, Polynomial);

fn compute_node_y<F>(f: F, node_x: &[f64]) -> Self::NodeY
where
F: Fn(f64) -> Self,
{
node_x
.iter()
.map(|x| {
let z = f(*x);
(z.re, z.im)
})
.unzip()
}

fn compute_polynomial(node_x: &[f64], node_y: &Self::NodeY) -> Self::NCPolynomial {
(
lagrange_polynomial(node_x.to_vec(), node_y.0.to_vec()),
lagrange_polynomial(node_x.to_vec(), node_y.1.to_vec()),
)
}

fn integrate_polynomial(p: &Self::NCPolynomial) -> Self::NCPolynomial {
(p.0.integral(), p.1.integral())
}

fn evaluate_polynomial(p: &Self::NCPolynomial, x: f64) -> Self {
p.0.eval(x) + C64::I * p.1.eval(x)
}
}

// Gauss Lagrange and Kronrod Quadrature for Complex Functions of one Real Variable
impl GLKIntegrable for C64 {
const ZERO: Self = C64::ZERO;
}

// Gauss Kronrod Quadrature for Complex Functions of one Real Variable
impl GKIntegrable for C64 {
fn is_finite(&self) -> bool {
C64::is_finite(*self)
}

fn gk_norm(&self) -> f64 {
self.norm()
}
}
Loading

0 comments on commit ff880f2

Please sign in to comment.