MATLAB中有没有可以改变矩阵形式的函数?

发布于 2024-08-30 13:58:20 字数 666 浏览 0 评论 0原文

我必须通过考虑以下规则改变已知矩阵的形式来获得未知矩阵:

H = [-P'|I] %'
G = [I|P]

其中

  • H 是已知矩阵
  • G 是必须计算的未知矩阵
  • I 是单位矩阵

例如,如果我们有一个矩阵,

H = [1 1 1 1 0 0; 
     0 0 1 1 0 1; 
     1 0 0 1 1 0]

其形式必须更改为

H = [1 1 1 1 0 0; 
     0 1 1 0 1 0; 
     1 1 0 0 0 1]

So

-P' = [1 1 1; 
       0 1 0; 
       1 1 0] 

并且在二进制矩阵 -P = P 的情况下。

因此,

 G = [1 0 0 1 1 1; 
      0 1 0 0 1 0; 
      0 0 1 1 1 0]

我知道如何通过执行基本的行运算在纸上解决它,但还没有弄清楚如何使用 MATLAB 解决它。

解决给定问题的方法是什么?

I have to get the unknown matrix by changing the form of a known matrix considering the following rules:

H = [-P'|I] %'
G = [I|P]

where

  • H is a known matrix
  • G is an unknown matrix which has to be calculated
  • I is the identity matrix

So for example, if we had a matrix,

H = [1 1 1 1 0 0; 
     0 0 1 1 0 1; 
     1 0 0 1 1 0]

its form has to be changed to

H = [1 1 1 1 0 0; 
     0 1 1 0 1 0; 
     1 1 0 0 0 1]

So

-P' = [1 1 1; 
       0 1 0; 
       1 1 0] 

and in case of binary matrices -P = P.

Therefore

 G = [1 0 0 1 1 1; 
      0 1 0 0 1 0; 
      0 0 1 1 1 0]

I know how to solve it on paper by performing basic row operations but haven't figured out how to solve it using MATLAB yet.

What is the method for solving the given problem?

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

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

发布评论

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

评论(1

末が日狂欢 2024-09-06 13:58:20

如果 -P' 中的列顺序并不重要,这里有一个使用函数 ISMEMBER

>> H = [1 1 1 1 0 0; 0 0 1 1 0 1; 1 0 0 1 1 0];  %# From above
>> pColumns = ~ismember(H',eye(3),'rows')  %'# Find indices of columns that
                                            %#   are not equal to rows
pColumns =                                  %#   of the identity matrix

     1
     0
     1
     1
     0
     0

>> P = -H(:,pColumns)'  %'# Find P

P =

    -1     0    -1
    -1    -1     0
    -1    -1    -1

>> G = logical([eye(3) P])  %# Create the binary matrix G

G =

     1     0     0     1     0     1
     0     1     0     1     1     0
     0     0     1     1     1     1

注意:此解决方案适用于 H 中的整数或二进制值。如果 H 具有浮点值,则在使用 ISMEMBER (请参阅 这里此处了解有关此问题的更多讨论)。

If the order of columns in -P' doesn't matter, here's one solution using the function ISMEMBER:

>> H = [1 1 1 1 0 0; 0 0 1 1 0 1; 1 0 0 1 1 0];  %# From above
>> pColumns = ~ismember(H',eye(3),'rows')  %'# Find indices of columns that
                                            %#   are not equal to rows
pColumns =                                  %#   of the identity matrix

     1
     0
     1
     1
     0
     0

>> P = -H(:,pColumns)'  %'# Find P

P =

    -1     0    -1
    -1    -1     0
    -1    -1    -1

>> G = logical([eye(3) P])  %# Create the binary matrix G

G =

     1     0     0     1     0     1
     0     1     0     1     1     0
     0     0     1     1     1     1

NOTE: This solution will work properly for integer or binary values in H. If H has floating-point values, you will likely run into an issue with floating-point comparisons when using ISMEMBER (see here and here for more discussion of this issue).

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