Help with deSolveDiffEq

Why with deSolveDiffEq I am not receiving all the solutions of the system, as can be seen in the examples?

I only get these results

19:42:41->>retcode: Default
Interpolation: 1st order linear
t: 2-element view(::Array{Float64,2}, :, 1) with eltype Float64:
  0.0
 50.0
u: 2-element Array{Array{Float64,1},1}:
 [0.0, 0.66]
 [-33.0, 15.510000000000002]
### Examples  
using DifferentialEquations
using Plots; gr()
function integrate_ODE!(du,u,t)
    du[1] = -0.4*u[1] - u[2]
    du[2] = u[1] + 0.45*u[2]   
end
u0 = [0.0,0.66]
tspan = (0.0,50.0)
prob = ODEProblem(integrate_ODE!,u0,tspan)
sol = solve(prob)# Euler ImplicitEuler 
plot(sol,linewidth=2,xaxis="t",layout=(2,1))
plot(sol,vars=(1,2), lw=1)

#
using OrdinaryDiffEq
prob = ODEProblem(integrate_ODE!,u0,tspan)
OrdinaryDiffEq.solve(prob, ImplicitEuler())
plot(sol,linewidth=2,xaxis="t",layout=(2,1))
plot(sol,vars=(1,2), lw=1)

#
A=[-0.4 -1.0
    1.0 0.45]
u0 = [0.0; 0.66]
tspan = (0.0,50.0)
f(u,p,t)=A*u
prob = ODEProblem(f,u0,tspan)
sol=solve(prob)
plot(sol,linewidth=2,xaxis="t",layout=(2,1))
plot(sol,vars=(1,2), lw=1)

#
using deSolveDiffEq
u0 = [0.0;0.66]
tspan = (0.0,50.0)
prob = ODEProblem(integrate_ODE!,u0,tspan)
sol = solve(prob,deSolveDiffEq.euler()) 
#

you mean integrate_ODE!(du,u,p,t)?

In function integr_ODE! (du, u, t), I do not declare parameters. Should I in the declaration of the function, enter it, even though in the body of the function I don’t use them?

function integrate_ODE!(du,u,t)
    du[1] = -0.4*u[1] - u[2]
    du[2] = u[1] + 0.45*u[2]   
end
function integrate_ODE!(du,u,p,t)
    du[1] = -0.4*u[1] - u[2]
    du[2] = u[1] + 0.45*u[2]   
end

using deSolveDiffEq

u0 = [0.0;0.66]
tspan = (0.0,50.0)
prob = ODEProblem(integrate_ODE!,u0,tspan)
sol = solve(prob,deSolveDiffEq.euler())
08:51:07->>retcode: Default
Interpolation: 1st order linear
t: 2-element view(::Array{Float64,2}, :, 1) with eltype Float64:
  0.0
 50.0
u: 2-element Array{Array{Float64,1},1}:
 [0.0, 0.66]
 [-33.0, 15.510000000000002]

Introducing in solve, saveat = 0.1, I get the results!

sol = solve(prob,deSolveDiffEq.euler(),saveat=0.1) 
>retcode: Default
Interpolation: 1st order linear
t: 501-element view(::Array{Float64,2}, :, 1) with eltype Float64:
  0.0
  0.1
  0.2
  0.3
  0.4
  0.5
  0.6
  0.7
  0.8
  0.9
  1.0
  ⋮
 49.1
 49.2
 49.3
 49.4
 49.5
 49.6
 49.7
 49.8
 49.9
 50.0
u: 501-element Array{Array{Float64,1},1}:
 [0.0, 0.66]
 [-0.066, 0.6897]
 [-0.13233, 0.7141365]
 [-0.19845045, 0.7330396425]
 [-0.26381639625000003, 0.7461813814125]
 [-0.32788187854125, 0.7533779039510625]
 [-0.39010439379470624, 0.7544917217747353]
 [-0.4499493902203915, 0.7494334098751279]
 [-0.5068947555990887, 0.7381629742974695]
 [-0.5604352628048721, 0.7206908325809467]
 [-0.6100869355507719, 0.6970783937666021]
 ⋮
 [-4.192619673242593, 17.848340068051428]
 [-5.809748893118055, 18.23225340378949]
 [-7.400584277772191, 18.471729917648197]
 [-8.951733898426145, 18.56289933616515]
 [-10.449954476105635, 18.503056416449965]
 [-11.882261938706426, 18.29069850757965]
 [-13.236041311916154, 17.925553746550086]
 [-14.499155034094445, 17.408599533953254]
 [-15.660048786126008, 16.742071009571696]
 [-16.707853935638152, 15.929459326389809]

My next question,
How to see the saveat, which was used by default in the previous examples? To be able to replicate it in this case

I think when you choose a method with fixed time steps, deSolve chooses to set the time step to the maximal value unless you specify a dt which we do implicitly through saveat because of how it mixes those ideas. You can’t make deSolveDiffEq.euler adaptive because their implementation of it is not adaptive.

BTW, I’m curious what the purpose of this exercise is. Using Euler from deSolve is a very curious thing :laughing:

1 Like