DifferentialEquations.jl is a metapackage for solving differential equations in Julia. The basic workflow is:
- Define a problem
- Solve a problem
- Plot the solution
The API between different types of differential equations is unified through multiple dispatch.
See the DifferentialEquations.jl Documentation.
using DifferentialEquations
# Define a problem
const a = 1.0; const b = 2.0
const c = 1.5; const d = 1.25
f = function (t,u,du) # Define f as an in-place update into du
du[1] = a*u[1] - b*u[1]*u[2]
du[2] = -c*u[2]+ d*u[1]*u[2]
end
u0 = [1.0;1.0]; tspan = (0.0,10.0)
prob = ODEProblem(f,u0,tspan);
# Solve the problem
sol = solve(prob);
# Plot the solution using the plot recipe
using Plots; gr() # Using the Plotly Backend
plot(sol,title="All Plots.jl Attributes are Available")
The plot recipe contains special fields for plotting phase diagrams and other transformations:
plot(sol,title="Phase Diagram",vars=(1,2))
The solution object acts both as an array and as an interpolation of the solution
@show sol.t[3] # Time at the 3rd timestep
@show sol[3] # Value at the third timestep
@show sol(5) # Value at t=5 using the interpolation
sol.t[3] = 0.29277163636804704
sol[3] = [0.768635,0.887673]
sol(5) = [1.45932,0.99208]
2-element Array{Float64,1}:
1.45932
0.99208
Also included are problems for stochastic differential equations
g = function (t,u,du)
du[1] = .5*u[1]
du[2] = .1*u[2]
end
prob = SDEProblem(f,g,u0,tspan)
sol = solve(prob,dt=1/2^4)
plot(sol)
For more information, see the documentation: https://github.com/JuliaDiffEq/DifferentialEquations.jl
The DifferentialEquations.jl algorithms choose the number type of their calculation given their input. Use this fact to solve the Lorenz equation using BigFloats. You may want to check out the example notebooks. Make a 3D plot of the Lorenz attractor using the plot recipe.
Use the event handling the model a bouncing ball with friction, i.e. at every bounce the velocity flips but is decreased to 80%. Does the ball eventually stop bouncing?
Install the LSODA and ODEInterfaceDiffEq (note: ODEInterface may give build issues on Windows! See the repo README for details on setting up the compiler) and run some of the benchmarks notebooks on your machine. Do you notice any trends amongst the algorithms? Use the method as shown in the Pleiades benchmarks to benchmark the algorithms against each other on nonlinear problems with no known analytical solution. Try building an example problem with a large number of independent variables to accentuate the differences between the algorithms (Example: the Linear problem in the benchmarks is a 100x100 problem).