matlab:2 常用命令续

2. 矩阵的运算

2.1 矩阵运算包括加、减、乘、除(左除\、右除/)、逆、乘幂等。

>>  A=[3,1;2,4];B=[0,3;5,6];
>> A+B,A-B,A*B,A/B,A\B,inv(A)

ans =

     3     4
     7    10


ans =

     3    -2
    -3    -2


ans =

     5    15
    20    30


ans =

   -0.8667    0.6000
    0.5333    0.4000


ans =

   -0.5000    0.6000
    1.5000    1.2000


ans =

    0.4000   -0.1000
   -0.2000    0.3000

2.2 矩阵的多项式运算
>> 2*A+3*B+5*A*B-A^2

ans =

    20    79
   105   158

注:数字与矩阵、矩阵与矩阵之间的*不能省略!

2.3 矩阵的关系运算与逻辑运算

Matlab中的关系运算符有:<、<=、>、>=、==、=。关系运算的结果是逻辑值1(ture)0(false)

常用的逻辑运算符有&、|、~、xor(异或)。

>> C=(A<B)&(A==B)

C =

     0     0
     0     0

>> help &
 &  Logical and.
    A & B performs a logical and of arrays A and B and returns an array
    containing elements set to either logical 1 (TRUE) or logical 0
    (FALSE).  An element of the output array is set to 1 if both input
    arrays contain a non-zero element at that same array location.
    Otherwise, that element is set to 0.  A and B must have the same
    dimensions unless one is a scalar. 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值