• MATLAB学习(三)元素访问和常用代数运算


    >> A=[1,2;3,4],B=[0,2;4,5]
    
    A =
    
         1     2
         3     4
    
    
    B =
    
         0     2
         4     5
    
    >> C=A>=B
    
    C =
    
         1     1
         0     0
    
    >> D=A==B
    
    D =
    
         0     1
         0     0
    
    >> A~=B
    
    ans =
    
         1     0
         1     1

    >> x=-3:5;L=abs(x)>2;y=x(L)
    
    y =
    
        -3     3     4     5
    
    >> x
    
    x =
    
        -3    -2    -1     0     1     2     3     4     5
    
    >> L
    
    L =
    
         1     0     0     0     0     0     1     1     1
    
    >> 

     

    >> a=[16 2 3 13;5 11 0 8;9 7 6 12;4 14 -1 2]
    
    a =
    
        16     2     3    13
         5    11     0     8
         9     7     6    12
         4    14    -1     2
    
    >> a(1:3,3)
    
    ans =
    
         3
         0
         6
    
    >> b=a(1:3,:)
    
    b =
    
        16     2     3    13
         5    11     0     8
         9     7     6    12
    
    >> x=(-1:0.2:1)
    
    x =
    
      1 至 7-1.0000   -0.8000   -0.6000   -0.4000   -0.2000         0    0.2000
    
      8 至 110.4000    0.6000    0.8000    1.0000
    
    >> z=[x,sin(x)]
    
    z =
    
      1 至 7-1.0000   -0.8000   -0.6000   -0.4000   -0.2000         0    0.2000
    
      8 至 140.4000    0.6000    0.8000    1.0000   -0.8415   -0.7174   -0.5646
    
      15 至 21-0.3894   -0.1987         0    0.1987    0.3894    0.5646    0.7174
    
      220.8415
    
    >> c=magic(4)
    
    c =
    
        16     2     3    13
         5    11    10     8
         9     7     6    12
         4    14    15     1
    
    >> c(:,3)=[]
    
    c =
    
        16     2    13
         5    11     8
         9     7    12
         4    14     1
    
    >> k=find(A<=3)
    未定义函数或变量 'A'。
     
    是不是想输入:
    >> k=find(a<=3) %单下标从上到下,从左到右
    
    k =
    
         5
         9
        10
        12
        16
    
    >> [s,t]=find(a<=3)
    
    s =
    
         1
         1
         2
         4
         4
    
    
    t =
    
         2
         3
         3
         3
         4
    
    >> I=(a<=3)
    
    I =
    
         0     1     1     0
         0     0     1     0
         0     0     0     0
         0     0     1     1
    
    >> a(I)
    
    ans =
    
         2
         3
         0
        -1
         2
    
    >> B=a(abs(a-2)<=1)
    
    B =
    
         2
         3
         2

    >> A=[1,3,5;2,4,6;3,5,9]
    
    A =
    
         1     3     5
         2     4     6
         3     5     9
    
    >> B=[1,3,5;2,4,6;1,1,1]
    
    B =
    
         1     3     5
         2     4     6
         1     1     1
    
    >> dB=det(B),nA=inv(A)
    
    dB =
    
         0
    
    
    nA =
    
       -1.5000    0.5000    0.5000
       -0.0000    1.5000   -1.0000
        0.5000   -1.0000    0.5000
    
    >> rref([A,B])
    
    ans =
    
         1     0     0     0    -2    -4
         0     1     0     2     5     8
         0     0     1    -1    -2    -3
    
    >> c=ones(3),[V,D]=eig(C)
    
    c =
    
         1     1     1
         1     1     1
         1     1     1
    
    未定义函数或变量 'C'>> C=ones(3),[V,D]=eig(C)
    
    C =
    
         1     1     1
         1     1     1
         1     1     1
    
    
    V =
    
        0.4082    0.7071    0.5774
        0.4082   -0.7071    0.5774
       -0.8165         0    0.5774
    
    
    D =
    
       -0.0000         0         0
             0   -0.0000         0
             0         0    3.0000
    
    >> cT=(A+i*B)',T=(A+i*B).',rT=A'
    
    cT =
    
       1.0000 - 1.0000i   2.0000 - 2.0000i   3.0000 - 1.0000i
       3.0000 - 3.0000i   4.0000 - 4.0000i   5.0000 - 1.0000i
       5.0000 - 5.0000i   6.0000 - 6.0000i   9.0000 - 1.0000i
    
    
    T =
    
       1.0000 + 1.0000i   2.0000 + 2.0000i   3.0000 + 1.0000i
       3.0000 + 3.0000i   4.0000 + 4.0000i   5.0000 + 1.0000i
       5.0000 + 5.0000i   6.0000 + 6.0000i   9.0000 + 1.0000i
    
    
    rT =
    
         1     2     3
         3     4     5
         5     6     9
  • 相关阅读:
    python 多个变量赋值
    python标准数据类型
    Python 变量类型
    H3C 扩展ACL与基于时间的ACL
    H3C BGP-filter-policy
    H3C 标准ACL
    H3C BGP实验集合
    H3C IS-IS实验大集合(ipv6)
    H3C ISIS实验大集合(IPv4)
    JS 封装一个显示时间的函数
  • 原文地址:https://www.cnblogs.com/caiyishuai/p/11149781.html
Copyright © 2020-2023  润新知