Survey
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
* Your assessment is very important for improving the work of artificial intelligence, which forms the content of this project
Built-in Matlab Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour Test Scores Distribution of Test Scores 100 120 100 Chapter 3 100 200 Average = 50 Average = 50 60 # of students Score 80 40 20 0 80 60 40 20 0 200 400 600 Student Number 800 0 1000 0 20 40 60 80 100 Score 300 100 400 120 100 100 200 300 400 500 # of students 500 Score 80 Average = 50 60 40 20 0 Average = 50 80 60 40 20 0 200 400 600 Student Number 800 1000 0 0 20 Matlab for Engineers 40 60 Score 80 100 In this chapter we’ll cover Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • • • • • • • • • Using Built in Functions Using the Help Feature Elementary Math Functions Trigonometric Functions Data Analysis Functions Random Number Functions Complex Number Functions Computational Limits Special Values and Miscellaneous Functions Matlab for Engineers Matlab uses function names consistent with most major programming languages Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour For example • • • • 100 200 300 400 500 100 200 300 400 sqrt sin cos log 500 Matlab for Engineers Function Input can be either scalars or matrices Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Function Input can be either scalars or matrices Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Using Predefined Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • Functions consist of • Name • Input argument(s) • Output In MATLAB 100 200 sqrt (x)= result 300 400 500 100 200 300 400 sqrt(4) 500 ans = 2 Matlab for Engineers Some functions require multiple inputs Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 • Remainder function returns the remainder in a division problem • For example the remainder of 10/3, is 1 200 300 400 500 100 200 300 400 500 Matlab for Engineers Some functions return multiple results Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • size function determines the number of rows and columns 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers You can assign names to the output Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Nesting Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers There are functions for almost anything you want to do Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • Use the help feature to find out what they are and how to use them • From the command window • From the help selection on the menu bar Matlab for Engineers From the Command Window Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 From the Help Menu 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Elementary Math Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • • • • • abs(x) sign(x) exp(x) log(x) log10(x) absolute value plus or minus ex natural log log base 10 Matlab for Engineers Rounding Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 • • • • round(x) fix(x) floor(x) ceil(x) 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Discrete Mathmatics Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • • • • • • • factor(x) gcd(x,y) lcm(x) rats(x) factorial(x) primes(x) isprime(x) greatest common denominator lowest common multiple represent x as a fraction Matlab for Engineers Trigonometric Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • • • • • • • • sin(x) cos(x) tan(x) asin(x) sinh(x) asinh(x) sind(x) asind(x) sine cosine tangent inverse sine hyperbolic sine inverse hyperbolic sine sine with degree input inverse sin with degree output Matlab for Engineers Data Analysis Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • • • • • • • max(x) min(x) mean(x) median(x) sum(x) prod(x) sort(x) Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 When x is a matrix, the max is found for each column Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 max value -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour element number where the max value occurs 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour Vector of maximums 100 200 300 400 500 100 200 300 400 500 Vector of row numbers Matlab for Engineers Determining Matrix Size Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • size(x) • length(x) number of rows and columns biggest dimension 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Variance and Standard Deviation Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 2 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • std(x) • var(x) N 100 200 300 2 400 500 100 200 300 400 500 x k 1 2 k N 1 Matlab for Engineers Standard Deviation Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Random Numbers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • rand(x) • Returns an x by x matrix of random numbers between 0 and 1 • rand(n,m) 100 200 300 400 500 100 200 300 400 500 • Returns an n by m matrix of random numbers • These random numbers are evenly distributed Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Gaussian Random numbers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 • randn(n) • Also called a normal distribution • Generates numbers with a mean of 0 and a standard deviation of 1 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour To generate random numbers between other bounds… x b a r a 100 200 300 400 500 100 200 300 400 500 a and b are the upper and lower bounds r is the array of random numbers Matlab for Engineers Test Scores Distribution of Test Scores 100 120 Rate of Change 100 80 Average = 50 -4 -3.5 -2 -1.5 -1 Average = 50 60 # of students -3 -2.5 Score Rate of temperature change, degrees/hour -5 -4.5 40 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 80 60 40 5 time, hour 20 0 20 0 200 400 600 Student Number 800 0 1000 0 20 40 60 80 100 Score 100 120 100 80 Score 200 300 # of students 100 Average = 50 60 40 400 500 100 200 300 400 500 20 0 Average = 50 80 60 40 20 0 200 400 600 Student Number 800 1000 0 0 20 40 60 Score Matlab for Engineers 80 100 More about Manipulating Matrices Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • M(:) • Converts a two dimensional matrix to a single column 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Complex Numbers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • complex(x,y) • real(A) • • • • • imag(A) isreal(A) conj(A) abs(A) angle(A) used if A is a complex number imaginary real Matlab for Engineers Computational Limits Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • Matlab’s computational range on most computers is: • 10-308 • 10308 100 200 300 400 500 100 200 300 400 500 • When you divide by 0, the computer returns Inf Matlab for Engineers Check the limits on your computer with these commands Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 • • • • realmax realmin intmax intmin 300 400 500 100 200 300 400 500 Matlab for Engineers Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers When using very large or very small numbers the result may depend on the order of operation Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Special Values and Functions Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • • • • • • • • pi i,j Inf NaN clock date eps ans Hint: The function i is the most common of these functions to be unintentionally renamed by Matlab users. Matlab for Engineers Summary Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour 100 200 300 400 500 100 200 300 400 500 • MATLAB contains a wide array of predefined functions • • • • • Elementary Math Functions Trigonometric Functions Data Analysis Functions Random Numbers Complex Numbers Matlab for Engineers Summary Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • The colon operator allows you to manipulate matrices 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers Summary Rate of Change Rate of temperature change, degrees/hour -5 -4.5 -4 -3.5 -3 -2.5 -2 -1.5 -1 -0.5 0 0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5 time, hour • Computational Limits • Special Values and Functions 100 200 300 400 500 100 200 300 400 500 Matlab for Engineers