Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!news.albasani.net!rt.uk.eu.org!newsfeed.xs4all.nl!newsfeed3.news.xs4all.nl!xs4all!newsgate.cistron.nl!newsgate.news.xs4all.nl!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.120 X-Spam-Level: * X-Spam-Evidence: '*H*': 0.78; '*S*': 0.02; 'say,': 0.05; 'affected': 0.07; 'subject:query': 0.07; 'assuming': 0.09; 'curve': 0.09; 'here?': 0.09; 'integral': 0.09; '(within': 0.16; 'curve.': 0.16; 'incorrect': 0.16; 'segment': 0.16; 'wrote:': 0.18; 'comfortable': 0.22; '31,': 0.24; 'stopping': 0.24; 'subject:Code': 0.24; 'initial': 0.24; 'mon,': 0.24; 'subject:/': 0.26; 'header:In- Reply-To:1': 0.27; 'chris': 0.29; 'needed.': 0.30; 'reaches': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; "d'aprano": 0.31; 'second,': 0.31; 'steven': 0.31; 'probably': 0.32; 'quite': 0.32; 'actual': 0.34; '(2)': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'next': 0.36; 'operating': 0.37; 'two': 0.37; '(3)': 0.38; 'to:addr:python- list': 0.38; 'pm,': 0.38; 'to:addr:python.org': 0.39; 'called': 0.40; 'skip:u 10': 0.60; 'easy': 0.60; 'first': 0.61; 'connecting': 0.64; 'more': 0.64; 'distance': 0.65; 'modeling': 0.65; 'between': 0.67; 'mar': 0.68; 'increase': 0.74; 'distinctive': 0.84; 'heh.': 0.84; 'points,': 0.84; 'traveled': 0.84; 'distance.': 0.91; 'increases': 0.91; 'stretch': 0.91; 'average': 0.93; 'comfort': 0.96; 'picture': 0.97 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=TKIyGmRGgacPdlBYY8erW3+QT+ErIDxE2VPYxEAO0JQ=; b=S8xEz7HB0BaOLl83lRXgvfAugyIX4USpoNrgYFjqkBeICtBbgO8QiOoCUY5q2V2JJQ 03711FEab43+Z2uNYdg9AfQIcnyYdWEonI+nhybagGQkuTbeCQW+tqkpvDCPKt6eFS9g XWdDTA7y5Dhgz/oOhU/RuasmsXLVLuSpeHawlx/aKJTolDvl1WxZx0CoU5xgSSUYQ98N c1T+tsaMA6yPWe+amyGocp4aK0rNcHodS/y5tsvz41+xBfZlqoQ1MI/0H9b5rKYIit+X 6ZLMcKwHZL0DMvwokBrZr8TL784tGt31SOwTfFa69F6ygZwXKOpKRQfRe5N82sc1CycJ 8zQw== X-Received: by 10.66.41.106 with SMTP id e10mr13293482pal.109.1396332820771; Mon, 31 Mar 2014 23:13:40 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> From: Ian Kelly Date: Tue, 1 Apr 2014 00:13:00 -0600 Subject: Re: Code style query: multiple assignments in if/elif tree To: Python Content-Type: text/plain; charset=ISO-8859-1 X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.15 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 36 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396332824 news.xs4all.nl 2904 [2001:888:2000:d::a6]:36732 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69473 On Mon, Mar 31, 2014 at 11:01 PM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 3:26 PM, Steven D'Aprano 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.