1
2
3
4
5
6
7
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
42
43
44
45
46
47
48
use crate::traits::{
math::{Normed, Norm}
};
use crate::structure::matrix::Matrix;
use crate::numerical::{
integral,
integral::Integral::GaussLegendre,
eigen,
eigen::{Eigen, EigenMethod::Jacobi},
};
pub trait SimpleNorm: Normed {
fn norm(&self) -> Self::Scalar;
fn normalize(&self) -> Self;
}
pub fn integrate<F: Fn(f64) -> f64>(f: F, (a, b): (f64, f64)) -> f64 {
integral::integrate(f, (a, b), GaussLegendre(15))
}
pub fn eigen(m: &Matrix) -> Eigen {
eigen::eigen(m, Jacobi)
}
impl SimpleNorm for Vec<f64> {
fn norm(&self) -> Self::Scalar {
Normed::norm(self, Norm::L2)
}
fn normalize(&self) -> Self {
Normed::normalize(self, Norm::L2)
}
}
impl SimpleNorm for Matrix {
fn norm(&self) -> Self::Scalar {
Normed::norm(self, Norm::F)
}
fn normalize(&self) -> Self {
unimplemented!()
}
}