In [ ]:
import numpy as np
from pycvodes import integrate_adaptive, fpes
from van_der_pol import get_f_and_j
In [ ]:
help(integrate_adaptive)
In [ ]:
rhs, jac = get_f_and_j(1.0)
xout, yout, info = integrate_adaptive(
rhs, jac, [0, 1], 0, 25.0, dx0=1e-12, atol=1e-7, rtol=1e-7,
record_rhs_xvals=True, record_jac_xvals=True, record_order=True,
record_fpe=True, record_steps=True, nsteps=2000, ew_ele=True)
print(info['success'])
In [ ]:
import matplotlib.pyplot as plt
%matplotlib inline
fig, axes = plt.subplots(7, 1, figsize=(16,20))
for k, ax in zip(['steps', 'rhs', 'jac'], axes.flat):
for x in xout if k == 'steps' else info[k + '_xvals']:
ax.axvline(x, c='darkgreen', alpha=0.1)
ax.plot(xout, yout)
ax.set_xlim([xout[0], xout[-1]])
ax.set_ylabel(k)
axes[-4].plot(info['steps'])
axes[-4].set_ylabel('step-size')
axes[-3].plot(xout[1:], info['fpes'][1:] - fpes['FE_INEXACT'])
axes[-3].set_ylabel('fpes')
axes[-2].plot(xout, info['orders'])
axes[-2].set_ylabel('order')
axes[-1].plot(xout, np.prod(info['ew_ele'], axis=1))
_ = plt.tight_layout
In [ ]:
fpes
In [ ]:
info['steps'].size, xout.size
In [ ]:
sum(info['steps']), xout[-1]
In [ ]: