我已经安装了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。有谁知道该怎么办?
在任何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。
有两种方法可以处理此输入:
(顺便说一句,没有Octave接口的SymPy默认采用第一种方法,而不试图猜测用户的意图。)
> x = sym(0.1, 'f')
x = (sym)
3602879701896397
─────────────────
36028797018963968
。