在 Octave 中从小数转换为十进制表示

Converting from fractional to decimal representation in Octave

我收到以下警告:

warning: Using rat() heuristics for double-precision input (is this what you wanted?)

当我想要小数形式时,我的结果计算使用的是理性方法。如何强制计算将有理数转换为十进制表示形式?

代码如下:

pkg load symbolic
syms a b c d real
C = [1, 0, 0, 0; 0, 1, 0, 0; 0, 0, 0, 1; 0, 0, 1, 0]
H = (1/sqrt(2))*[1, 1; 1, -1]
I = [1, 0; 0, 1]
X = [a, b, c, d]

s = kron(H, I)
s*C*X'

有理数可以用vpa. vpa(x,n) evaluates x to at least n significant digits. If you want to use current value of digits转成浮点数,可以省略n

vpa(s*C*X.',4)   
% Above line evaluates the result to at least 4 significant digits

另请注意 ' is not transpose. It is complex conjugate transpose. Use transpose (i.e. .') 当您打算进行转置时。这就是我在上面的代码中进行替换的原因。


关于警告信息,可以turned off by:

warning ('off', 'OctSymPy:sym:rationalapprox');

您可以通过将上面代码中的off替换为on来再次开启它。