当前位置: 首页>>代码示例>>Python>>正文


Python integrate.ode方法代码示例

本文整理汇总了Python中scipy.integrate.ode方法的典型用法代码示例。如果您正苦于以下问题:Python integrate.ode方法的具体用法?Python integrate.ode怎么用?Python integrate.ode使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在scipy.integrate的用法示例。


在下文中一共展示了integrate.ode方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _do_problem

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _do_problem(self, problem, integrator, method='adams'):

        # ode has callback arguments in different order than odeint
        f = lambda t, z: problem.f(z, t)
        jac = None
        if hasattr(problem, 'jac'):
            jac = lambda t, z: problem.jac(z, t)

        ig = ode(f, jac)
        ig.set_integrator(integrator,
                          atol=problem.atol/10,
                          rtol=problem.rtol/10,
                          method=method)
        ig.set_initial_value(problem.z0, t=0.0)
        z = ig.integrate(problem.stop_t)

        assert_(ig.successful(), (problem, method))
        assert_(problem.verify(array([z]), problem.stop_t), (problem, method)) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:20,代码来源:test_integrate.py

示例2: _run_solout_test

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _run_solout_test(self, integrator):
        # Check correct usage of solout
        ts = []
        ys = []
        t0 = 0.0
        tend = 10.0
        y0 = [1.0, 2.0]
        def solout(t, y):
            ts.append(t)
            ys.append(y.copy())
        def rhs(t, y):
            return [y[0] + y[1], -y[1]**2]
        ig = ode(rhs).set_integrator(integrator)
        ig.set_solout(solout)
        ig.set_initial_value(y0, t0)
        ret = ig.integrate(tend)
        assert_array_equal(ys[0], y0)
        assert_array_equal(ys[-1], ret)
        assert_equal(ts[0], t0)
        assert_equal(ts[-1], tend) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:22,代码来源:test_integrate.py

示例3: _run_solout_test

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _run_solout_test(self, integrator):
        # Check correct usage of solout
        ts = []
        ys = []
        t0 = 0.0
        tend = 10.0
        y0 = [1.0, 2.0]

        def solout(t, y):
            ts.append(t)
            ys.append(y.copy())

        def rhs(t, y):
            return [y[0] + y[1], -y[1]**2]

        ig = ode(rhs).set_integrator(integrator)
        ig.set_solout(solout)
        ig.set_initial_value(y0, t0)
        ret = ig.integrate(tend)
        assert_array_equal(ys[0], y0)
        assert_array_equal(ys[-1], ret)
        assert_equal(ts[0], t0)
        assert_equal(ts[-1], tend) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:25,代码来源:test_integrate.py

示例4: __init__

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def __init__(self, fun, t0, y0, t_bound, first_step=None, min_step=0.0,
                 max_step=np.inf, rtol=1e-3, atol=1e-6, jac=None, lband=None,
                 uband=None, vectorized=False, **extraneous):
        warn_extraneous(extraneous)
        super(LSODA, self).__init__(fun, t0, y0, t_bound, vectorized)

        if first_step is None:
            first_step = 0  # LSODA value for automatic selection.
        elif first_step <= 0:
            raise ValueError("`first_step` must be positive or None.")

        if max_step == np.inf:
            max_step = 0  # LSODA value for infinity.
        elif max_step <= 0:
            raise ValueError("`max_step` must be positive.")

        if min_step < 0:
            raise ValueError("`min_step` must be nonnegative.")

        rtol, atol = validate_tol(rtol, atol, self.n)

        if jac is None:  # No lambda as PEP8 insists.
            def jac():
                return None

        solver = ode(self.fun, jac)
        solver.set_integrator('lsoda', rtol=rtol, atol=atol, max_step=max_step,
                              min_step=min_step, first_step=first_step,
                              lband=lband, uband=uband)
        solver.set_initial_value(y0, t0)

        # Inject t_bound into rwork array as needed for itask=5.
        solver._integrator.rwork[0] = self.t_bound
        solver._integrator.call_args[4] = solver._integrator.rwork

        self._lsoda_solver = solver 
开发者ID:ryfeus,项目名称:lambda-packs,代码行数:38,代码来源:lsoda.py

