Code style query: multiple assignments in if/elif tree

Ian Kelly ian.g.kelly at gmail.com
Tue Apr 1 02:13:00 EDT 2014


On Mon, Mar 31, 2014 at 11:01 PM, Chris Angelico <rosuav at gmail.com> wrote:
> On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano <steve at pearwood.info> wrote:
>> The scenario you describe has (effectively) infinite rate-of-change-of-
>> acceleration, often called "jerk". (A jerk is a rapid change in
>> acceleration.) Human comfort is (within reasonable limits) more affected
>> by jerk than acceleration. The passengers will feel three quite
>> distinctive jerks, one when the brakes are first applied (which is
>> probably reasonable), then one at 1s, then again at 2s. That's not
>> comfortable by any stretch of the imagination.
>
> It actually is a smooth increase in deceleration, but I'm operating
> the simulator on a 1s period, so it's actually an average across the
> first second, and an average across the next second...

Then your computation is incorrect and will systematically
underestimate the stopping distance.  Assuming for simplicity that the
acceleration actually increases linearly until it reaches maximum,
picture the velocity graph between, say, t=0 and t=1s.  You are
modeling it as a straight line segment.  However, it would actually be
part of a quadratic curve connecting the same points, convex upwards.
The line segment is short-cutting the curve between the two points.
The distance traveled is the integral of the curve, and it is easy to
see that the integral of the line segment is less than the integral of
the actual curve.


>> (1) v = u + at
>> (2) s = 1/2(u + v)t
>> (3) s = ut + 1/2(at^2)
>> (4) v^2 = u^2 + 2as
>>
>> Only (1) and (3) are needed.
>
> Okay, what's u here? Heh.

u is the initial velocity; v is the velocity after accelerating at a for time t.



More information about the Python-list mailing list