Predefined MATLAB Functions - PowerPoint PPT Presentation

1 / 21
About This Presentation
Title:

Predefined MATLAB Functions

Description:

ceil(x), floor(x) rem(x,y) exp(x) log(x), log2(x), log10(x) 206_M3. 3. Trigonometric Functions ... Angle in radians (180 degrees = pi radians) sin(x), cos(x) ... – PowerPoint PPT presentation

Number of Views:258
Avg rating:3.0/5.0
Slides: 22
Provided by: drron6
Category:

less

Transcript and Presenter's Notes

Title: Predefined MATLAB Functions


1
Predefined MATLAB Functions
  • ELEC 206
  • Computer Applications for Electrical Engineers
  • Dr. Ron Hayne

2
Elementary Math Functions
  • abs(x)
  • sqrt(x)
  • sign(x)
  • round(x), fix(x)
  • ceil(x), floor(x)
  • rem(x,y)
  • exp(x)
  • log(x), log2(x), log10(x)

3
Trigonometric Functions
  • Angle in radians (180 degrees pi radians)
  • sin(x), cos(x), tan(x)
  • asin(x), acos(x), atan(x)
  • Angle in degrees
  • sind(x), cosd(x), tand(x)
  • asind(x), acosd(x), atand(x)
  • angle_deg angle_rad(180/pi)
  • angle_rad angle_deg(pi/180)

4
Data Analysis Functions
  • Minimum and Maximum
  • max(x), a,bmax(x), max(x,y)
  • min(x), a,bmin(x), min(x,y)
  • Averages
  • median(x), mean(x), std(x)
  • Sums and Products
  • sum(x), prod(x)
  • cumsum(x), cumprod(x)

5
Data Analysis Functions
  • Sorting
  • sort(x)
  • Size
  • size(x), a,bsize(x)
  • length(x)

6
Random Numbers
  • Uniform Random Numbers
  • rand('seed',n), rand(n), rand(m,n)
  • Interval 0 to 1
  • Interval a to b
  • x (b - a)r a
  • Gaussian Random numbers
  • randn('seed',n), randn(n), randn(m,n)
  • Normal Distribution
  • Mean 0, Standard Deviation 1.0
  • Modified Distribution
  • Mean b, Standard Deviation a
  • x ar b

7
Problem Solving Applied
  • Weather Data
  • Problem Statement
  • Using the data in the file Weather_Data.xls, find
    the total monthly precipitation, the total
    precipitation for the year, and the day on which
    it rained the most.
  • Input/Output Description

Total Monthly Precipitation
Total Precipitation
Day of Most Rain
Weather_Data.xls
8
Problem Solving Applied
  • Hand Example
  • 12x31 Matrix
  • Rows Months
  • Columns Days
  • Hundreths of inches
  • Invalid -99999
  • tot_jan 2.72 in
  • tot_feb 1.66 in
  • tot_janfeb 4.38 in
  • max Jan 3

9
Problem Solving Applied
  • Algorithm Development
  • Import spreadsheet into matrix
  • Change -99999 values to 0
  • Interchange rows and columns
  • Monthly Totals (inches) sum columns/100
  • Yearly Total sum Monthly Totals
  • Find max and location

10
MATLAB Solution
11
MATLAB Solution
  • clc
  • Example 3.3 - Weather Data
  • Find the total precipitation for each month,
    and
  • for the entire year, using a data file
  • wdWeather_Data
  • wd(2,29)0 Change -99999 values to 0
  • wd(2,30)0
  • wd(2,31)0
  • wd(4,31)0
  • wd(6,31)0
  • wd(9,31)0
  • wd(11,31)0

12
MATLAB Solution
  • Use transpose operator to change rows to
    columns
  • wd wd'
  • Sum of each column is sum for each month
  • monthly_total sum(wd)/100
  • Find the annual total
  • yearly_total sum(monthly_total)
  • Find the annual maximum, and month
  • maximum_precip,month max(max(wd))
  • Find the annual maximum, and day
  • maximum_precip,day max(max(wd'))
  • Print max data
  • maximum_precip maximim_precip/100
  • month
  • day

13
(No Transcript)
14
Manipulating Matrices
  • Defining Matrices
  • A 1 2 3 4 5 6 (2x3)
  • A 1 2 3
  • 4 5 6
  • B 1 2 3 (1x3)
  • B 1 2 ...
  • 3
  • C A B
  • 1 2 3 4 5 6 1 2 3 (3x3)

15
Manipulating Matrices
  • Changing Matrices
  • D 3 4 5
  • D(2) 8
  • D
  • 3 8 5
  • D(5) 7
  • D
  • 3 8 5 0 7

16
Manipulating Matrices
  • Defining Matrices with the Colon Operator
  • E 14
  • E
  • 1 2 3 4
  • F 0.00.52.0
  • F
  • 0.0 0.5 1.0 1.5 2.0

17
Manipulating Matrices
  • Extracting Data with the Colon Operator
  • G 1 2 3 2 3 4 3 4 5 4 5 6
  • x G(3, )
  • x
  • 3 4 5
  • y G(, 23)
  • y
  • 2 3
  • 3 4
  • 4 5
  • 5 6

18
Manipulating Matrices
  • Extracting Data with the Colon Operator
  • G 1 2 3 2 3 4 3 4 5 4 5
    6
  • G(3,2)
  • ans 4
  • G(7)
  • ans 4
  • G()
  • ans
  • 1
  • 2
  • 3
  • 4
  • 2
  • 3
  • 4
  • 5
  • 3
  • ...

19
Computational Limitations
  • Double Range
  • 10-308 to 10308
  • Exponent Overflow
  • y 2e200
  • y2
  • ans Inf
  • Exponent Underflow
  • x 2e-200
  • x/y
  • ans 0
  • Double Precision
  • eps
  • ans 2.2204e-016
  • Divide by Zero
  • y/0
  • ans Inf
  • 0/0
  • ans NaN

20
Special Values and Functions
  • Special Values
  • pi
  • i
  • j
  • Inf
  • NaN
  • Special Functions
  • clock
  • Year Month Day Hour Minute Seconds
  • date
  • dd-Mth-yyyy

21
Summary
  • MATLAB Functions
  • Math, Trig, Data Analysis, Random Numbers
  • Problem Solving Applied
  • Manipulating Matrices
  • Special Values and Functions
  • End of Chapter Summary
  • MATLAB Summary
  • Characters, Commands and Functions
  • Key Terms
Write a Comment
User Comments (0)
About PowerShow.com