如何在 Octave 中求逆矩阵和整数结果?

发布于 2024-08-18 07:01:56 字数 229 浏览 3 评论 0原文

我想在 Octave 中得到一个可逆矩阵,但作为整数矩阵,所以:

x = [9,15;19,2];
inv(x)

这里我得到:

[-0.0074906, 0.0561798; 0.0711610, -0.0337079]

但我想得到 [22,17;25,21] 有人知道如何求逆矩阵吗?

I would like to get an invertible matrix in Octave but as integers matrix, so:

x = [9,15;19,2];
inv(x)

Here I get:

[-0.0074906, 0.0561798; 0.0711610, -0.0337079]

but I would like to get [22,17;25,21]
anyone knows how to invert a matrix?

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

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

发布评论

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

评论(3

花心好男孩 2024-08-25 07:01:56

每个元素的逆是:

x .^ -1

哪些结果

0.1111    0.0667
0.0526    0.5000

为什么要得到[22,17;25,21]?什么样的数学运算会产生这样的结果?

The inverse of each element is:

x .^ -1

Which results

0.1111    0.0667
0.0526    0.5000

Why you want to get [22,17;25,21]? What mathematical operation would yield such result?

眼趣 2024-08-25 07:01:56

以八度音程反转矩阵:

您对矩阵的逆是什么感到困惑,这里没有人知道您想要的输出是什么,所以这里有一些线索。

如果对单位矩阵求逆,您将得到单位矩阵:

octave:3> a = [1,0;0,1]
a =

   1   0
   0   1

octave:4> inv(a)
ans =

   1   0
   0   1

非方阵(m×n 矩阵,其中 m != n)没有逆矩阵

x = [9,15;19,2;5,5]; 
inv(x) 
%error: inverse: argument must be a square matrix

对对角线上为零的矩阵求逆会导致无穷大:

octave:5> a = [1,0;0,0]
a =

   1   0
   0   0

octave:6> inv(a)
warning: inverse: matrix singular to machine precision, rcond = 0
ans =

   Inf   Inf
   Inf   Inf

对具有完整值的矩阵求逆,如下所示:

octave:1> a = [1,2;3,4]
a =
   1   2
   3   4

octave:2> inv(a)
ans =    
  -2.00000   1.00000
   1.50000  -0.50000

了解逆函数底层发生的情况的描述:

https://www .khanacademy.org/math/precalculus/precalc-matrices/inverting_matrices/v/inverse-of-a-2x2-matrix

Invert a matrix in octave:

You are confused about what an inverse of a matrix is, don't nobody here knows what you want with your output, so here are some clues.

If you Invert an identity matrix, you get the identity matrix:

octave:3> a = [1,0;0,1]
a =

   1   0
   0   1

octave:4> inv(a)
ans =

   1   0
   0   1

Non-square matrices (m-by-n matrices for which m != n) do not have an inverse

x = [9,15;19,2;5,5]; 
inv(x) 
%error: inverse: argument must be a square matrix

Inverting a matrix with a zero on the diagonal causes an infinity:

octave:5> a = [1,0;0,0]
a =

   1   0
   0   0

octave:6> inv(a)
warning: inverse: matrix singular to machine precision, rcond = 0
ans =

   Inf   Inf
   Inf   Inf

Inverting a matrix with full values like this:

octave:1> a = [1,2;3,4]
a =
   1   2
   3   4

octave:2> inv(a)
ans =    
  -2.00000   1.00000
   1.50000  -0.50000

For a description of what is happening under the hood of the inverse function:

https://www.khanacademy.org/math/precalculus/precalc-matrices/inverting_matrices/v/inverse-of-a-2x2-matrix

清欢 2024-08-25 07:01:56

我很晚了,不知道如何有效地回答这个问题,但看起来你正在寻找矩阵的模逆,特别是 mod 26。

x = [9,15,19,2];
modulus = 26;
inverse_determinant = mod_inverse(det(x),modulus)

你必须自己实现 mod_inverse 函数,但算法应该很容易找到。如果这仅适用于小模值,那么线性搜索应该足够有效。

result = mod(det(x)*inv(x)*inverse_determinant,modulus)`

I'm very late to this and don't know how to answer the question efficiently, but it looks like you're looking to find the modular inverse of the matrix, in particular mod 26.

x = [9,15,19,2];
modulus = 26;
inverse_determinant = mod_inverse(det(x),modulus)

You have to implement the mod_inverse function by yourself, but the algorithm should be easy enough to find. If this is only for small modulus values, then a linear search should be efficient enough.

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