Skip to content
This repository has been archived by the owner on Sep 9, 2024. It is now read-only.

Complex variables support #39

Closed
pwl opened this issue Jun 14, 2014 · 2 comments
Closed

Complex variables support #39

pwl opened this issue Jun 14, 2014 · 2 comments

Comments

@pwl
Copy link

pwl commented Jun 14, 2014

Are the equations for complex dependent variables officially supported? I tried to solve the following simple equation and I got the InexactError():

julia> F(t,y)=1im*y
F (generic function with 1 method)

julia> ODE.ode45(F,y0,[0.0,1.0])
ERROR: InexactError()
 in setindex! at array.jl:305

julia> y0=[0.0im]
1-element Array{Complex{Float64},1}:
 0.0+0.0im

julia> ODE.ode45(F,y0,[0.0,1.0])
ERROR: InexactError()
 in setindex! at array.jl:305

EDIT: ok, I have just read the example by @acroy in issue #37. Why is there a new type needed to get the complex numbers working?

@acroy
Copy link
Contributor

acroy commented Jun 14, 2014

Basically, complex variables are not a problem:

julia> y0=1.
1.0

julia> ODE.ode45(F,y0,[0.0,1.0])
ERROR: InexactError()
 in setindex! at array.jl:296
 in oderkf at /Users/acr/Development/Julia/ODE.jl/src/ODE.jl:203
 in ode45_dp at /Users/acr/Development/Julia/ODE.jl/src/ODE.jl:298

julia> y0=complex(1.,0.)
1.0 + 0.0im

julia> ODE.ode45(F,y0,[0.0,1.0])
([0.0,0.01,0.34233,0.674447,1.0],Complex{Float64}[1.0+0.0im,0.99995+0.00999983im,0.941975+0.335683im,0.781052+0.624465im,0.540301+0.841471im])

julia> y0=complex([1.])
1-element Array{Complex{Float64},1}:
 1.0+0.0im

julia> ODE.ode45(F,y0,[0.0,1.0])
([0.0,0.01,0.34233,0.674447,1.0],[Complex{Float64}[1.0+0.0im],Complex{Float64}[0.99995+0.00999983im],Complex{Float64}[0.941975+0.335683im],Complex{Float64}[0.781052+0.624465im],Complex{Float64}[0.540301+0.841471im]])

As you can see above (and as we state somewhere in doc/api.md - I think), the return type of F must be the same as the type of y0 (roughly speaking).

Which version of ODE.jl are you using? I used the latest master ...

@pwl
Copy link
Author

pwl commented Jun 14, 2014

I updated to master and the problem disappeared. Thanks!

@pwl pwl closed this as completed Jun 14, 2014
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants