Solving simultaneous equations with R

后端 未结 4 1233
迷失自我
迷失自我 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:19

    For clarity, I modified the way the matrices were constructed in the previous answer.

    a <- rbind(c(1, 2, 3), 
               c(2, 5, 9), 
               c(5, 7, 8))
    b <- c(20, 100, 200)
    solve(a, b)
    

    In case we need to display fractions:

    library(MASS)
    fractions(solve(a, b))
    

提交回复
热议问题