Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.python > #69483
| Path | csiph.com!newsfeed.hal-mli.net!feeder3.hal-mli.net!newsfeed.hal-mli.net!feeder1.hal-mli.net!newsfeed.xs4all.nl!newsfeed2a.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail |
|---|---|
| Return-Path | <rosuav@gmail.com> |
| X-Original-To | python-list@python.org |
| Delivered-To | python-list@mail.python.org |
| X-Spam-Status | OK 0.007 |
| X-Spam-Evidence | '*H*': 0.99; '*S*': 0.00; 'say,': 0.05; 'affected': 0.07; 'made.': 0.07; 'subject:query': 0.07; 'suppose': 0.07; 'variables': 0.07; 'here?': 0.09; 'oh,': 0.09; 'second.': 0.09; 'toss': 0.09; 'yeah,': 0.09; 'cc:addr:python-list': 0.11; '(within': 0.16; ':-p': 0.16; 'assignment?': 0.16; 'assignments,': 0.16; 'averaging': 0.16; 'bullet': 0.16; 'corresponds': 0.16; 'encodings': 0.16; 'enough.': 0.16; 'equation': 0.16; 'equations': 0.16; 'formula': 0.16; 'from:addr:rosuav': 0.16; 'from:name:chris angelico': 0.16; "he'll": 0.16; 'linear,': 0.16; 'measured': 0.16; 'motion.': 0.16; 'rough': 0.16; 'seconds.': 0.16; 'statements,': 0.16; 'suggested,': 0.16; 'variables,': 0.16; 'zero,': 0.16; 'wrote:': 0.18; 'bit': 0.19; 'written': 0.21; '>>>': 0.22; 'import': 0.22; 'comfortable': 0.22; 'separate': 0.22; 'cc:addr:python.org': 0.22; 'this?': 0.23; 'certainly': 0.24; 'integrate': 0.24; 'subject:Code': 0.24; 'fine': 0.24; 'initial': 0.24; 'looks': 0.24; 'question': 0.24; 'cc:2**0': 0.24; "i've": 0.25; '(see': 0.26; 'right.': 0.26; 'train': 0.26; 'post': 0.26; 'subject:/': 0.26; 'header:In-Reply-To:1': 0.27; 'appreciated.': 0.29; 'chris': 0.29; 'resolution': 0.29; "doesn't": 0.30; 'compared': 0.30; 'needed.': 0.30; 'message-id:@mail.gmail.com': 0.30; "i'm": 0.30; '(which': 0.31; 'code': 0.31; 'easier': 0.31; 'usually': 0.31; 'calculated': 0.31; "d'aprano": 0.31; 'decimal': 0.31; 'second,': 0.31; 'steven': 0.31; 'them?': 0.31; 'probably': 0.32; 'know.': 0.32; "we're": 0.32; 'quite': 0.32; 'becomes': 0.33; 'guess': 0.33; 'comment': 0.34; 'there,': 0.34; "can't": 0.35; 'advice': 0.35; 'anywhere': 0.35; 'except': 0.35; '(2)': 0.35; 'good.': 0.35; 'hundreds': 0.35; 'but': 0.35; 'received:google.com': 0.35; 'really': 0.36; 'sequence': 0.36; 'next': 0.36; 'should': 0.36; 'seconds': 0.37; 'too': 0.37; 'operating': 0.37; 'two': 0.37; '(3)': 0.38; 'pm,': 0.38; 'track': 0.38; 'previous': 0.38; 'sure': 0.39; 'enough': 0.39; 'either': 0.39; 'called': 0.40; 'units': 0.60; 'break': 0.61; 'simple': 0.61; 'first': 0.61; 'back': 0.62; 'high': 0.63; 'our': 0.64; 'more': 0.64; 'school': 0.64; 'total': 0.65; 'different': 0.65; 'great': 0.65; 'distance': 0.65; 'teach': 0.65; 'of:': 0.68; 'sound': 0.68; 'increase': 0.74; 'attention': 0.75; '(ie': 0.84; 'asked.': 0.84; 'complex,': 0.84; 'distances': 0.84; 'distinctive': 0.84; 'effectively,': 0.84; 'fonts': 0.84; 'heh.': 0.84; 'here)': 0.84; 'me!': 0.84; 'meters': 0.84; 'naughty': 0.84; 'remembering': 0.84; 'increases': 0.91; 'stretch': 0.91; 'to:none': 0.92; 'average': 0.93; 'have.': 0.93; 'comfort': 0.96 |
| DKIM-Signature | v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=mime-version:in-reply-to:references:date:message-id:subject:from:cc :content-type:content-transfer-encoding; bh=vppIfkUUvDuQoM/nHfco+BOdfIckolFuyy3jCVrF+zc=; b=JDiEmOlqTwIuLFsRGyT5bCD8vpX+JJNUvhZrtoBItvsi4OqEA/grIp5pqK6z4KmhRJ GxFBtSRxU89MeBVa983GvyfUFEEIMkB3Z8MW9PlObSHNHJ4t0/BqGn4vdsm4H7xhjP9E qQizMZeoTC6s8Nt/4rRSDaYjz6Thzx/MlB6kiCgq7wiU+JenrogJVAKMmRSNnZIu0QzF FTPKQDspy8XIDN/6QO55XPxF4Z7SVz+fmSRbC2h9b7KyZJXg0fURoZvDuwHvQE1htXMo KGK50QXA7vOZ23fzVT8tAOXe5efoGwODNd0MJGczngtYD3KcWTaoLcgp5ghqexRLimMo pxVg== |
| MIME-Version | 1.0 |
| X-Received | by 10.68.200.74 with SMTP id jq10mr90292pbc.169.1396337752495; Tue, 01 Apr 2014 00:35:52 -0700 (PDT) |
| In-Reply-To | <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> |
| References | <mailman.8744.1396276875.18130.python-list@python.org> <533a3fd8$0$2909$c3e8da3$76491128@news.astraweb.com> <mailman.8767.1396328509.18130.python-list@python.org> <533a68c3$0$2909$c3e8da3$76491128@news.astraweb.com> |
| Date | Tue, 1 Apr 2014 18:35:52 +1100 |
| Subject | Re: Code style query: multiple assignments in if/elif tree |
| From | Chris Angelico <rosuav@gmail.com> |
| Cc | "python-list@python.org" <python-list@python.org> |
| Content-Type | text/plain; charset=UTF-8 |
| 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 <python-list.python.org> |
| List-Unsubscribe | <https://mail.python.org/mailman/options/python-list>, <mailto:python-list-request@python.org?subject=unsubscribe> |
| List-Archive | <http://mail.python.org/pipermail/python-list/> |
| List-Post | <mailto:python-list@python.org> |
| List-Help | <mailto:python-list-request@python.org?subject=help> |
| List-Subscribe | <https://mail.python.org/mailman/listinfo/python-list>, <mailto:python-list-request@python.org?subject=subscribe> |
| Newsgroups | comp.lang.python |
| Message-ID | <mailman.8778.1396337762.18130.python-list@python.org> (permalink) |
| Lines | 119 |
| NNTP-Posting-Host | 2001:888:2000:d::a6 |
| X-Trace | 1396337762 news.xs4all.nl 2835 [2001:888:2000:d::a6]:37524 |
| X-Complaints-To | abuse@xs4all.nl |
| Xref | csiph.com comp.lang.python:69483 |
Show key headers only | View raw
On Tue, Apr 1, 2014 at 6:20 PM, Steven D'Aprano <steve@pearwood.info> wrote: > On Tue, 01 Apr 2014 16:01:40 +1100, Chris Angelico 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... > > Hmmm. A 1-second resolution doesn't really sound too great to me. > > Suppose the deceleration increases linearly from 0 to 0.85 m/s over two > seconds. Averaging it in the way you suggested, we get a total distance > of: > > 2*u - 0.5125 > > (see my previous post for details) where u is measured in metres per > second. Multiply by seconds to get the units right. For a Japanese bullet > train where u = 320 km/hr that corresponds to > > py> 2*88.888889 - 0.5125 > 177.26527800000002 > > metres. > > Now let's do it properly! Given our assumption that the deceleration is > linear, the jerk will be constant: > > j = Δa/Δt > = (0.85 - 0)/2 > = 0.425 m/s^3 > > Let's start integrating! > > py> from sympy import integrate > py> from sympy.abc import t > py> j = '0.425' > py> a = integrate(j, t) > py> v = 88.888889 - integrate(a, t) > py> s = integrate(v, (t, 0, 2)) > py> s > 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! > Of course, if the equation for acceleration was more complex, the > approximation may not be anywhere near as good. And that's the bit I can't know. I've added a comment to the code and will toss it back to my brother - hopefully he'll either know the answer or know where to look it up / who to ask. > [...] >>> This becomes a simple question for the four standard equations of >>> motion: >>> >>> (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. > > They're *standard* equations of motion. Weren't you paying attention > through the, oh, three years of high school where they teach this? :-P They're certainly the standard equations, but I learned that: d = v₀t + at²/2 which is the same as you had, except for the names: d for distance, v₀ (V zero, that's a subscript zero if encodings or fonts kill you here) for initial velocity (ie velocity at time zero - vₜ (that's a subscript t, U+209C, but it isn't working in this font) is velocity at time t, which is v₀+at), and a and t are the same as you have. > s = displacement (distance) > t = time > u = initial velocity > v = final velocity > a = acceleration I have to say, the one-letter variables are a lot easier to work with. Guess I learned them the hard way, heh. Although remembering that v is velocity is easier than remembering which of u and v is initial and which is final. >> Fair enough. :) That's why I asked. Is it naughty enough to break into >> two statements, or is it better to combine it into a single multiple >> assignment? > > Since they are unrelated assignments, of two different variables, they > should be written as two separate assignments, not one using sequence > unpacking. Change made. Yeah, that looks a bit cleaner. Although I would prefer a simple formula to what I have there, and I'm still not perfectly sure it's accurate. Advice appreciated. :) ChrisA
Back to comp.lang.python | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 01:33 +1100
Re: Code style query: multiple assignments in if/elif tree Marko Rauhamaa <marko@pacujo.net> - 2014-03-31 18:40 +0300
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:03 +1100
Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 09:20 -0700
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 03:29 +1100
Re: Code style query: multiple assignments in if/elif tree "Rhodri James" <rhodri@wildebst.org.uk> - 2014-03-31 21:31 +0100
Re: Code style query: multiple assignments in if/elif tree Ned Batchelder <ned@nedbatchelder.com> - 2014-03-31 17:42 -0400
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 09:50 +1100
Re: Code style query: multiple assignments in if/elif tree Ben Finney <ben+python@benfinney.id.au> - 2014-04-01 09:57 +1100
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 10:12 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve+comp.lang.python@pearwood.info> - 2014-04-01 00:57 +0000
Re: Code style query: multiple assignments in if/elif tree Ethan Furman <ethan@stoneleaf.us> - 2014-03-31 17:30 -0700
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 04:26 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 16:01 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:20 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:35 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 08:07 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:12 +1100
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:18 -0600
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:24 -0600
Re: Code style query: multiple assignments in if/elif tree Rustom Mody <rustompmody@gmail.com> - 2014-03-31 22:45 -0700
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:05 -0400
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:28 -0600
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:13 -0600
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 02:24 -0400
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 00:39 -0600
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 17:55 +1100
Re: Code style query: multiple assignments in if/elif tree Steven D'Aprano <steve@pearwood.info> - 2014-04-01 07:29 +0000
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:49 +1100
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:29 -0600
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 19:56 +1100
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:21 -0400
Re: Code style query: multiple assignments in if/elif tree Chris Angelico <rosuav@gmail.com> - 2014-04-01 18:26 +1100
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:34 -0400
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:39 -0400
Re: Code style query: multiple assignments in if/elif tree David Hutto <dwightdhutto@gmail.com> - 2014-04-01 03:46 -0400
Re: Code style query: multiple assignments in if/elif tree Ian Kelly <ian.g.kelly@gmail.com> - 2014-04-01 02:55 -0600
csiph-web