R中方程组的求解 [英] Solving systems of equations in R

查看:126
本文介绍了R中方程组的求解的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可以使用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.

这篇关于R中方程组的求解的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