栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

如何在Python中使用dorpi5或dop853

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

如何在Python中使用dorpi5或dop853

您可以使用或作为其参数

set_integrator
ode
类上调用方法。
'dopri5'``'dop853'

这是一个例子:

import numpy as npimport matplotlib.pyplot as pltfrom scipy.integrate import odedef fun(t, z, omega):    """    Right hand side of the differential equations      dx/dt = -omega * y      dy/dt = omega * x    """    x, y = z    f = [-omega*y, omega*x]    return f# Create an `ode` instance to solve the system of differential# equations defined by `fun`, and set the solver method to 'dop853'.solver = ode(fun)solver.set_integrator('dop853')# Give the value of omega to the solver. This is passed to# `fun` when the solver calls it.omega = 2 * np.pisolver.set_f_params(omega)# Set the initial value z(0) = z0.t0 = 0.0z0 = [1, -0.25]solver.set_initial_value(z0, t0)# Create the array `t` of time values at which to compute# the solution, and create an array to hold the solution.# Put the initial value in the solution array.t1 = 2.5N = 75t = np.linspace(t0, t1, N)sol = np.empty((N, 2))sol[0] = z0# Repeatedly call the `integrate` method to advance the# solution to time t[k], and save the solution in sol[k].k = 1while solver.successful() and solver.t < t1:    solver.integrate(t[k])    sol[k] = solver.y    k += 1# Plot the solution...plt.plot(t, sol[:,0], label='x')plt.plot(t, sol[:,1], label='y')plt.xlabel('t')plt.grid(True)plt.legend()plt.show()

这将生成以下图:



转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/648466.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号