100 likes | 231 Views
13.3 Matrices and Matrix Arithmetic. A 11 A 12 … A 1n A= A 21 A 22 … A 2n : : : : : : A m1 A m2 … A mn . 13.3.1 Definition and Properties of Small Matrices. >>A=[1 2 3 4;5 6 7 8 ;9 10 11 12;13 14 15 16];
E N D
13.3 Matrices and Matrix Arithmetic A11 A12 …A1n A= A21 A22 …A2n : : : : : : Am1 Am2 …Amn 13.3.1 Definition and Properties of Small Matrices >>A=[1 2 3 4;5 6 7 8 ;9 10 11 12;13 14 15 16]; and >>A=[ 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 ] P.S. : Matrix rows are separated by a semicolon a mew line, and the elements within a row of a matrix may be separated by commas as well as a blank. The elements of a matrix are enclosed by brackets.
Accessing Matrix Elements : • Ex2: >>V = [ 5 4 3 2 1 ]; >>V(2) ans = 4 >> • Ex1: >>A(1,2),A(2,3) ans = 2 ans = 7 >> • Size of a Matrix : >>size([1 2 3 4 5 ;6 7 8 9 10 ;11 12 13 14 15 ] ) ans= 3 5 >>
Square Matrices : Equal Matrices : • If a matrix has the same numbers of rows as columns(i.e.,m=n),then we say that it is square. >> A = [ 1 2 3; 4 5 6 ]; >>B=A; B= 1 2 3 4 5 6 >> • Defining Matrices with Built-In MATLAB Functions • Empty Matrices : >> eye(3,4) ans = 1 0 0 0 0 1 0 0 0 0 1 0 0 0 0 1 >> >> A=[ ];
13.3.3 Application of Mathematical Functions to Matrices >>x=[ 1 2 3 4 5; 6 7 8 9 10 ] x= 1 2 3 4 5 6 7 8 9 10 >> then the command >>sin(x) ans = 0.8415 0.9093 0.1411 -0.7568 -0.9589 -0.794 0.6570 0.9894 0.4121 -0.5440
13.3.4 Colon Notation >> -3 : 3 ans= -3 -2 -1 0 1 2 3 >> The default increment is by 1 but that can be changed. For example : >>x = [0.0:0.1:2.0]’ ; >>y = sin(x); >>[x y] The third command takes the x and y column vectors and places then in a 21-by-2 matrix table.
13.3.5 Submatrices >> A=[1:6;2:7;4:9]; generates a 3-by-3 matrix >>A(1:4,3) is the column vector consisting of the first four entries of the third column of A >>A(:,3) is the third column of A, and A(1:4;) is the first four rows of A. 13.3.6 Matrix Arithmetic
Dot Product Ex : • Matrix Multiplication