-2

How do we find the solution of x say in

2*x=6

using R? It must be very trivial but I cant find out the appropriate answer.

user2458552
  • 419
  • 2
  • 5
  • 17
  • 6
    To explain the reaction you've gotten: this question is too vague, appears to have little to do with an actual programming problem, and probably some people are just asking themselves why you don't divide both sides by 2. – joran Jun 25 '13 at 19:12
  • 1
    I believe this is a particular case of http://stackoverflow.com/questions/8145694/solving-simultaneous-equations-with-r, but not really a duplicate IMHO. – Waldir Leoncio Jun 25 '13 at 19:17
  • 3
    The actual program would be too large and messy to be written down here and the actual question might get shadowed.Hence,such an example. – user2458552 Jun 25 '13 at 19:24
  • 4
    Why not using directly a package for Symbolic computation such as `Ryacas`. For example : `Solve("2 * x == 6", "x")` and the result in R is `{x==3};` – dickoa Jun 25 '13 at 21:06

1 Answers1

12

You can use the solve() function, which can actually handle multiple equations:

solve(2, 6)

The first argument is the left side of the equation, the second is the right side.

Waldir Leoncio
  • 10,853
  • 19
  • 77
  • 107
  • 2
    Thank you so much for taking out time to answer such a simple qs.Thanks! :) – user2458552 Jun 25 '13 at 19:25
  • According to the [documentation](http://stat.ethz.ch/R-manual/R-patched/library/base/html/solve.html), the function solves the equation a %*% x = b for x, where b can be either a vector or a matrix. Thus, you'd have to transform 2*exp(x)=6 into something like x = log(3) before entering the parameters, which would look like this: `solve(1, log(3))`. – Waldir Leoncio Jun 25 '13 at 19:48