Download presentation
Presentation is loading. Please wait.
Published byElmer Bryan Modified over 9 years ago
1
Matlab for Engineers Built-in Matlab Functions Chapter 3
2
Matlab for Engineers In this chapter we’ll cover 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
3
Matlab for Engineers Matlab uses function names consistent with most major programming languages For example sqrt sin cos log
4
Matlab for Engineers Function Input can be either scalars or matrices
5
Matlab for Engineers Function Input can be either scalars or matrices
6
Matlab for Engineers Using Predefined Functions Functions consist of Name Input argument(s) Output sqrt(x)= result In MATLAB sqrt(4) ans = 2
7
Matlab for Engineers Some functions require multiple inputs Remainder function returns the remainder in a division problem For example the remainder of 10/3, is 1
8
Matlab for Engineers Some functions return multiple results size function determines the number of rows and columns
9
Matlab for Engineers You can assign names to the output
10
Matlab for Engineers Nesting Functions
11
Matlab for Engineers There are functions for almost anything you want to do 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
12
Matlab for Engineers From the Command Window
13
Matlab for Engineers From the Help Menu
14
Matlab for Engineers
15
Elementary Math Functions abs(x)absolute value sign(x)plus or minus exp(x)e x log(x) natural log log10(x)log base 10
16
Matlab for Engineers Rounding Functions round(x) fix(x) floor(x) ceil(x)
17
Matlab for Engineers
19
Discrete Mathmatics factor(x) gcd(x,y) greatest common denominator lcm(x) lowest common multiple rats(x) represent x as a fraction factorial(x) primes(x) isprime(x)
20
Matlab for Engineers Trigonometric Functions sin(x)sine cos(x)cosine tan(x)tangent asin(x)inverse sine sinh(x)hyperbolic sine asinh(x)inverse hyperbolic sine sind(x)sine with degree input asind(x)inverse sin with degree output
21
Matlab for Engineers Data Analysis max(x) min(x) mean(x) median(x) sum(x) prod(x) sort(x)
22
Matlab for Engineers When x is a matrix, the max is found for each column
23
Matlab for Engineers max value element number where the max value occurs
24
Matlab for Engineers Vector of row numbers Vector of maximums
25
Matlab for Engineers Determining Matrix Size size(x)number of rows and columns length(x)biggest dimension
26
Matlab for Engineers
27
Variance and Standard Deviation std(x) var(x)
28
Matlab for Engineers Standard Deviation
29
Matlab for Engineers Random Numbers rand(x) Returns an x by x matrix of random numbers between 0 and 1 rand(n,m) Returns an n by m matrix of random numbers These random numbers are evenly distributed
30
Matlab for Engineers
33
Gaussian Random numbers randn(n) Also called a normal distribution Generates numbers with a mean of 0 and a standard deviation of 1
34
Matlab for Engineers
37
To generate random numbers between other bounds… a and b are the upper and lower bounds r is the array of random numbers
38
Matlab for Engineers
39
More about Manipulating Matrices M(:) Converts a two dimensional matrix to a single column
40
Matlab for Engineers
42
Complex Numbers complex(x,y) real(A) used if A is a complex number imag(A) isreal(A) conj(A) abs(A) angle(A) real imaginary
43
Matlab for Engineers Computational Limits Matlab’s computational range on most computers is: 10 -308 10 308 When you divide by 0, the computer returns Inf
44
Matlab for Engineers Check the limits on your computer with these commands realmax realmin intmax intmin
45
Matlab for Engineers
46
When using very large or very small numbers the result may depend on the order of operation
47
Matlab for Engineers Special Values and Functions 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.
48
Matlab for Engineers Summary MATLAB contains a wide array of predefined functions Elementary Math Functions Trigonometric Functions Data Analysis Functions Random Numbers Complex Numbers
49
Matlab for Engineers Summary The colon operator allows you to manipulate matrices
50
Matlab for Engineers Summary Computational Limits Special Values and Functions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.