示例5: test_concurrent_fail

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def test_concurrent_fail(self):
        for sol in ('vode', 'zvode', 'lsoda'):
            f = lambda t, y: 1.0

            r = ode(f).set_integrator(sol)
            r.set_initial_value(0, 0)

            r2 = ode(f).set_integrator(sol)
            r2.set_initial_value(0, 0)

            r.integrate(r.t + 0.1)
            r2.integrate(r2.t + 0.1)

            assert_raises(RuntimeError, r.integrate, r.t + 0.1) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:16,代码来源:test_integrate.py

示例6: test_concurrent_ok

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def test_concurrent_ok(self):
        f = lambda t, y: 1.0

        for k in xrange(3):
            for sol in ('vode', 'zvode', 'lsoda', 'dopri5', 'dop853'):
                r = ode(f).set_integrator(sol)
                r.set_initial_value(0, 0)

                r2 = ode(f).set_integrator(sol)
                r2.set_initial_value(0, 0)

                r.integrate(r.t + 0.1)
                r2.integrate(r2.t + 0.1)
                r2.integrate(r2.t + 0.1)

                assert_allclose(r.y, 0.1)
                assert_allclose(r2.y, 0.2)

            for sol in ('dopri5', 'dop853'):
                r = ode(f).set_integrator(sol)
                r.set_initial_value(0, 0)

                r2 = ode(f).set_integrator(sol)
                r2.set_initial_value(0, 0)

                r.integrate(r.t + 0.1)
                r.integrate(r.t + 0.1)
                r2.integrate(r2.t + 0.1)
                r.integrate(r.t + 0.1)
                r2.integrate(r2.t + 0.1)

                assert_allclose(r.y, 0.3)
                assert_allclose(r2.y, 0.2) 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:35,代码来源:test_integrate.py

示例7: _get_solver

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _get_solver(self, f, jac):
        solver = ode(f, jac)
        if self.solver_uses_jac:
            solver.set_integrator(self.solver_name, atol=1e-9, rtol=1e-7,
                                  with_jacobian=self.solver_uses_jac)
        else:
            # XXX Shouldn't set_integrator *always* accept the keyword arg
            # 'with_jacobian', and perhaps raise an exception if it is set
            # to True if the solver can't actually use it?
            solver.set_integrator(self.solver_name, atol=1e-9, rtol=1e-7)
        return solver 
开发者ID:ktraunmueller,项目名称:Computable,代码行数:13,代码来源:test_integrate.py

示例8: __init__

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def __init__(self, t0=None, y0=None, rhs=None, options=None):

        # all de specification arguments are necessary to instantiate scipy ode object
        if (t0 is None) or (y0 is None) or (rhs is None):
            raise Exception('QiskitZVODE solver requires t0, y0, and rhs at instantiation.')

        # initialize internal attribute for storing scipy ode object
        self._ODE = None

        super().__init__(t0, y0, rhs, options) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:12,代码来源:DE_Methods.py

示例9: set_rhs

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def set_rhs(self, rhs=None, reset=True):
        """This set_rhs function fully instantiates the scipy ode object behind the scenes."""

        if rhs is None:
            rhs = {'rhs': None}

        if callable(rhs):
            rhs = {'rhs': rhs}

        if 'rhs' not in rhs:
            raise Exception('ODE_Method requires at minimum a specification of an rhs function.')

        self.rhs = self._state_type_converter.transform_rhs_funcs(rhs)

        self._ODE = ode(self.rhs['rhs'])

        self._ODE._integrator = qiskit_zvode(method=self.options.method,
                                             order=self.options.order,
                                             atol=self.options.atol,
                                             rtol=self.options.rtol,
                                             nsteps=self.options.nsteps,
                                             first_step=self.options.first_step,
                                             min_step=self.options.min_step,
                                             max_step=self.options.max_step
                                             )

        # Forces complex ODE solving
        if not self._ODE._y:
            self._ODE.t = 0.0
            self._ODE._y = np.array([0.0], complex)
        self._ODE._integrator.reset(len(self._ODE._y), self._ODE.jac is not None)

        self._ODE.set_initial_value(self._y, self._t)

        self._reset_method(reset) 
