用 R 求解联立方程
假设我有以下方程:
x + 2y + 3z = 20
2x + 5y + 9z = 100
5x + 7y + 8z = 200
如何解出这些方程的 x
、y
和 z
?如果可能的话,我想使用 R 或任何其他计算机工具来求解这些方程。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这应该有效
This should work
为了清楚起见,我修改了之前答案中构造矩阵的方式。
如果我们需要显示分数:
For clarity, I modified the way the matrices were constructed in the previous answer.
In case we need to display fractions:
另一种方法是使用
lm
对方程进行建模,如下所示:它会产生相同的
如果您使用
tibble
包,您甚至可以让它像原始方程一样读取:结果输出。
Another approach is to model the equations using
lm
as follows:which produces
If you use the
tibble
package you can even make it read just like the original equations:which produces the same output.
请注意,这是一个方阵!
Note that this is a square matrix!