Verlet Integration+加速度公式

Verlet积分是一种常用于解决牛顿动力学方程的数值积分方法,尤其在物理学和计算机图形学中。它不需要直接计算加速度的变化(jerk),从而减少了误差至O(Δt^4)。通过使用前一时刻和当前时刻的位置来预测下一时刻的位置,可以避免存储速度信息。在需要速度信息的情况下,可以通过Stormer-Verlet方法以较低精度O(Δt^2)计算。这种方法在节省计算资源的同时,保持了较高的模拟精度。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

https://www.algorithm-archive.org/contents/verlet_integration/verlet_integration.html
https://www.techbrood.com/zh/news/webgl/%E7%B2%92%E5%AD%90%E8%BF%90%E5%8A%A8%E6%A8%A1%E6%8B%9F—verlet%E7%A7%AF%E5%88%86%E7%AE%97%E6%B3%95%E7%AE%80%E4%BB%8B.html
http://datagenetics.com/blog/july22018/index.html
http://www.myliushu.com/4922.html 加速度公式
在这里插入图片描述

Verlet Integration
Verlet integration is essentially a solution to the kinematic equation for the motion of any object,
在这里插入图片描述
where x is the position, v is the velocity, a is the acceleration, b is the often forgotten jerk term, and t is time. This equation is a central equation to almost every Newtonian physics solver and brings up a class of algorithms known as force integrators. One of the first force integrators to work with is Verlet Integration.

So, let’s say we want to solve for the next timestep in x . To a close approximation (actually performing a Taylor Series Expansion about x(t±Δt) ) , that might look like this:

This means that if we need to find the next x , we need the current x , v , a , etc. However, because few people calculate the jerk term, our error is typically O(Δt3) .

that said, we can calculate x with less knowledge and higher accuracy if we play a trick!
let us say we want to calculate x of the previous timestep.
again, to a close approximation, that might look like this:
在这里插入图片描述

now, we have two equations to solve for two different timesteps in x, one of which we already have.
if we add the two equations together and solve for x(t+Δt) , we find that
在这里插入图片描述
so, this means we can find our next x simply by knowing our current x, the x before that, and the acceleration!
no velocity necessary!
in addition, this drops the error to O(Δt4) . which is great!
here is what it looks like in code:

function verlet(pos::Float64, acc::Float64, dt::Float64)
    prev_pos = pos
    time = 0.0

    while (pos > 0)
        time += dt
        temp_pos = pos
        pos = pos * 2 - prev_pos + acc * dt * dt
        prev_pos = temp_pos
    end

    return time
end

now, obviously this poses a problem;
what if we want to calculate a term that requires velocity, like the kinetic energy, 0.5mv^2?动能?
in this case, we certainly can not get rid of the velocity!
well, we can find the velocity to O(Δt2) accuracy by using the Stormer-Verlet method, which is the same as before, but we calculate velocity like so
在这里插入图片描述
note that the 2 in the denominator appears because we are going over 2 timestep.
it is essentially solving v = Δx/Δt.
in addition, we can calculate the velocity of the next timestep like so:

在这里插入图片描述

However, the error for this is O(Δt) , which is quite poor, but it gets the job done in a pinch. Here’s what it looks like in code:

function stormer_verlet(pos::Float64, acc::Float64, dt::Float64)
    prev_pos = pos
    time = 0.0
    vel = 0.0

    while (pos > 0.0)
        time += dt
        temp_pos = pos
        pos = pos * 2 - prev_pos + acc * dt * dt
        prev_pos = temp_pos

        # Because acceleration is constant, velocity is straightforward
        vel += acc * dt
    end

    return time, vel
end
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值