Chapter 3 Notes
Chapter 3 Notes COMP 1200 - 002
Popular in MATLAB
Popular in Computer Information Systems
This 9 page Class Notes was uploaded by Nichole Kirby on Friday September 25, 2015. The Class Notes belongs to COMP 1200 - 002 at Auburn University taught by Jacqueline Holliday Hundley in Fall 2015. Since its upload, it has received 93 views. For similar materials see MATLAB in Computer Information Systems at Auburn University.
Reviews for Chapter 3 Notes
Report this Material
What is Karma?
Karma is the currency of StudySoup.
You can buy or earn more Karma at anytime and redeem it for class notes, study guides, flashcards, and more!
Date Created: 09/25/15
Chapter 3 Notes BuiltIn MATLAB Functions 0 MATLAB is in the C programming language but it is also in Fortran and Java as well Argument input to a function Example rem 103 The remainder function rem requires two inputs a dividend and a divisor This calculates the remainder of 10 divided by 3 ans 1 Example d 1 2 3 4 5 6 f size d The size function is an example of a function that returns two outputs Which are stored in a single array It determines the number of rows and columns in a matrix Returns the 1x2 result matrix Common Math Functions absx Finds the absolute value of X abs 3 ans 3 sqrtx Finds the square root of X sqrt 85 ans 92195 nthrootxn Finds the real nth root of X This function Will not return complex results Thus does not return the same result yet both answers are legitimate third roots of 2 nthroot23 ans12599 2quot13 signx Returns a value of 1 if X is less than zero a value of 0 if x equals zero and a value of 1 if x is greater than zero Sign8 ans1 remxy Computes the remainder of xy rem254 ans1 eXpx Computes the value of equot where e is the base for natural logarithms or approximately 27183 eXp10 ans22026e004 logx Computes lnx the natural logarithm of X to the base e log 10 ans23026 log10x Computes log10x the common logarithm of X to the base 10 log1010 ans1 Rounding Functions roundx Rounds X to the nearest integer round86 ans9 fiXx Rounds or truncates X to the nearest integer toward zero Notice that 86 truncates to 8 not 9 with this function fiX86 ans8 fiX86 ans8 oorx Rounds X to the nearest integer toward negative infinity oor86 ans9 ceilx Rounds X to the nearest integer toward positive infinity ceil86 ans8 Functions Used in Discrete Mathematics factorx Finds the prime factors of X factor12 ans2 2 3 gcdxy Finds the greatest common denominator of X and y gcd1015 ans5 lcmxy Finds the least common multiple of X and y lcm25 ans10 lcm210 ans10 ratsx Represents X as a fraction rats15 ans32 factorialx Finds the value of X factorial x A factorial is the product of all the integers less than X For example 66X5X4X3X2X1720 factorial6 ans7 20 nchooseknk Finds the number of possible combinations of k items from a group of 11 items For example use this function to determine the number of possible subgroups of 3 chosen from a group of 10 primes x isprimex nchoosek103 ans120 Finds all the prime numbers less than X primes10 ans2 3 5 7 Checks to see if X is a prime number If it is the function returns 1 if not it returns 0 isprime10 ans1 isprime10 ans0 Some of the Available Trigonometric Functions sinx cosx tanx asinx sinhx asinhx sindx asindx Finds the sine of X when X is expressed in radians sin0 ans0 Finds the cosine of X when X is expressed in radians cospi ans1 Finds the tangent of X when X is expressed in radians tanpi ans 12246e39016 Finds the arcsine or invers sine of X where X must be between 1 or 1 The H H function returns an angle in radians between E and E Finds the hyperbolic sine of X when X is expressed in radians asin1 ans15708 Finds the hyperbolic sine of X when x is expressed in radians sinhpi ans115487 Finds the inverse hyperbolic sin of X asinh1 ans08814 Finds the sin of X when X is expressed in degrees sind90 ans1 Finds the inverse sin of X and reports the result in degrees asind1 ans90 Maxima and Minima maXx Finds the largest value in a vector X For example if xl 5 3 the maximum value is 5 Creates a row vector containing the maximum element from each column of a matrix x For example if xl 5 3 2 4 6 then the maximum value in column 1 is 2 the maximum value in column 2 is 5 and the maximum value is column 3 is 6 X153 maXX ans5 abmaXx Find both the largest value in a vector X and its location in vector X For x1 5 3 maxxy minx abminx mm the maximum value is named a and is found to be 5 The location of the maximum value is element 2 and is named b x153 abmaXX a5 b2 Creates a matrix the same size as x and y Both x and y must have the same number of rows and columns Each element in the resulting matrix contains the maximum value from the corresponding positions in x and y For example if x153246 and y1024187 then the resulting matrix Will be x1054287 X153246 y1024187 maxxy ans 10 5 4 2 8 7 Finds the smallest value in a vector X For example if x15 3 the minimum value is 1 Creates a row vector containing the minimum element from each column of a matrix X For example if x153246 then the minimum value in column 1 is 1 the minimum value in column 2 is 4 and the minimum value in column 3 is 3 x153 minX ans1 X153246 minX ans1 4 3 Finds both the smallest value in a vector x and its location in vector X For x153 the minimum value is named a and is found to be 1 The location of the minimum value is element 1 and is named b Creates a row vector containing the minimum element from each column of a matrix X and returns a row vector With the location of the minimum in each column of matix X For example if x153246 then the minimum value in column 1 is 1 the minimum value in column 2 is 4 and the minimum value in column 3 is 3 These minima occur in row 1 row 2 and row 1 respectively x153 abminX a1 b1 X153246 abminX 31 4 3 b1 2 1 Creates a matrix the same size as X and y Both X and y must have the same number of rows and columns Each element in the resulting matrix contains the minimum value from the corresponding positions in X and y For example if x153246 and y1024187 then the resulting matrix Will be 123146 Averages meanx medianx modex x153246 y1024187 minxy ans 1 2 3 1 4 6 Computes the mean value or average value of a vector X For example if x153 the mean value is 3 Returns a row vector contain the mean value from each column of a matrix X For example if x153246 then the mean value of column 1 is 15 the mean value of column 2 is 45 and the mean value of column 3 is 45 x153 meanx ans30000 x153246 meanx ans15 45 45 Finds the median of the elements of a vector X For example if x153 the median value is 3 Returns a row vector containing the median value from each column of a matrix x For example if x153246384 then the median value from column 1 is 2 the median value from column 2 is 5 and the median value from column 3 is 4 x153 median x ans3 x153246384 medianx ans 2 5 4 Finds the value that occurs most often in an array Thus for the array x1233 the mode is 3 x1233 modex ans3 Sums and Products sumx prodx cumsumx Sums the elements in vector x For example if x153 the is 9 x153 sumx ans9 Computes the product of the elements of a vector x For example if xl5 3 the product is 15 x153 prodx ans15 computes a vector of the same size as and containing cumulative sums of the elements of a vector x For example if xl5 3 the resulting vector is x169 x153 cumsumx ans1 6 9 cumprodx Computes a vector of the same size as and containing cumulative products of the elements of a vector x For example if x15 3 the resulting vector is x1515 x153 cumprodx ans1 5 15 Sorting Functions sortx Sorts the elements of a vector X into ascending order For example if x153 the resulting vector is x135 x153 sortx ans1 3 5 sortx descend Sorts the elements in each column in descending order x153246 sortx descend ans2 5 6 1 4 3 sortrowsx Sorts the rows in a matrix in ascending order on the basis of the values in the first column and keeps each row intact For example if x312193436 then using the sortrows command Will move the middle row into the top position The first column defaults to the basis for sorting x313193436 sortrowsx ans 1 9 3 3 1 2 4 3 6 sortrowsxn Sorts the rows in a matrix on the basis of the values in column 11 If n is negative the values are sorted in descending order If n is not specified the default column used as the basis for sorting is column 1 sortrowsx2 ans3 1 2 4 3 6 1 9 3 Size Functions Sizex Determines the number of rows and columns in matrix X If x is a multidimensional array size determines how many dimensions exist and how big they are x153246 Sizex ans2 3 absizex Determines the number of rows and columns in matrix x and assigns the number lengthx numelx of rows to a and the number of columns to b absizex a2 b3 Determines the largest dimension of a matrix x x153246 lengthx ans3 Determines the total number of elements in a matrix x x153246 numelx ans6 Statistical Functions stdx varx Computes the standard deviation of the values in a vector x For example if x153 the standard deviation is 2 However standard deviations are not usually calculated for small samples of data Returns a row vector containing the standard deviation calculated for each column of a matrix x For example if x153246 the standard deviation is column 2 is 07071 and standard deviation in column 3 is 21213 Again standard deviations are not usually calculated for small samples of data x153 stdx ans2 x153246 stdx ans07071 07071 21213 Calculates the variance of the data in x For example if x15 3 the variance is 4 However variance is not usually calculated for small samples of data Notice that the standard deviation in this example is the square root of the variance varx ans4 Random Number Generators randx randmn Returns an n x n matrix Each value in the matrix is a random number between 0 to 1 rand2 ans 09501 06068 02311 04860 Returns an m x n matrix Each value in the matrix is a random number between 0 tol rand32 ans 08913 00185 07621 08214 randnn randnmn 04565 04447 Returns as n x n matrix Each value in the matrix is a Gaussian or normal random number With a mean of 0 and a variance of 1 randn2 ans 04326 01253 16656 02877 Returns an m x n matrix Each value in the matrix is a Gaussian or normal random number With a mean of 0 and a variance of 1 randn32 ans 11465 00376 11909 03273 11892 01746 Functions Used with Complex Numbers absx anglex c0mplexxy realx imagx isrealx Computes the absolute value of a complex number using the Pythagorean theorem This is equivalent to the radius if the complex number is represented in polar coordinates x34i absx ans5 For example if x34i the absolute value is sqt3quot24quot25 Computes the angle from the horizontal in radians When a complex number is represented in polar coordinates x34i anglex ans09273 Generates a complex number With a real component x and an imaginary component y x3 y4 c0mplexxy ans 3000040000i Extracts the real component from a complex number x34i realx ans3 Extracts the imaginary component form a complex number x34i imagx ans4 Determines Whether the values in an array are real If they are real the function returns a 1 if they are complex it returns a 0 x34i isrealx ans0 conjX Generates the complex conjugate of a complex number x34i conjx ans 3000040000i Computational Limits realmax Returns the largest possible oatingpoint number used in MATLAB realmax ans17977e308 realmin Returns the smallest possible oatingpoint number used in MATLAB realmin ans22251e308 intmaX Returns the largest possible integer number used in MATLAB intmax ans2147483647 Intmin Returns the smallest possible integer number used in MATLAB Intmin ans2147483647
Are you sure you want to buy this material for
You're already Subscribed!
Looks like you've already subscribed to StudySoup, you won't need to purchase another subscription to get this material. To access this material simply click 'View Full Document'