Octave中的Sympy错误:不支持sym中的假设'f'

问题描述 投票:1回答:1

我已经安装了Python 3.6和SymPy 1.1.1。在Octave我运行命令

pkg install -forge symbolic

之后我加载了包并尝试了syms x以查看它是否有效。它执行成功,我得到了

OctSymPy v2.6.0: this is free software without warranty, see source. 
Initializing communication with SymPy using a popen2() pipe.
Some output from the Python subprocess (pid 10580) might appear next.
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information. 
OctSymPy: Communication established.  SymPy v1.1.1.
Python 3.6.4 (v3.6.4:d48eceb, Dec 19 2017, 06:54:40) [MSC v.1900 64 bit (AMD64)]

但是,当我使用命令qazxsw poi时,我收到错误:

x=sym('x','f')

这没有任何意义,因为我有最新的SymPy。有谁知道该怎么办?

python octave sympy
1个回答
0
投票

在任何SymPy版本中都没有有效的假设'f';提到版本是一种分心。你是混乱的假设和ratflag。假设的工作方式如下:

error: sym: the assumption "f" is not supported in your Sympy version.

输入x = sym('x', 'positive') 以查看所有支持的假设。

Ratflags'r'和'f'的工作原理如下:

assumptions('possible')

> x = sym(0.1, 'r')
x = (sym) 1/10

它们适用于要放在符号变量中的数字输入。问题是0.1和大多数小数部分没有在二进制系统中准确表示。所以当你传递0.1时,你实际上是通过了3602879701896397/36028797018963968。

有两种方法可以处理此输入:

  1. 以面值表示,如3602879701896397 / 36028797018963968.这发生在ratflag'f'。
  2. 猜猜你真的意味着1/10,因为这个复杂的分数与1/10有多接近。这种情况发生在ratflag'r'中,并且是默认行为。

(顺便说一句,没有Octave接口的SymPy默认采用第一种方法,而不试图猜测用户的意图。)

> x = sym(0.1, 'f') x = (sym) 3602879701896397 ───────────────── 36028797018963968

© www.soinside.com 2019 - 2024. All rights reserved.