Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Solving systems of equations in 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)")

gives

expression(list(x == a/(1 - a)))

Does anybody know how to (symbolically) solve a system of equations?

Thank you.

like image 390
Brani Avatar asked Nov 02 '10 08:11

Brani


People also ask

How do you solve two equations with two variables in R?

Use plotEqn() for equations with two-variable equations and use plotEqn3d for three-variable equations.

What is R in linear equations?

The number r is called the constant of the equation ax + by = r. Examples. 10x - 3y = 5 and -2x - 4y = 7 are linear equations in two variables. Solutions of equations.


1 Answers

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}

So that's how to solve a system of equations using symbolic algebra, except through a python package.

The good news is that there's an R port to sympy, called rsympy, which is available on CRAN, or Google Code, here.

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.

like image 105
doug Avatar answered Oct 05 '22 10:10

doug