24小时热门版块排行榜    

查看: 1100  |  回复: 0

jackyma

新虫 (小有名气)

[求助] 请教一个关于重力系统下质点球平抛落地反弹的运动轨迹数学模型建立的问题

有一个简单的物理问题想用Python 来实现,
问题:
有一质量为1kg的质点,在时刻t=0【s】时从高度0.5米的位置水平以1.0m/s的速度水平弹出(考虑重力向下),
与高度为0m,最大静止摩擦系数0.5,动摩擦系数为0.1且不会变形的平面接触(球与平面的反弹系数为0.3)后反弹,并反复落下反弹运动直至静止于平面之上,模拟出t=T[s]为止球的运动轨迹,间隔相同时间(Δ t)输出球的位置坐标。
T 和Δ t任意选择。

这个问题应该属于球体平抛反弹的轨迹模拟,网络上有类似问题建模。

在http://www.matlabsky.com/thread-13700-1-1.html里有考虑空气摩擦力的微分方程公式,但是我的问题是不需考虑空气摩擦,只要考虑地面摩擦力,有没有数学建模高手给指点一下。我这个模型要如何实现?

下面是我参考那个Matlab的帖子,写的一个python版,
可是问题是python的scipy的odeint函数没有办法判断着陆点y=0的时刻,也就意味着质点落地后反弹的运动轨迹无法模拟。
另外觉得那个帖子里的微分方程有点问题,请知道的大侠指点迷津!

再此先做感谢!
CODE:
import numpy as np
from scipy.integrate import odeint
import matplotlib.pyplot as plt

def fun(w, t, p):
    """Define the  equation for throw
    Arguments:
        w: vector of the state variables:
            w = [x,y, vx, vy]
        t: time
        p: vector of the parameters:
            p = [m, mu, g, e]
    :return: f
    """
    x, y, vx, vy = w
    m, mu, g, k = p

    # create f = (x',y', vx', vy'):

    f = [vx,                          # x' = dx/dt = vx
         -mu * vx / m,                 # vx' = dvx/dt = -mu * vx / m
         vy,                           # y' = dy/dt = vy
         -mu * vy / m - g,             # vy' = dvy/dt = -mu * vy /m - g
         ]
    return f

def main():
    # Parameter values
    # Masses
    m = 1
    # Friction coefficients
    mu = 0.1
    # Acceleration
    g = 9.8
    # Restitution coefficients
    k = 0.3

    # Initial conditions
    x = 0
    y = 0.5
    vx = 1
    vy = 0


    # ODE solver parameters
    abserr = 1.0e-8
    relerr = 1.0e-6
    # stop time for movement simulation
    stoptime = 0.7
    # delta time
    numpoints = 30

    # Create the time samples for the output of the ODE solver.
    t = [stoptime * float(i) / (numpoints - 1) for i in range(numpoints)]

    # Pack up the parameters and initial conditions:
    p = [m, mu, g, k]
    w0 = [x, y, vx, vy]

    # Call the ODE solver
    wsol = odeint(fun, w0, t, args=(p,), atol=abserr, rtol=relerr)

    with open('ball_movement.dat', 'w') as fi:
        # print and save the solution.
        for t1, w1 in zip(t, wsol):
            if w1[2] >= 0:
                print >> fi, t1, w1[0], w1[2]
            else:
                # print >> fi, "The ball is landing to floor!"

                x = w1[0]
                y = w1[2]
                vx = w1[1]
                vy = w1[3]
    # wsol = odeint(fun, w0, )

    # Plot the solution that was generated

    from numpy import loadtxt
    from pylab import figure, plot, xlabel, grid, hold, legend, title, savefig
    from matplotlib.font_manager import FontProperties

    t, x, y = loadtxt('ball_movement.dat', unpack=True)

    figure(1, figsize=(6, 4.5))

    xlabel('t')
    grid(True)
    hold(True)
    lw = 1

    plot(x, y, 'b', linewidth=lw)
    #plot(t, y, 'g', linewidth=lw)

    legend((r'$x$', r'$y$'), prop=FontProperties(size=16))
    title('Ball Mass System')
    savefig('ball_movement.png', dpi=100)


if __name__ == "__main__":
    main()

回复此楼
已阅   回复此楼   关注TA 给TA发消息 送TA红花 TA的回帖
相关版块跳转 我要订阅楼主 jackyma 的主题更新
信息提示
请填处理意见