我如何应用速度和加速度以匹配数学公式的结果
因此,我有一个初始速度iv
最终速度fv
(始终为0)时间t
和加速变量a
a
/code>
我使用这些变量来计算最终距离fd
注意:此处使用的语言是Kotlin
注意:用于计算fd
和A
的公式是我想出的不是
var iv = 10.0 // initial velocity
var fv = 0.0 // final velocity
var t = 8.0 // time
var a = ((fv - iv)/t) // acceleration
var fd: Double = ((iv*t) + (a/2.0*Math.pow(t,2.0)))
我想到的结果:fd = 40.0
当我尝试按照我尝试将其应用于代码的方式进行建模时。
var d = 0.0 // current distance traveled
var i = 0 // current time elapsed
while (i < t) {
d += v
v += a
i++
}
我最终得到d = 45.0
的结果,d
在结尾应等于fd
。
在将速度和加速度应用于速度上,我做错了什么,以使我的结果与数学公式所表明的结果有所不同?
So I have an initial velocity iv
a final velocity fv
(that is always 0) a time t
and an acceleration variable a
I use these variables to calculate final distance fd
Note: language used here is Kotlin
Note: Formula used for calculating fd
and a
are not something I came up with
var iv = 10.0 // initial velocity
var fv = 0.0 // final velocity
var t = 8.0 // time
var a = ((fv - iv)/t) // acceleration
var fd: Double = ((iv*t) + (a/2.0*Math.pow(t,2.0)))
I get the result that fd = 40.0
when I try to model this the way I would try to apply it in code.
var d = 0.0 // current distance traveled
var i = 0 // current time elapsed
while (i < t) {
d += v
v += a
i++
}
I end up with the result of d = 45.0
when d
should equal fd
at the end.
what am I doing wrong in applying velocity and acceleration to velocity so that my results differ from what the mathematical formulas show they should be?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
不用担心“公式” - 考虑物理学。
如果您曾经研究过微积分和物理学,那么您就会知道:
如果您足够了解微积分,则可以两次集成加速的方程,以使距离的距离作为时间的函数:
您可以计算常数:
替换:
您还可以计算计算数字回答。这就是您与Kotlin所做的。
如果您知道最初的条件,
可以在这样的时间增量DT结束时计算价值:
看起来您正在假设加速度在您感兴趣的整个时间内都是恒定的。
您不会说您是什么单位使用。我将假设度量单位:以米为单位,时间为几秒钟。
您从10 m/sec的初始速度下降到在8秒内的最终速度为0 m/秒。这意味着-1.25 m/sec^2的恒定加速度。
您应该能够将值替换为这些方程式并获得所需的答案。
在尝试编码它们之前,请手动进行计算。
Don't worry about "formulas" - think about the physics.
If you have ever studied calculus and physics you know that:
If you know calculus well enough you can integrate the equation for acceleration twice to get the distance traveled as a function of time:
You can calculate the constants:
Substituting:
You can also calculate the answer numerically. That's what you're doing with Kotlin.
If you know the initial conditions
you can calculate the value at the end of a time increment dt like this:
Looks like you are assuming that acceleration is constant throughout the time you're interested in.
You don't say what units you're using. I'll assume metric units: length in meters and time in seconds.
You decelerate from an initial velocity of 10 m/sec to a final velocity of 0 m/second over 8 seconds. That means a constant acceleration of -1.25 m/sec^2.
You should be able to substitute values into these equations and get the answers you need.
Do the calculations by hand before you try to code them.