如何计算R中矩阵的零空间,以使所得的矢量根据R中的自由变量显示基本变量? [英] How to calculate null space of a matrix in R so that the resulting vectors show basic variables in terms of free variables in R?
本文介绍了如何计算R中矩阵的零空间,以使所得的矢量根据R中的自由变量显示基本变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个矩阵A1,我想计算它的空空间.
I have a matrix A1 and I want to calculate it's null space.
A1=matrix(c(1,1,2,3,2,1,1,3,1,4),nrow=2,ncol=5,byrow =TRUE)
[,1] [,2] [,3] [,4] [,5]
[1,] 1 1 2 3 2
[2,] 1 1 3 1 4
我从软件包'pracma'中使用了'nullspace'函数.
I have using the function 'nullspace' from the package 'pracma'.
nullspace(matrix(c(1,1,2,3,2,1,1,3,1,4),nrow=2,ncol=5,byrow =TRUE))
我得到的结果是
[,1] [,2] [,3]
[1,] -0.53530338 -0.53530338 -0.6117753
[2,] 0.23344278 -0.76655722 0.5525060
[3,] 0.68910778 0.02244112 -0.4505435
[4,] -0.07744944 0.25588390 0.1019625
[5,] -0.42200333 0.24466334 0.3272343
但是当我手动解决它时,我得到的结果是
But when I am solving it manually, the result I am getting is
[,1] [,2] [,3]
[1,] -1 -7 2
[2,] 1 0 0
[3,] 0 2 -2
[4,] 0 1 0
[5,] 0 0 1
如何使用R代码获得第二个答案? 我找不到任何包装.
How can I get the second answer using R codes? I cant find any package for this.
推荐答案
请仔细阅读此问题与解答;答:解决R中任何m * n矩阵A的同质系统Ax = 0(找到A的零空间基础).
Have a close read on this Q & A: Solve homogenous system Ax = 0 for any m * n matrix A in R (find null space basis for A).
答案中的NullSpace
函数完全符合您的期望.
The NullSpace
function in the answer does exactly what you are look for.
## Your matrix
A1 <- matrix(c(1,1,2,3,2,1,1,3,1,4),nrow=2,ncol=5,byrow =TRUE)
## get NullSpace from the linked Q & A yourself
## call NullSpace
X <- NullSpace(A1)
round(X, 15)
# [,1] [,2] [,3]
#[1,] -7 2 -1
#[2,] 0 0 1
#[3,] 2 -2 0
#[4,] 1 0 0
#[5,] 0 1 0
这篇关于如何计算R中矩阵的零空间,以使所得的矢量根据R中的自由变量显示基本变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文