python函数参数为数组_为参数数组求解ODE(Python)

*我知道这个问题很简单,但是我想知道在Python中设置这样的for循环的最佳方法.

我已经编写了一个程序来计算和绘制二阶微分方程的解(此代码在下面给出).

我想知道针对f参数数组(因此为f_array)重复此计算的最佳方法.即因此,该图显示了20个数据集,这些数据涉及作为t的函数的解,每个解具有不同的f值.

为任何想法加油.

from pylab import *

from scipy.integrate import odeint

#Arrays.

tmax = 100

t = linspace(0, tmax, 4000)

fmax = 100

f_array = linspace(0.0, fmax, 20)

#Parameters

l = 2.5

w0 = 0.75

f = 5.0

gamma = w0 + 0.05

m = 1.0

alpha = 0.15

beta = 2.5

def rhs(c,t):

c0dot = c[1]

c1dot = -2*l*c[1] - w0*w0*c[0] + (f/m)*cos((gamma)*t)-alpha*c[0] - beta*c[0]*c[0]*c[0]

return [c0dot, c1dot]

init_x = 15.0

init_v = 0.0

init_cond = [init_x,init_v]

ces = odeint(rhs, init_cond, t)

s_no = 1

subplot(s_no,1,1)

xlabel("Time, t")

ylabel("Position, x")

grid('on')

plot(t,ces[:,0],'-b')

title("Position x vs. time t for a Duffing oscillator.")

show()

这是一个曲线图,显示了针对t值数组的f的单个值的此方程的解.我想要一种快速的方法来对f值数组重复此图.

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值