def test_lorenz(self): """Test the Lorenz model ODE convenience function.""" rv = Constant(np.array([1.0, 1.0, 1.0])) lg1 = ivp_examples.lorenz(self.tspan, rv) lg2 = ivp_examples.lorenz( self.tspan, rv, params=( 10.0, 28.0, 8.0 / 3.0, ), ) self.assertIsInstance(lg1, ivp.IVP) self.assertIsInstance(lg2, ivp.IVP)
def test_lorenz_jacobian(self): rv = Constant(np.array([1.0, 1.0, 1.0])) lg1 = ivp_examples.lorenz(self.tspan, rv) random_direction = 1 + 0.1 * np.random.rand(lg1.dimension) random_point = 1 + np.random.rand(lg1.dimension) fd_approx = (0.5 * 1.0 / self.dt * (lg1(0.1, random_point + self.dt * random_direction) - lg1(0.1, random_point - self.dt * random_direction))) self.assertAllClose( lg1.jacobian(0.1, random_point) @ random_direction, fd_approx, rtol=self.rtol, )
def test_lorenz_rhs(self): rv = Constant(np.ones(3)) lg1 = ivp_examples.lorenz(self.tspan, rv) self.assertEqual(lg1.rhs(0.1, rv).shape, rv.shape)