This example looks at the effect of the 'reltol' setting of casadi::Integrator.
View output (PDF) | source (python)
- See also
CASADI_EXPORT Function integrator(const std::string &name, const std::string &solver, const SXDict &dae, const Dict &opts=Dict())
33 states = vertcat(x,dx)
35 dae={
'x':states,
'ode':vertcat(dx,-x)}
38 ts = linspace(0,tend,1000)
40 tolerances = [-10,-5,-4,-3,-2,-1]
44 for tol
in tolerances:
45 opts = {
'reltol':10.0**tol,
'abstol':10.0**tol,
'grid':ts,
'output_t0':
True}
48 plot(ts,array(res[
'xf'])[0,:].T,label=
'tol = 1e%d' % tol)
49 legend( loc=
'upper left')
55 tolerances = logspace(-15,1,500)
58 for tol
in tolerances:
65 endresult.append(res[
'xf'][0])
67 endresult = vcat(endresult)
70 loglog(tolerances,(array(endresult)-1),
'b',label=
'Positive error')
71 loglog(tolerances,-(array(endresult)-1),
'r',label=
'Negative error')
72 xlabel(
'Integrator relative tolerance')
73 ylabel(
'Error at the end of integration time')
74 legend(loc=
'upper left')