Now let's go through some basic arithmetic in MATLAB. First, we create simple matrices to work with.
A = [1 2; 3 4]B = [5 6; 7 8]C = [9 10; 11 12]
A =
1 2
3 4
B =
5 6
7 8
C =
9 10
11 12
A + B
ans =
6 8
10 12
A - B
ans =
-4 -4
-4 -4
A * B
ans =
19 22
43 50
B2 = [1 2; 4 5; 6 7];size(B2)size(A)
ans =
3 2
ans =
2 2
A * B2
error: operator *: nonconformant arguments (op1 is 2x2, op2 is 3x2)
A * B2'
ans =
5 14 20
11 32 46
We can also divide matrices with a forward slash /
. But if you remember from linear algebra there isn't really a matrix division like that. The division of scalars is very simple.
3/5
ans = 0.6000
A .* B
ans =
5 12
21 32
A ./ B
ans =
0.2000 0.3333
0.4286 0.5000
x = [1 2 3]y = [4 5 6]x * y'
x =
1 2 3
y =
4 5 6
ans = 32
dot(x, y)
ans = 32