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

在使用scipy.integrate.odeint和python时遇到麻烦

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

在使用scipy.integrate.odeint和python时遇到麻烦

您的代码有几个问题,如果更仔细地阅读文档字符串

odeint
,您可能可以解决大多数问题。

为了帮助您入门,以下是使用求解标量微分方程的简单示例

odeint
。我将尝试使用一个非常简单的方程式,而不是尝试去理解(并可能调试)您的函数。我将用初始条件y(0)=
100求解方程dy / dt = a * y。一旦使本示例生效,就可以进行修改
fun
以解决问题。

import numpy as npfrom scipy.integrate import odeintimport matplotlib.pyplot as pltdef fun(y, t, a):    """Define the right-hand side of equation dy/dt = a*y"""     f = a * y    return f# Initial conditiony0 = 100.0# Times at which the solution is to be computed.t = np.linspace(0, 1, 51)# Parameter value to use in `fun`.a = -2.5# Solve the equation.y = odeint(fun, y0, t, args=(a,))# Plot the solution.  `odeint` is generally used to solve a system# of equations, so it returns an array with shape (len(t), len(y0)).# In this case, len(y0) is 1, so y[:,0] gives us the solution.plt.plot(t, y[:,0])plt.xlabel('t')plt.ylabel('y')plt.show()

这是情节:

odeint
在SciPy
Cookbook
中可以找到使用的更复杂的示例(向下滚动到标有“常微分方程”的项目符号)。



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

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

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