Calculate from the command line with Spigot
|
Conversion
Spigot supports conversion between numbering systems using various kinds of syntax. The command shown here will work in every case:
echo <valueI> | spigot -b<output_base> ,base <input_base>fd:0'
Figure 4 shows common usage examples.
Calculating Frequency
The example from Listing 2 shows how to deal with variables as exponents. Here you see that the variables are isolated by quotes; the e-12 describes the exponent's remainder. Use the script to calculate the frequency of a resonant circuit using the coil (Inductance , ?H ) and the capacitor (Capacitor , pF ). See Figure 5 for the script's output.
Listing 2
qrgcalc.sh
#!/bin/bash # qrgcalc.sh echo "Resonant circuit calculation, result in MHz" read -p "Inductance in ?H: " L read -p "Capacitor in pF: " C echo "Inductance: $L ?H, Capacitor $C pF" # In the header, correct conversion for ISO units to H and F echo "------------------------------" qrg=$(spigot --rn -d50 "$L"e-6*"$C"e-12 | spigot --rn -d50 '(1/(2pi*sqrt(base10fd:0))/1000000)' --printf %10.3f) echo "Frequency $qrg MHz"
« Previous 1 2 3 4 Next »
Buy this article as PDF
Pages: 4
(incl. VAT)