【问题标题】:How to inverse matrix and integer result in Octave?如何在 Octave 中求逆矩阵和整数结果?
【发布时间】:2010-01-17 00:41:04
【问题描述】:

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

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

我明白了:

[-0.0074906, 0.0561798; 0.0711610, -0.0337079]

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

【问题讨论】:

  • inv(x) 的结果是正确的。 [22,17,25,21] 实际上应该是 [22,17;25,21] 吗? (注意分号)你想从 [9,15;19,2] 得到 [22,17;25,21] 吗?
  • 什么是[22,17;25,21]

标签: matrix octave inversion


【解决方案1】:

每个元素的倒数是:

x .^ -1

哪些结果

0.1111    0.0667
0.0526    0.5000

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

【讨论】:

    【解决方案2】:

    以八度音阶反转矩阵:

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

    如果你反转一个单位矩阵,你会得到单位矩阵:

    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

    【讨论】:

      【解决方案3】:

      我很晚了,不知道如何有效地回答这个问题,但看起来你正在寻找矩阵的模逆,特别是 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)`
      

      【讨论】:

        猜你喜欢
        • 2021-02-23
        • 2019-01-04
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2014-09-02
        • 1970-01-01
        • 2013-05-05
        • 2011-08-30
        相关资源
        最近更新 更多