Search code examples
runiroot

solving equations with variables on both sides with r


0.5Q+30 = −0.2Q+100

0.5q+0.2q=100-30

70=0.7q

q=70/0.7

q=100

0.5*100+30

=80

Is there a package that solves equations with variables on both sides?


Solution

  • One option is to subtract the right hand side from the left and then use uniroot to solve it.

    #0.5Q+30 = −0.2Q+100
    leftside <- function(Q){
       x<- 0.5*Q+30
       return(x)
    }
    
    rightside <- function(Q){
       x<- -0.2*Q+100
       return(x)
    }
    
    solution<-uniroot(function(Q) {leftside(Q)- rightside(Q) },  lower = 0, upper = 999)
    print(solution$root)
    
    leftside(solution$root)