[英]Solving systems of equations in R
Solving an equation symbolically can be achieved in R using the Ryacas library. 象征性地求解方程可以使用Ryacas库在R中实现。 For example
例如
library(Ryacas)
yacas("Solve(x/(1+x) == a, x)")
gives 给
expression(list(x == a/(1 - a)))
Does anybody know how to (symbolically) solve a system of equations? 有人知道如何(象征性地)解决方程组吗?
Thank you. 谢谢。
Well, i use the excellent python library, sympy , for symbolic computation. 好吧,我使用优秀的python库, sympy ,进行符号计算。
Using sympy , solving systems of equations straightforward: 使用sympy ,直接求解方程组:
>>> 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}
So that's how to solve a system of equations using symbolic algebra, except through a python package. 这就是如何使用符号代数来解决方程组,除了通过python包。
The good news is that there's an R port to sympy, called rsympy , which is available on CRAN, or Google Code, here . 好消息是有一个名为rsympy的R端口,可以在CRAN或Google Code上找到 。
I have never used rsympy, other than downloading/installing it and working through a couple of the simplest examples in the rsympy Manual. 除了下载/安装它并使用rsympy手册中的几个最简单的例子之外,我从未使用过rsympy。 I have used the original python library a lot during the past three years and i can recommend it highly.
在过去的三年里,我经常使用原来的python库,我可以高度推荐它。
试试这个:
yacas( "OldSolve({a*x+y==0,x+z==0},{x,y})" )
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.