问题描述
根据 Octave 的 format
文档,short
的默认值是:
By default,Octave displays 5 significant digits in a human
readable form (option ‘short’ paired with ‘loose’ format for
matrices). If format is invoked without any options,this default
format is restored.
short
Fixed point format with 5 significant figures in a field that
is a maximum of 10 characters wide. (default).
If Octave is unable to format a matrix so that columns line up
on the decimal point and all numbers fit within the maximum
field width then it switches to an exponential ‘e’ format.
short e long e
Exponential format. The number to be represented is split
between a mantissa and an exponent (power of 10). The mantissa
has 5 significant digits in the short format and 15 digits in
the long format. For example,with the ‘short e’ format,pi is
displayed as 3.1416e+00.
这是我得到的:
octave:8> pi*1e3
ans = 3141.6
octave:9> pi*1e4
ans = 31415.92654
我可以看到 short
如何产生第一个输出,但看不到第二个输出精度是如何达到的。谁能解释一下?
采取的步骤
我认为除了 ~/.octaverc: format compact
中的 1 条语句之外,我已经处于默认条件下。我只通过 octave --no-window-system --silent
在 CLI 模式下使用 Octave。 [a b c]=format
和 ver
的结果是:
octave:1> [a b c] = format
a = short
b = compact
error: element number 3 undefined in return list
octave:1> ver
----------------------------------------------------------------------
GNU Octave Version: 5.2.0 (hg id: eb46a9f47164)
GNU Octave License: GNU General Public License
Operating System: CYGWIN_NT-10.0-19041 3.1.7-340.x86_64 2020-08-22 17:48 UTC x86_64
5.2 版是 Cygwin 的最新版本。
我使用 GUI (octave --gui
) 获得了相同的结果,无论是在波动精度还是 format
和 ver
的输出方面。
解决方法
我无法使用 Octave 6.2.0 重新创建您的结果。您确定在获得上述输出之前重置为默认条件吗?您可以使用最多三个输出变量调用 format
来验证您的当前状态。例如:
octave:6> format
octave:7> [a b c] = format
a = short
b = loose
c = lowercase
octave:8> pi*1e3
ans = 3141.6
octave:9> pi*1e4
ans = 3.1416e+04
我在 CLI 和 GUI 中得到了相同的结果。