Zsh Mailing List Archive
Messages sorted by:
Reverse Date,
Date,
Thread,
Author
zsh functions, bicycle tire and gas law (PV = nRT)
- X-seq: zsh-workers 45716
- From: Emanuel Berg <moasenwood@xxxxxxx>
- To: zsh-workers@xxxxxxx
- Subject: zsh functions, bicycle tire and gas law (PV = nRT)
- Date: Fri, 24 Apr 2020 19:31:47 +0200
- Cancel-lock: sha1:9sb9BoI7j81wJha2RTLbWe4DBsM=
- List-help: <mailto:zsh-workers-help@zsh.org>
- List-id: Zsh Workers List <zsh-workers.zsh.org>
- List-post: <mailto:zsh-workers@zsh.org>
- List-unsubscribe: <mailto:zsh-workers-unsubscribe@zsh.org>
- Mail-copies-to: never
- Mail-followup-to: zsh-workers@xxxxxxx
- Mailing-list: contact zsh-workers-help@xxxxxxx; run by ezmlm
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.
# <https://en.climate-data.org/europe/belgium/wallonia/liege-6396>
}
# 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:
<incal> 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
<https://dataswamp.org/~incal/bike/tire-size.png>
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
<incal> 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
<incal> PSI/kPa/bar tho, in PV = nRT in atm; volume in
liter) ... _I think_! I'm not so strong in
science ...
<incal> it seems you can't do ^ in zsh, maybe
that's XOR, ** seems to work tho: $pi**2 * $w *
($b + $w**2) / 4
<incal> how is it with shell programming, is it OK to
return data or should you just return if the
program successfully finished or not?
<incal> 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://en.climate-data.org/europe/belgium/wallonia/liege-6396/>
<incal> 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
Messages sorted by:
Reverse Date,
Date,
Thread,
Author