我想将分数(在第一个循环中计算分数)提高到小数幂(第二个循环),但是,我总是得到 1 作为结果。我也想将第二个循环的输出存储在一个数组中。任何想法如何解决这个问题?谢谢!
#
# vector of vertical pressure levels
levs=($(seq 200.0 50.0 900.0))
printf "%s\n" "${levs[@]}"
#
# exponent for dry air
rho=$(bc -l <<<'e(l(0.0819)*0.5)')
echo $rho
#
# calculate fraction of P_surf/P_i from Poisson equation for each vertical pressure level
val3=()
#
for i in "${levs[@]}"
do
echo $i
val3+=($(bc -l <<<"1000.0/$i"))
echo "$val3"
done
printf "%s\n" "${val3[@]}"
#
# raise fraction of P_surf/P_i to the rho power for dry air (#bc <<< "2 ^ 3")
pow=()
#
for j in "${val3[@]}"
do
echo $j
echo $rho
pow+=($(bc <<<"$j^rho"))
#echo $((i*rho))
echo "$pow"
done
#