【matlab基础知识代码】(十一)特殊矩阵输入&矩阵性质

发布于:2024-05-09 ⋅ 阅读:(87) ⋅ 点赞:(0)

>> A=zeros(3,8)

A =

     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0
     0     0     0     0     0     0     0     0

>> B=eye(size(A))

B =

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

>> n = 6; % 定义变量n并赋值为10
A = rand(n)% 生成一个n*n的随机矩阵

A =

    0.3786    0.5502    0.2305    0.4357    0.9797    0.2622
    0.8116    0.6225    0.8443    0.3111    0.4389    0.6028
    0.5328    0.5870    0.1948    0.9234    0.1111    0.7112
    0.3507    0.2077    0.2259    0.4302    0.2581    0.2217
    0.9390    0.3012    0.1707    0.1848    0.4087    0.1174
    0.8759    0.4709    0.2277    0.9049    0.5949    0.2967

>> C=[1,2,3];V=diag(C)

V =

     1     0     0
     0     2     0
     0     0     3

>> V1=diag(V)

V1 =

     1
     2
     3
>> %生成主对角线上第2条对角线为C的矩阵
>> V2=diag(C,2)

V2 =

     0     0     1     0     0
     0     0     0     2     0
     0     0     0     0     3
     0     0     0     0     0
     0     0     0     0     0

>> V3=diag(C,-1)

V3 =

     0     0     0     0
     1     0     0     0
     0     2     0     0
     0     0     3     0

 

 

>> H=hankel(C)%后面都为0

H =

     1     2     3
     2     3     0
     3     0     0

 范德蒙矩阵

 

 

>> P=[2 0 4 5 6]; A=compan(P)

A =

         0   -2.0000   -2.5000   -3.0000
    1.0000         0         0         0
         0    1.0000         0         0
         0         0    1.0000         0

 

 

 

>> A=sym('a%d%d',4)
 
A =
 
[a11, a12, a13, a14]
[a21, a22, a23, a24]
[a31, a32, a33, a34]
[a41, a42, a43, a44]
>>  B=sym('a%d%d',[4,2])
 
B =
 
[a11, a12]
[a21, a22]
[a31, a32]
[a41, a42]
>> C=sym('f%d%d',[4,4])
 
C =
 
[f11, f12, f13, f14]
[f21, f22, f23, f24]
[f31, f32, f33, f34]
[f41, f42, f43, f44]

 

 

 

>> A=[16 2 3 13; 5 11 10 8; 9 7 6 12; 4 14 15 1]; det(A)%数值解,不一定精准

ans =

   5.1337e-13

>> det(sym(A))%符号矩阵
 
ans =
 
0

 

>> A=sym('a%d%d',[4,4]),det(A)
 
A =
 
[a11, a12, a13, a14]
[a21, a22, a23, a24]
[a31, a32, a33, a34]
[a41, a42, a43, a44]
 
 
ans =
 
a11*a22*a33*a44 - a11*a22*a34*a43 - a11*a23*a32*a44 + a11*a23*a34*a42 + a11*a24*a32*a43 - a11*a24*a33*a42 - a12*a21*a33*a44 + a12*a21*a34*a43 + a12*a23*a31*a44 - a12*a23*a34*a41 - a12*a24*a31*a43 + a12*a24*a33*a41 + a13*a21*a32*a44 - a13*a21*a34*a42 - a13*a22*a31*a44 + a13*a22*a34*a41 + a13*a24*a31*a42 - a13*a24*a32*a41 - a14*a21*a32*a43 + a14*a21*a33*a42 + a14*a22*a31*a43 - a14*a22*a33*a41 - a14*a23*a31*a42 + a14*a23*a32*a41

 

 

>> i=2; j=3; B=A; B(i,:)=[]; B(:,j)=[]; A23=(-1)^(i+j)*det(B)
 
A23 =
 
a11*a34*a42 - a11*a32*a44 + a12*a31*a44 - a12*a34*a41 - a14*a31*a42 + a14*a32*a41

 删除B的第i行,删除B的第j列

>> syms a23;A23_1=simplify((det(A)-subs(det(A),a23,0))/a23)
 
A23_1 =
 
a11*a34*a42 - a11*a32*a44 + a12*a31*a44 - a12*a34*a41 - a14*a31*a42 + a14*a32*a41