从位移图求振幅

2024-10-02 02:24:45 发布

您现在位置:Python中文网/ 问答频道 /正文

我一直在尝试对强迫驱动振荡器的问题建模,并使用scipy.integrate模块odeint绘制各种参数值的位移与时间周期图

这是密码

%matplotlib notebook
import numpy as np
import pandas as pd
import matplotlib.pyplot as plt
from scipy import integrate
import ipywidgets as ipw
"""
parameters involved
I=moment of inertia of load(cylinder or disc) connected
b=damping constant
s=tortional constant of wire
f0=max driving torque
w=frequency of driving torque 
x=angular deflection of cylinder(taken in place of theta)
x"=d2x/dt2(xddot)
x'=dx/dt(xdot)
equation
I(x")+bx'+sx=f0cos(wt)
x"=(f0/I)cos(wt)-(b/I)x'-(s/I)x
x"=F0cos(wt)-Bx'-Sx

"""
def ode(X, t, B, S, F0, w):
    """
    Free Harmonic Oscillator ODE
    """
    x, xdot = X
    xddot = -B*xdot -S*x + F0 * np.cos(w * t)
    return [xdot, xddot]

def update(B = 0.79, S = 3.21, F0 = 1., w= 1.76):
    """
    Update function.
    """
    X0 = np.zeros(2)
    sol = integrate.odeint(ode, X0, t, args = (B, S, F0, w))
    line0.set_ydata(sol[:, 0])

Nt = 1000
t = np.linspace(0., 100., Nt)
#t=np.exp(np.linspace(0.,100.,Nt))
dummy = np.zeros_like(t)
fig = plt.figure()
line0, = plt.plot(t, dummy, label = "position")
plt.grid()
plt.ylim(-1., 1.)
plt.xlabel("Time, $t$")
plt.ylabel("Amplitude, $a$")
plt.legend()

ipw.interact(update, B = (0., 1., 0.01),
             S = (0, 10, 0.01),
             F0 = (0, 2., 0.05), w = (0,2*np.pi*1,2*np.pi*0.01));

我无法理解如何从这个给定的代码中绘制振幅与频率以及相位与频率的关系图。请帮忙


Tags: ofimportmatplotlibasnp绘制pltscipy

热门问题