正在加载图片...
omp >>x=3+4 maginary part of IT > imag(x)=4 Magnitude of ar >>abs(x) →5 Angle of >> angle(x)=→0.9273 plex conjugate of >> conj(x) →3-4i 4.2 Generating vectors Vectors can be generated using the command. For example, to generate a vector a that takes on the values 0 to 10 in increments of 0.5, type the following which generates a 1 x 21 matrix Other ways to generate vectors include the commands: "linspace' which generates a vector by specifying the first and last number and the number of equally spaced entries between the first and last number, and"logspace' which is the same except that entries are spaced logarithmically between the first and last entry 4.3 Accessing vector ele ts Elements of a matrix are accessed by specifying the row and column. For example, in matrix specified by A=[1 2 3;456:789], the element in the first row and third column can be accessed by writing > x=A(1, 3)which yields 3 The entire second row can be accessed with A (2,: which yields [4 5 6] where the: ' here means"take all the entries in the column". A submatrix of A consisting of rows 1 and 2 and all three columns is specified by >>z=A(1:2,1:3) which yields[123;456 5 Matrix Operations MATLAB contains a number of arithmetic, relational, and logical operations on matricesComplex scalar >> x = 3+4j Real part of x >> real(x) =⇒ 3 Imaginary part of x >> imag(x) =⇒ 4 Magnitude of x >> abs(x) =⇒ 5 Angle of x >> angle(x) =⇒ 0.9273 Complex conjugate of x >> conj(x) =⇒ 3 - 4i 4.2 Generating vectors Vectors can be generated using the ‘:’ command. For example, to generate a vector x that takes on the values 0 to 10 in increments of 0.5, type the following which generates a 1 × 21 matrix >> x = [0:0.5:10]; Other ways to generate vectors include the commands: ‘linspace’ which generates a vector by specifying the first and last number and the number of equally spaced entries between the first and last number, and ‘logspace’ which is the same except that entries are spaced logarithmically between the first and last entry. 4.3 Accessing vector elements Elements of a matrix are accessed by specifying the row and column. For example, in the matrix specified by A = [1 2 3; 4 5 6; 7 8 9], the element in the first row and third column can be accessed by writing >> x = A(1,3) which yields 3 The entire second row can be accessed with >> y = A(2,:) which yields [4 5 6] where the ‘:’ here means “take all the entries in the column”. A submatrix of A consisting of rows 1 and 2 and all three columns is specified by >> z = A(1:2,1:3) which yields [1 2 3; 4 5 6] 5 Matrix Operations MATLAB contains a number of arithmetic, relational, and logical operations on matrices. 5
<<向上翻页向下翻页>>
©2008-现在 cucdc.com 高等教育资讯网 版权所有