可以使用Ryacas库在R中以符号方式求解方程式. 例如
Solving an equation symbolically can be achieved in R using the Ryacas library. For example
library(Ryacas) yacas("Solve(x/(1+x) == a, x)")给予
expression(list(x == a/(1 - a)))有人知道如何(象征性地)求解方程组吗?
Does anybody know how to (symbolically) solve a system of equations?
谢谢.
推荐答案好吧,我使用出色的python库 sympy 进行符号计算.
Well, i use the excellent python library, sympy, for symbolic computation.
使用符号,直接求解方程组:
Using sympy, solving systems of equations straightforward:
>>> from sympy import * >>> x,y = symbols('x y') >>> solve([Eq(x + 5*y, 2), Eq(-3*x + 6*y, 15)], [x, y]) {y: 1, x: -3}因此,除了通过python程序包外,这就是使用符号代数求解方程组的方法.
So that's how to solve a system of equations using symbolic algebra, except through a python package.
好消息是,有一个指向sympy的R端口,称为 rsympy ,可在CRAN或Google Code,此处.
The good news is that there's an R port to sympy, called rsympy, which is available on CRAN, or Google Code, here.
除了下载/安装rsympy并通过rsympy手册中的几个最简单的示例进行工作外,我从未使用过rsympy.在过去的三年中,我已经大量使用了原始的python库,因此我强烈推荐它.
I have never used rsympy, other than downloading/installing it and working through a couple of the simplest examples in the rsympy Manual. I have used the original python library a lot during the past three years and i can recommend it highly.