Numerical data type in Matlab Getting the Size
Numerical data type in Matlab
Getting the Size of the Matrix To get the size of the matrix, use the size command. Example: [numRow, numCol] = size(aaa); [R,C]=size(aaa); S = size(Matrix,dim); nR = size(aaa,1) nC = size(aaa,2) If dimension of the matrix K>2 S = size(aaa,k); S=1
Getting the length of the Vector To get the length of the vector, use the length command. Example: nE=length(vec) For matrix the use the length command nR = length(aaa) nR = length(aaa,1) =size(aaa,1) nC = length(aaa,2) =size(aaa,2)
Transposing a Matrix A transpose operation changes the column of a matrix into rows, and rows into columns. To do a transpose, use the single quote operator “ var’ ”. TTM=aaa’; TTV=vec’
Example: Transposing a Row Matrix
Example: Transposing a Column Matrix
Example: Transposing a Regular Matrix
Linear Algebra whit matrices To create the Identity matrix (I) NxN, use the eye function. Example: IdentM = eye(N); To find the Matrix inverse , use the inv function. A * inv(A) = I . Example: invM = inv(aaa); To find the Matrix determinant , use the det function. Example: detM = det(aaa);
Finding the Maximum Value To find the maximum value for a matrix, use the max function. Example: maxValV = max(vec); maxValCM = max(aaa); maximum value for each column. maxValM = max(max(aaa)); maxValM = max(aaa(:)); max. value for all matrix
Finding the Minimum Value To find the minimum value for a matrix, use the min function. Example: minValV = min(vec); minValCM = min(aaa); minimum value for each column. minValM = min(min(aaa)); minValM = min(aaa(:)); min. value for all matrix
Maximun and Minimum Value Maximun and minimum value for a matrix, Example: maxValRM = max(aaa,[],2); minValRM = min(aaa,[],2); maximum or minimun value for each row. C = max(A,B); C = min(A,B); The largest or smallest elements taken from A or B. C = max(A,k) C = min(A,k) Compare each element of A to a scalar k
Finding the Sum of Columns To find the sum of each column, use the sum command. Example: colSum = sum(aaa); CSum = sum(aaa,1) RSum = sum(aaa,2) sum for each row TSum = sum(sum(aaa)); sum for all matrix
13 MATLAB Special Variables ans Default variable name for results pi Value of inf Infinity NaN Not a number e.g. 0/0 i and j i = j = square root of minus one: (-1) (imaginary number) e.g. sqrt(-1) ans= 0 + 1.0000i realmin The smallest usable positive real number realmax The largest usable positive real number
Operators (arithmetic) + addition - subtraction * multiplication .* element-by-element multiplication / division ./ element-by-element division ^ power .^ element-by-element power
Adding Matrices To add matrices, use the + operator. Example: add matrices A and B. S = A + B S = A .+ B Make sure that the matrices are the same size.
Subtracting Matrices To subtract matrices, use the - operator. Example: subtract matrix B from A. R = A – B R = A .- B Make sure that the matrices are the same size.
Multiplying Matrices To multiply matrices, use the .* and * operator. Example: multiply matrices A and B. M = A * B Make sure that the matrices are the according size ( QxN = QxM * MxN ). eM = A .* B Make sure that the matrices are the same size (MxN .* MxN).
Dividing Matrices To divide matrices, use the / and ./ operator. Example: divide matrices A with B. D = A / B = D = A*inv(B) Make sure that the matrices are the according size ( QxN = QxM / MxN ). eD = A ./ B Make sure that the matrices are the same size (MxN ./ MxN). .
Power of matrices To power of matrices, use the ^ and .^ operator. Example: power of matrices A with B. P = A ^ B P = A ^ k A to a scalar k P = k ^ A a scalar k to A eP = A .^ B Make sure that the matrices are the same size (MxN .^ MxN). .
Homework NxN Vec=[13 ,21, 10, 19, 34, 1, 34, 18, 21, 10, 19] Из таких матр. получить: MN=LAR*IM; Определитель LAR Обратная матрица LAR Миним. и максим. знач. Фамилии.
2418-matlab_ruso_2_-_matlab_fundamentals.ppt
- Количество слайдов: 20