Solving simultaneous equations with R

后端 未结 4 1232
迷失自我
迷失自我 2020-12-04 21:56

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

4条回答
  •  感动是毒
    2020-12-04 22:34

    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)
    solve(A)%*% b
    

    Note that this is a square matrix!

提交回复
热议问题