Search code examples
rmathequationnonlinear-functions

How to rearrange the complex algebraic equation in R?


enter image description here

The nonlinear equation is following,A,B,C,D,E are know. I want to rearrange the formation of the equation. Let the X at the left of equation,and let other parameters all at the right of equation. such as X= A*B/D+E^2/C Is there are some software to do this?such as R.


Solution

  • Try this -- ignore the warnings from that XML package that have started recently.

    library(Ryacas)
    A <- Sym("A")
    B <- Sym("B")
    C <- Sym("C")
    D <- Sym("D")
    E <- Sym("E")
    X <- Sym("X")
    Solve(E == A * B * (X + C) / (A + B * (X + C)) - A * B * (X + D + C) / (A + B * (X + D + C)), X)
    

    giving:

    expression(list(X == (root((2 * (E * A * B) + (2 * (E * B^2 * 
        C) + E * B^2 * D))^2 - 4 * (E * B^2 * (E * A^2 + (2 * (E * 
        A * B * C) + E * A * B * D) + (E * B^2 * C^2 + E * B^2 * 
        C * D) + A^2 * B * D)), 2) - (2 * (E * A * B) + (2 * (E * 
        B^2 * C) + E * B^2 * D)))/(2 * (E * B^2)), X == -(2 * (E * 
        A * B) + (2 * (E * B^2 * C) + E * B^2 * D) + root((2 * (E * 
        A * B) + (2 * (E * B^2 * C) + E * B^2 * D))^2 - 4 * (E * 
        B^2 * (E * A^2 + (2 * (E * A * B * C) + E * A * B * D) + 
        (E * B^2 * C^2 + E * B^2 * C * D) + A^2 * B * D)), 2))/(2 * 
        (E * B^2))))
    

    An alternative to the above if you have specific values for A, B, C, D, E would be to numerically solve it using, for example, uniroot.