矩阵的逆和乘法

发布于 2024-12-14 14:29:38 字数 798 浏览 3 评论 0原文

我是矩阵世界的新手,很抱歉我无法弄清楚这个基本问题:

我有四个矩阵(一个未知)。

矩阵 X

x <- c(44.412, 0.238, -0.027, 93.128, 0.238, 0.427, -0.193, 0.673, 0.027, 
     -0.193, 0.094, -0.428, 93.128, 0.673, -0.428, 224.099)

X <- matrix(x, ncol = 4 )

矩阵 B :需要求解,1 X 4(列 x n 行),具有 b1、b2、b3、b4 值

矩阵 G

g <- c(33.575, 0.080, -0.006, 68.123, 0.080, 0.238, -0.033, 0.468, -0.006, 
-0.033, 0.084, -0.764, 68.123, 0.468, -0.764, 205.144)

G <- matrix(g, ncol = 4)

矩阵 A

a <- c(1, 1, 1, 1) # one this case but can be any value 
A <- matrix(a, ncol = 1)

解决方案:

B = inv(X) G A  # inv(X) is inverse of the X matrix multiplied by G and A 

我不知道如何正确解决这个问题,特别是矩阵的逆矩阵。感谢您的帮助。

I am new to world of matrix, sorry for this basic question I could not figure out:

I have four matrix (one unknown).

Matrix X

x <- c(44.412, 0.238, -0.027, 93.128, 0.238, 0.427, -0.193, 0.673, 0.027, 
     -0.193, 0.094, -0.428, 93.128, 0.673, -0.428, 224.099)

X <- matrix(x, ncol = 4 )

Matrix B : need to be solved , 1 X 4 (column x nrows), with b1, b2, b3, b4 values

Matrix G

g <- c(33.575, 0.080, -0.006, 68.123, 0.080, 0.238, -0.033, 0.468, -0.006, 
-0.033, 0.084, -0.764, 68.123, 0.468, -0.764, 205.144)

G <- matrix(g, ncol = 4)

Matrix A

a <- c(1, 1, 1, 1) # one this case but can be any value 
A <- matrix(a, ncol = 1)

Solution:

B = inv(X) G A  # inv(X) is inverse of the X matrix multiplied by G and A 

I did not know how to solve this properly, particularly inverse of the matrix. Appreciate your help.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

女皇必胜 2024-12-21 14:29:38

我猜尼克和本都是老师,对做别人的作业比我有更大的顾虑,但通往完整解决方案的道路确实如此明显,不这样做并没有多大意义。下一步:

B = solve(X) %*% G %*% A 
> B
             [,1]
[1,] -2.622000509
[2,]  7.566857261
[3,] 17.691911600
[4,]  2.318762273

可以通过提供单位矩阵作为第二个参数来调用 QR 求逆方法:

> qr.solve(G, diag(1,4))
                [,1]             [,2]          [,3]             [,4]
[1,]  0.098084556856 -0.0087200426695 -0.3027373205 -0.0336789016478
[2,] -0.008720042669  4.4473233701790  1.7395207242 -0.0007717410073
[3,] -0.302737320546  1.7395207241703 13.9161591761  0.1483895429511
[4,] -0.033678901648 -0.0007717410073  0.1483895430  0.0166129089935

I'm guessing that Nick and Ben are both teachers and have even greater scruples than I do about doing other peoples' homework, but the path to a complete solution was really so glaringly obvious that it didn't make a lot of sense not to tae the next step:

B = solve(X) %*% G %*% A 
> B
             [,1]
[1,] -2.622000509
[2,]  7.566857261
[3,] 17.691911600
[4,]  2.318762273

The QR method of inversion can be invoked by supplying an identity matrix as the second argument:

> qr.solve(G, diag(1,4))
                [,1]             [,2]          [,3]             [,4]
[1,]  0.098084556856 -0.0087200426695 -0.3027373205 -0.0336789016478
[2,] -0.008720042669  4.4473233701790  1.7395207242 -0.0007717410073
[3,] -0.302737320546  1.7395207241703 13.9161591761  0.1483895429511
[4,] -0.033678901648 -0.0007717410073  0.1483895430  0.0166129089935
痞味浪人 2024-12-21 14:29:38

计算上更稳定的解决方案是使用 qr 而不是 solve

method1 <- solve(X) %*% G %*% A
method2 <- qr.coef(qr(X), G) %*% A
stopifnot(isTRUE(all.equal(method1, method2)))

请参阅 ?qr 中的示例。

A more computationally stable solution is to use qr rather than solve.

method1 <- solve(X) %*% G %*% A
method2 <- qr.coef(qr(X), G) %*% A
stopifnot(isTRUE(all.equal(method1, method2)))

See the examples in ?qr.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文