From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on inbox.vuxu.org X-Spam-Level: X-Spam-Status: No, score=-1.0 required=5.0 tests=MAILING_LIST_MULTI, RCVD_IN_DNSWL_NONE autolearn=ham autolearn_force=no version=3.4.2 Received: (qmail 28297 invoked from network); 24 Apr 2020 17:32:44 -0000 Received: from ns1.primenet.com.au (HELO primenet.com.au) (203.24.36.2) by inbox.vuxu.org with UTF8ESMTPZ; 24 Apr 2020 17:32:44 -0000 Received: (qmail 13822 invoked by alias); 24 Apr 2020 17:32:33 -0000 Mailing-List: contact zsh-workers-help@zsh.org; run by ezmlm Precedence: bulk X-No-Archive: yes List-Id: Zsh Workers List List-Post: List-Help: List-Unsubscribe: X-Seq: 45716 Received: (qmail 23688 invoked by uid 1010); 24 Apr 2020 17:32:33 -0000 X-Qmail-Scanner-Diagnostics: from ciao.gmane.io by f.primenet.com.au (envelope-from , uid 7791) with qmail-scanner-2.11 (clamdscan: 0.102.2/25786. spamassassin: 3.4.4. Clear:RC:0(159.69.161.202):SA:0(-1.6/5.0):. Processed in 3.496832 secs); 24 Apr 2020 17:32:33 -0000 X-Envelope-From: gcszd-zsh-workers@m.gmane-mx.org X-Qmail-Scanner-Mime-Attachments: | X-Qmail-Scanner-Zip-Files: | Received-SPF: pass (ns1.primenet.com.au: SPF record at m.gmane-mx.org designates 159.69.161.202 as permitted sender) X-Injected-Via-Gmane: http://gmane.org/ Mail-Followup-To: zsh-workers@zsh.org To: zsh-workers@zsh.org From: Emanuel Berg Subject: zsh functions, bicycle tire and gas law (PV = nRT) Date: Fri, 24 Apr 2020 19:31:47 +0200 Message-ID: <87v9loiyd8.fsf@ebih.ebihd> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/26.1 (gnu/linux) Cancel-Lock: sha1:9sb9BoI7j81wJha2RTLbWe4DBsM= Mail-Copies-To: never Hello guys, what do you think of this? After the code are some notes I wrote on IRC while I wrote it. There are some general zsh questions there, as well. TIA #! /bin/zsh # # this file: # http://user.it.uu.se/~embe8573/conf/.zsh/air # https://dataswamp.org/~incal/conf/.zsh/air # # Let's model an inflated bicycle tube/tire in the form # of a torus, as in this figure: [1] # # We use the ISO ETRTO notation for bicycle tire sizes. # For example, a typical "twenty-niner" MTB tire is # a 54-622 tire, where 54 is the tire width and 622 the # rim Bead Seat Diameter. See [2]. We denote these (w) # and (b). # # Comparing [1] and [2], we understand that # # r = w/2 # # and # # R = b/2 + r # # R = b/2 + w/2 # # with the volume of a torus being # # V = 2 * pi^2 * R * r^2 # # V = 2 * pi^2 * (b/2 + w/2) * (w/2)^2 # # V = pi^2w(b+w^2)/4 bike-tire-volume () { local width=$1 local bsd=$2 local pi=3.1415 local vmm=$(( $pi**2 * $width * ($bsd + $width**2) / 4 )) local vcm=$(units -t "$vmm mm3" cm3) local rvcm=$(( rint($vcm) )) printf "V = %d cm3\n" $rvcm return $rvcm } # Assuming air behaves like a gas at the intended # preassure, we use the ideal gas law, PV = nRT. We just # have to change the units a bit and then compute. bike-tire-air () { local width=$1 local bsd=$2 local psi=$3 bike-tire-volume $width $bsd local vcm=$? local p=$(units -t "$psi psi" atm) local v=$(units -t "$vcm cm3" liters) local t=290.45 # [*] local r=0.0821 local n=$(( ($p * $v) / ($r * $t) )) printf "%f moles of air gas\n" $n # [*] 290.45K = 17.3C, the average temperature in Liège in July, # the hottest month of the year. Seems like good for cycling. # } # Example invocations: # $ bike-tire-volume 57 622 # $ V = 544 cm3 # $ bike-tire-air 57 622 65 # $ V = 544 cm3 # $ 0.100902 moles of air gas # [1] https://www.mathsisfun.com/geometry/torus.html # # [2] https://dataswamp.org/~incal/bike/tire-size.png IRC notes: if my calculations are correct, the volume of/in an inflated bicycle tube/tire is pi^2w(b+w^2)/4 where b is the rim BSD and w the tire width if one has the volume, as well as the preassure (written on the tire), one can use the ideal gas law (or general gas equation) which is PV = nRT, solve n to get the number of moles! in the cycling press they like to say that the width of the tire isn't what determines the level of comfort, it is the quality of the tire and the amount of air in it. the scientific definition of quality is TPI (threads per inch) but if that is understood in the mundane sense and can be ignored it means they are wrong, the amount of air is actually determined by two components, one of which is derived from the tire width, and both of which are actually readily available, stated on the tire! (preassure in PSI/kPa/bar tho, in PV = nRT in atm; volume in liter) ... _I think_! I'm not so strong in science ... it seems you can't do ^ in zsh, maybe that's XOR, ** seems to work tho: $pi**2 * $w * ($b + $w**2) / 4 how is it with shell programming, is it OK to return data or should you just return if the program successfully finished or not? units(1) seem to have special rules for temperature, $ units -t "tempC(17.3)" # 290.45 K # +17.3C, the average temperature in Liège in July, the hottest month of the year https://dataswamp.org/~incal/conf/.zsh/air # but I should verify that air really behaves like a gas at the intended preassure before I send it to the snobbish bike magazine and try to own them -- underground experts united http://user.it.uu.se/~embe8573 https://dataswamp.org/~incal