gpt4 book ai didi

gnuplot - 与 gnuplot 格式说明符 %t 和 %T 不一致?

转载 作者:行者123 更新时间:2023-12-02 02:45:52 25 4
gpt4 key购买 nike

如果您使用 gnuplot 格式说明符 %t%T,您会观察到一些不一致的行为。

### gnuplot format specifiers

Numbers = "94 95 99 100 101"

do for [n in Numbers] {
print gprintf("%3g",n)." = ".gprintf("%t",n)." x 10^".gprintf("%T",n)
}

Mantissa(n) = real(n)/10**floor(log10(n))
Power(n) = floor(log10(n))
do for [n in Numbers] {
print gprintf("%3g",n)." = ",Mantissa(n)," x 10^",Power(n)
}
### end of code

结果:

 94 = 9.400000 x 10^1
95 = 0.950000 x 10^2
99 = 0.990000 x 10^2
100 = 1.000000 x 10^2
101 = 1.010000 x 10^2
94 = 9.4 x 10^1
95 = 9.5 x 10^1
99 = 9.9 x 10^1
100 = 1.0 x 10^2
101 = 1.01 x 10^2

例如,为什么 95 显示为 0.95 x 10^2 而不是 9.5 x 10^1?这背后的原因是什么?

最佳答案

实际上,除了 gprintf("%t",95)gprintf("%T",95) 没有显示预期的尾数和幂,还有公式floor(log10(n)) 有时不显示 n 的正确幂。 (参见此处:gnuplot: how to get correct order of magnitude?)

解决方法建议:以下公式绕过字符串格式化,但至少它们应该始终给出正确的尾数和幂。

Mantissa(n) = real(sprintf("%.15e",n)[1:strstrt(sprintf("%.15e",n),"e")-1])

Power(n) = int(sprintf("%.15e",n)[strstrt(sprintf("%.15e",n),"e")+1:])

从长远来看,函数gprintf("%t",...)gprintf("%T",...) 应该固定在gnuplot 源代码。

关于gnuplot - 与 gnuplot 格式说明符 %t 和 %T 不一致?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55130265/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com