Solving simultaneous equations with R

mlzboy picture mlzboy · Nov 16, 2011 · Viewed 41.7k times · Source

Suppose I have the following equations:

 x + 2y + 3z = 20  
2x + 5y + 9z = 100  
5x + 7y + 8z = 200

How do I solve these equations for x, y and z? I would like to solve these equations, if possible, using R or any other computer tools.

Answer

MYaseen208 picture MYaseen208 · Nov 16, 2011

This should work

A <- matrix(data=c(1, 2, 3, 2, 5, 9, 5, 7, 8), nrow=3, ncol=3, byrow=TRUE)    
b <- matrix(data=c(20, 100, 200), nrow=3, ncol=1, byrow=FALSE)
round(solve(A, b), 3)

     [,1]
[1,]  320
[2,] -360
[3,]  140