Path: csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!goblin1!goblin.stu.neva.ru!uio.no!news.tele.dk!news.tele.dk!small.news.tele.dk!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.030 X-Spam-Evidence: '*H*': 0.94; '*S*': 0.00; 'charset:iso-8859-7': 0.04; 'subject:query': 0.07; 'integration,': 0.09; 'linear': 0.09; 'method,': 0.09; '0.2': 0.16; 'averaging': 0.16; 'formula': 0.16; 'measured': 0.16; 'rough': 0.16; 'seconds,': 0.16; 'wrote:': 0.18; 'error': 0.23; 'stopping': 0.24; 'subject:Code': 0.24; 'fine': 0.24; 'train': 0.26; 'second': 0.26; 'subject:/': 0.26; 'header :In-Reply-To:1': 0.27; 'chris': 0.29; 'am,': 0.29; 'compared': 0.30; 'message-id:@mail.gmail.com': 0.30; 'usually': 0.31; 'calculated': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'steven': 0.31; 'them?': 0.31; 'though.': 0.31; "we're": 0.32; 'problem.': 0.35; 'hundreds': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'seconds': 0.37; 'to:addr:python-list': 0.38; 'pm,': 0.38; 'track': 0.38; 'does': 0.39; 'moving': 0.39; 'to:addr:python.org': 0.39; 'either': 0.39; 'first': 0.61; 'maximum': 0.63; 'different': 0.65; 'distance': 0.65; 'different.': 0.84; 'distances': 0.84; 'effectively,': 0.84; 'me!': 0.84; 'meters': 0.84; 'average': 0.93 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:content-transfer-encoding; bh=01bAW/6ABlknSCdWCQU6zrHmKuCSDTOLES+BgVD20PE=; b=S1ZCzmBxZLKxh9Avwrawq6MxYR+YF6tE7Ja7hRbvuYwaHZfXtVdfH8eZP7n6xgiii4 qM+6rLv9mHwkpGijqi14VucHEKga84krknqRz/bQ3oEZ38BnvShkV1gYIbFocIx6wBXc 8DTk5YGUeLbIYUgWRlSArEv1QYBifhwSDJmWlg0WTcP11fX7r3RGZK0QBnKV7V3RytmU Rx1FZyZ6hB62eL8pNFwgBbigaFRgPrwAUrUzUomVRsmU2QHYPjXaY7vo8mfxvraGm9tm iZlucP6ESk6C9hlVGs68BXfxNNH/c3jKUrDodsH93ZgHcQ0FVEu5/DW8oDvCqi1MDJiN YIMw== X-Received: by 10.68.135.195 with SMTP id pu3mr30148014pbb.70.1396340346990; Tue, 01 Apr 2014 01:19:06 -0700 (PDT) MIME-Version: 1.0 In-Reply-To: References: <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> From: Ian Kelly Date: Tue, 1 Apr 2014 02:18:26 -0600 Subject: Re: Code style query: multiple assignments in if/elif tree To: Python Content-Type: text/plain; charset=ISO-8859-7 Content-Transfer-Encoding: quoted-printable 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: 40 NNTP-Posting-Host: 2001:888:2000:d::a6 X-Trace: 1396340355 news.xs4all.nl 2902 [2001:888:2000:d::a6]:60112 X-Complaints-To: abuse@xs4all.nl Xref: csiph.com comp.lang.python:69489 On Tue, Apr 1, 2014 at 1:35 AM, Chris Angelico wrote: > On Tue, Apr 1, 2014 at 6:20 PM, Steven D'Aprano wro= te: >> 177.211111333333 >> >> compared to 177.26527800000002 calculated the rough way. That's not bad, >> only about 5cm off! Effectively, your rough calculation was accurate to >> one decimal place. > > 5cm when we're dealing with track distances measured in meters and > usually hundreds of them? Sounds fine to me! Erm, that's just the accumulated error over the first 2 seconds, though. A train moving at 88 m/s and decelerating at a maximum of 0.85 m/s^2 is not going to stop in just 177 meters. After the first 2 seconds, the model is the same using either method, but the velocity after 2 seconds is different. Using the linear deceleration integration, we get: a(t) =3D {-0.425t, t <=3D 2; -0.85, t > 2} v(t) =3D {v0 - 0.2125t^2, t <=3D 2; v0 - 0.85 - 0.85t, t > 2} Giving v(2s) =3D v0 - 0.85 m/s Using the averaging method, we get v(2s) =3D v0 - 0.2 - 0.425 =3D v0 - 0.62= 5 m/s For a difference of 0.225 m/s. Using Steven's formula (4), the additional difference in stopping distance is thus: =C4s =3D ((0 - (88.888889 - 0.625)^2) - (0 - (88.888889 - 0.85)^2)) / -1.7 =3D 23.33 m The reason the velocity is different after 2 seconds is because the linear deceleration does not match the constraints of the problem. The average deceleration for the first second is not 0.2 m/s, and the average deceleration for the second second is not 0.425 m/s.