Skip to content

Latest commit

 

History

History
130 lines (112 loc) · 4.36 KB

difeqs-with-julia.org

File metadata and controls

130 lines (112 loc) · 4.36 KB

introduction to solving differential equations with julia

import Pkg; Pkg.add("DifferentialEquations")
import Pkg; Pkg.add("Plots")

basic introduction via ODEs

corresponding docs: http://docs.juliadiffeq.org/latest/tutorials/ode_example.html

have IVP:

$$\frac{du}{dt} = f(u, p, t)$$

where $u$ is a (multivariate) variable, $p$ is model parameters, $t$ is time.

first model: exponential growth

$$u’ = au$$ $$u(0)=u_0$$

specifically:

$$a = 0.98$$ $$u_0 = 1.0$$

using DifferentialEquations
f(u,p,t) = 0.98u
u0 = 1.0
tspan = (0.0,1.0)
prob = ODEProblem(f,u0,tspan)

to solve:

sol = solve(prob)

solution has `t`, `u`, but also interpolation and return code.

plot it:

using Plots; gr()
plot(sol,linewidth=5,title="Solution to the linear ODE with a thick line",
     xaxis="Time (t)",yaxis="u(t) (in μm)",label="My Thick Line!") # legend=false
plot!(sol.t, t->1.0*exp(0.98t),lw=3,ls=:dash,label="True Solution!")