Using an IVP solution

We return to he equation \(u'=\sin[(u+t)^2]\) to inspect the output a bit more closely. The solution returned by DifferntialEquations acts like any callable function that can be evaluated at different values of \(t\), or plotted.

using FundamentalsNumericalComputation
f = (u,p,t) -> sin((t+u)^2);
tspan = (0.0,4.0);
u0 = -1.0;

ivp = ODEProblem(f,u0,tspan)
sol = solve(ivp,Tsit5());
@show sol(1.0);
@show sol.(0:.25:4);
sol(1.0) = -0.7903205813695868
sol.(0:0.25:4) = [-1.0, -0.853363106912641, -0.8020190841222593, -0.7933376865610076, -0.7903205813695868, -0.7587997812653271, -0.6515479926684693, -0.430971843510511, -0.2720391176721296, -0.33026780205097683, -0.495923334593884, -0.7021153944509847, -0.9261837658860447, -1.1589646547543004, -1.396786118578921, -1.6377791463281381, -1.8808597078036184]
plot(sol,label="u(t)")

The solution object holds some information about how the values and plot are produced:

sol
retcode: Success
Interpolation: specialized 4th order "free" interpolation
t: 15-element Array{Float64,1}:
 0.0
 0.08678069499623003
 0.2410351946142484
 0.4646651002889638
 0.696832349092298
 1.008615306920793
 1.3746102413343677
 1.704068006538051
 1.9357170751926207
 2.17184202493634
 2.4842966521192085
 2.694248741931428
 3.270491704240511
 3.625336900731927
 4.0
u: 15-element Array{Float64,1}:
 -1.0
 -0.9348300565111116
 -0.8566169597535431
 -0.8056683891198451
 -0.7936141682195507
 -0.7899253244169848
 -0.718601352601633
 -0.47683702734677913
 -0.29032951617928826
 -0.29499385673736533
 -0.4839483677250998
 -0.6541211733693211
 -1.1782986500945718
 -1.517292599725355
 -1.88085970780362

As you can guess from the output above, the object performs some interpolation on some discrete solution values (in this case, 15 of them). This chapter is about how the discrete \(t\) and \(u\) values are computed. For now, just note how we can extract them from the solution object.

scatter!(sol.t,sol.u,label="discrete values")