KmnsE2
KmnsE2

Reputation: 424

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?

Upvotes: 1

Views: 261

Answers (1)

Dave2e
Dave2e

Reputation: 24089

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)

Upvotes: 2

Related Questions