Numerical IVP solution

The equation \(u'=\sin[(u+t)^2]\) also has a solution that can be found numerically with ease, even though no formula exists for its solution. The DifferentialEquations package offers solvers for a variety of problems. Because many practical problems come with parameters that are fixed within an instance but varied from one instance to another, the syntax for IVPs includes a input argument p that stays fixed throughout the solution. Here we don’t use that argument, but it must be in our definition for the solver to work.

using FundamentalsNumericalComputation
f = (u,p,t) -> sin((t+u)^2)     # include p even when not used
tspan = (0.0,4.0)               # use parens, at least one value is floating-point
u0 = -1.0
-1.0

With the data above we define a “problem object” and then solve it. We tell the solver to use the Tsit5 method, which is a good first choice for most problems.

ivp = ODEProblem(f,u0,tspan)
sol = solve(ivp,Tsit5());

The plot function knows natively how to plot this solution.

plot(sol,label="",ylabel="u(t)",title="\$u'=\\sin((t+u)^2)\$")