开发者ID:Qiskit,项目名称:qiskit-aer,代码行数:37,代码来源:DE_Methods.py

示例10: __init__

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def __init__(self, integrator='dopri5', **kwargs):
        """
        Args:
            integrator(str): String to choose the integrator from the scipy.integrate.ode
            kwargs(dict): All parameters that can be set in the "set_integrator"-method of scipy.integrate.ode
        """
        self._solver = None
        self._solver_args = kwargs
        self._integrator = integrator 
开发者ID:upb-lea,项目名称:gym-electric-motor,代码行数:11,代码来源:solvers.py

示例11: set_system_equation

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def set_system_equation(self, system_equation, jac=None):
        # Docstring of superclass
        super().set_system_equation(system_equation, jac)
        self._ode = ode(system_equation, jac).set_integrator(self._integrator, **self._solver_args) 
开发者ID:upb-lea,项目名称:gym-electric-motor,代码行数:6,代码来源:solvers.py

示例12: _do_problem

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _do_problem(self, problem, integrator, method='adams'):

        # ode has callback arguments in different order than odeint
        f = lambda t, z: problem.f(z, t)
        jac = None
        if hasattr(problem, 'jac'):
            jac = lambda t, z: problem.jac(z, t)

        integrator_params = {}
        if problem.lband is not None or problem.uband is not None:
            integrator_params['uband'] = problem.uband
            integrator_params['lband'] = problem.lband

        ig = self.ode_class(f, jac)
        ig.set_integrator(integrator,
                          atol=problem.atol/10,
                          rtol=problem.rtol/10,
                          method=method,
                          **integrator_params)

        ig.set_initial_value(problem.z0, t=0.0)
        z = ig.integrate(problem.stop_t)

        assert_array_equal(z, ig.y)
        assert_(ig.successful(), (problem, method))
        assert_(ig.get_return_code() > 0, (problem, method))
        assert_(problem.verify(array([z]), problem.stop_t), (problem, method)) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:29,代码来源:test_integrate.py

示例13: _run_solout_break_test

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _run_solout_break_test(self, integrator):
        # Check correct usage of stopping via solout
        ts = []
        ys = []
        t0 = 0.0
        tend = 10.0
        y0 = [1.0, 2.0]

        def solout(t, y):
            ts.append(t)
            ys.append(y.copy())
            if t > tend/2.0:
                return -1

        def rhs(t, y):
            return [y[0] + y[1], -y[1]**2]

        ig = ode(rhs).set_integrator(integrator)
        ig.set_solout(solout)
        ig.set_initial_value(y0, t0)
        ret = ig.integrate(tend)
        assert_array_equal(ys[0], y0)
        assert_array_equal(ys[-1], ret)
        assert_equal(ts[0], t0)
        assert_(ts[-1] > tend/2.0)
        assert_(ts[-1] < tend) 
开发者ID:Relph1119,项目名称:GraphicDesignPatternByPython,代码行数:28,代码来源:test_integrate.py

示例14: set_integrator

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def set_integrator(self, name, **kwargs):
		self.f = ode(self.model.integration_loop)
		self.f.set_integrator(name, **kwargs)
		self.f.set_initial_value(self.init_state, self.t0) 
开发者ID:lindemer,项目名称:baldr,代码行数:6,代码来源:simulators.py

示例15: _dynamics

# 需要导入模块: from scipy import integrate [as 别名]
# 或者: from scipy.integrate import ode [as 别名]
def _dynamics(self, t, state, action):
        """ Evaluate the system dynamics

        Parameters
        ----------
        t: float
            Input Parameter required for the odesolver for time-dependent
            odes. Has no influence in this system.
        state: 2x1 array[float]
            The current state of the system
        action: 1x1 array[float]
            The action to be applied at the current time step

        Returns
        -------
        dz: 2x1 array[float]
            The ode evaluated at the given inputs.
        """

        inertia = self.m * self.l ** 2
        dz = np.zeros((2, 1))
        dz[0] = self.g / self.l * np.sin(
            state[1]) + action / inertia - self.b / inertia * state[0]
        dz[1] = state[0]

        return dz 
开发者ID:befelix,项目名称:safe-exploration,代码行数:28,代码来源:environments.py


注:本文中的scipy.integrate.ode方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。