-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #70 from GComitini/mainline-complex-integration
IMPL: generic and complex integration (#35)
- Loading branch information
Showing
3 changed files
with
178 additions
and
45 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,5 +2,6 @@ use num_complex::Complex; | |
|
||
pub type C64 = Complex<f64>; | ||
|
||
pub mod integral; | ||
pub mod matrix; | ||
pub mod vector; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters