-
Notifications
You must be signed in to change notification settings - Fork 26
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implement system solvers for complex vectors #14
Comments
Hi. Unfortunately I won't have time to work on this in the near future. Feel free to implement it and submit a PR. |
You can add support for complex vectors in This seems to work fine for |
Support for Complex ode systems could be implemented by wrapping the existing real solvers, similar to the approach used in scipy with the complex_ode class The mathematical background is that the complex field Instead of directly solving the complex ode system, we would map the n dimensional complex system to a 2n dimensional real system. Then, we can apply all the existing (and future) real ode solvers to the real state, and map the results back to the complex state. The user defines the system using complex numbers, i.e., with nalgebra::Complex ExampleThe exponential equation has the form The solution to this equation is Instead of solving the complex system for Unit Test (draft with real system)#[cfg(test)]
mod tests {
use crate::rk4::Rk4;
use crate::{OVector, System, Vector2};
use nalgebra::{allocator::Allocator, DefaultAllocator, Dim};
struct Test1 {}
impl<D: Dim> System<f64, OVector<f64, D>> for Test1
where
DefaultAllocator: Allocator<f64, D>,
{
fn system(&self, x: f64, y: &OVector<f64, D>, dy: &mut OVector<f64, D>) {
// dy/dt = iy with y = a + bi => dy/dt = ai - b = -b + ai
dy[0] = -y[1]; // -b
dy[1] = y[0]; // a
}
}
#[test]
fn test_complex_test1_svector() {
let system = Test1 {};
let t_end: f64 = 0.2;
let real_end_state = Vector2::new(t_end.cos(), t_end.sin());
let mut stepper = Rk4::new(system, 0., Vector2::new(1., 0.), t_end, 0.1);
let _ = stepper.integrate();
let x_out = stepper.x_out();
let y_out = stepper.y_out();
assert!(
(*x_out.last().unwrap() - t_end).abs() < 1.0E-8,
"x_out must end with x_end"
);
assert!(
y_out
.last()
.unwrap()
.relative_eq(&real_end_state, 1.0E-5, 1.0E-5),
"The last state must be the solution at x_end!"
);
}
} |
I've implemented
System
trait for my System, but I want to useDVector<Complex<f64>>
as myy
value.As i can see,
DVector
support in this crate is WIP, but nothing is said aboutComplex
types. Would you manage to add support for it?The text was updated successfully, but these errors were encountered: