Join GitHub today
GitHub is home to over 28 million developers working together to host and review code, manage projects, and build software together.Sign up
[Feature request] ODE solver for complex field elements #39
I am trying to use the FieldOrdinaryDifferentialEquation with Complex type but it seems not possible to use it as the Complex type doesn't implements RealFieldElements.
I do not understand why there is such a limitation of the FODE to only accept RealFieldElement and not FieldElement more generic type. Could you tell me why?
At least we need to use the absolute value in many places, which is not defined in FieldElements.
I didn't try to move abs upward in the hierarchy and rely only on FieldElements, but if it works, it could
Mmmm, it doesn't seems to be straightforward. I'll have a deeper look at it later on.
By making the Complex type implementing the RealFieldElement to see if intermediate interface could be used, the abs() function gives problem as the return type should be a complex and not a double.
Perhaps we could also move getReal() up. Complex implements a getReal() method that returns
I guess this limitation would not be too cumbersome. For event detection the semantics
For the abs() function, we could perhaps decide to have both an abs() and absDouble() method in
In any case, this change could be done only in a 2.0 release, as it is a breaking change. This is not
After some thinking, I think there is a better way to provide complex ODE solving.
The independent variable in ODE equations (call it time, but it can be any other coordinate) is inherently a one dimensional real number. The equations by themselves can be multi-dimensional. RealField-ODE in Hipparchus use the same RealField for both the independent variable and the components of the multi-dimensional state vector. This implies that modifying RealField so Complex are a type of RealField too implies that time becomes a two-dimensional element. Even considering in ODE we simply ignore the imaginary component in the independent variable would in fact not work. Suppose for example that as part of the ODE you compute t * x1, where x1 is one of the Complex component of the state vector. Then the imaginary part of t will be taken into account in the operation, and it will have an effect on the real part of the result, which could end up in the next value for t at the end of the step. Also considering a Complex is a kind of Real is freaking.
I therefore think something different should be done.
I guess you problem is to integrate an ODE where the state is a set of complex numbers (say some electrical properties, with amplitude and phase), but they are integrated with respect to a real variable (say time), i.e. the independent variable and the state variables do not belong to the same types.
Then, a simple and probably elegant solution would be to simply set up a dedicated
and then Hipparchus would provide a converter that would convert this complex representation into the
The converter would simply copy data between n dimension complex arrays and 2n dimensions double arrays. This would be similar to the existing
Would this help you solve your problem? I think I will anyway implement it, as it is probably something useful for other users.
I have implemented the converter. It is available in the master branch.