Built-in MATLAB Functions Chapter 3

Slides:



Advertisements
Similar presentations
CMPS 1371 Introduction to Computing for Engineers FUNCTIONS.
Advertisements

Slide deck by Dr. Greg Reese Miami University MATLAB An Introduction With Applications, 5 th Edition Dr. Amos Gilat The Ohio State University Chapter 3.
Introduction to MATLAB
Lecture 6 MATLAB functions Basics of Built-in Functions, Help Feature, Elementary Functions (e.g., Polynomials, Trigonometric Functions), Data Analysis,
Concatenation MATLAB lets you construct a new vector by concatenating other vectors: – A = [B C D... X Y Z] where the individual items in the brackets.
Lecture 4 Sept 7 Chapter 4. Chapter 4 – arrays, collections and indexing This chapter discusses the basic calculations involving rectangular collections.
Introduction to MATLAB ENGR 1187 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Builtin and user defined functions
Engineering Analysis ENG 3420 Fall 2009 Dan C. Marinescu Office: HEC 439 B Office hours: Tu-Th 11:00-12:00.
Predefined MATLAB Functions ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
Copyright © The McGraw-Hill Companies, Inc. Permission required for reproduction or display. A Concise Introduction to MATLAB ® William J. Palm III.
MATLAB Tutorials Session I Introduction to MATLAB Rajeev Madazhy Dept of Mechanical Engineering LSU.
Copyright © 2006 The McGraw-Hill Companies, Inc. Permission required for reproduction or display. 1 MATLAB Programming Chapter 2.
1 TAC2000/ Protocol Engineering and Application Research Laboratory (PEARL) MATH Functions in C Language.
Recap Graphic Window Edit Window Start Button Matrices in MATLAB Scalar Operations Order of Operations Array Operations Matrix Addition Matrix Multiplication.
Introduction to MATLAB Computational Probability and Statistics CIS 2033 Section 003 Djordje Gligorijevic, Temple University, Fall 2015.
ENG 1181 College of Engineering Engineering Education Innovation Center MATLAB is a powerful program for numerical computations, plotting and programming.
Introduction to MATLAB ENGR 1181 MATLAB 1. Programming In The Real World Programming is a powerful tool for solving problems in every day industry settings.
Introduction to Engineering MATLAB – 1 Introduction to MATLAB Agenda Introduction Arithmetic Operations MATLAB Windows Command Window Defining Variables.
MATLAB An Introduction to MATLAB (Matrix Laboratory) 1.
Matlab for Engineers Built-in Matlab Functions Chapter 3.
1 MATLAB Basics. 2 MATLAB Documentation /help/techdoc/ Matrix Algebra.
Matrix Computations ELEC 206 Computer Applications for Electrical Engineers Dr. Ron Hayne.
MATLAB Basics. The following screen will appear when you start up Matlab. All of the commands that will be discussed should be typed at the >> prompt.
1 Functions ผศ. ดร. อนันต์ ผลเพิ่ม Anan Phonphoem
MATLAB Trigonometry, Complex Numbers and Array Operations.
Introduction to Matlab Module #2 Page 1 Introduction to Matlab Module #2 – Arrays Topics 1.Numeric arrays (creation, addressing, sizes) 2.Element-by-Element.
Matlab for Engineers Manipulating Matlab Matrices Chapter 4.
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Recap Script M-file Editor/Debugger Window Cell Mode Chapter 3 “Built in MATLAB Function” Using Built-in Functions Using the HELP Feature Window HELP.
Recap Sum and Product Functions Matrix Size Function Variance and Standard Deviation Random Numbers Complex Numbers.
Introduction to Matlab
MATLAB for Engineers 4E, by Holly Moore. © 2014 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved. This material is protected by Copyright.
Visual Basic I Programming
Lec-10 Manipulations of Matlab Matrices. Built-in functions The chapter will be covered quickly There are quite a few built-in functions in MATLAB – If.
C++ Programming Lecture 9 Functions – Part I By Ghada Al-Mashaqbeh The Hashemite University Computer Engineering Department.
(The Transpose Operator) 1 >> C=[ ; ; ] C = >> D=C' D =
Lecture 24: Rough and Ready Analysis. MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log.
MATLAB Lecture 1 염익준. Introduction MATLAB (MATrix LABoratory) a special purpose computer program optimized to perform engineering and scientific calculations.
Some “What’s the output” questions to get the day started… >>A = [1 2 3; 3 5 6] This statement stores the matrix: 1. A= 2. A= 3. A= 4. A= Ask Garvin’s.
Matrix Mayhem: Outline
Part(2) MATLAB.
Introduction To MATLAB
Arithmetic Operations
Introduction to Matlab
Manipulating MATLAB Matrices Chapter 4
Numeric, Cell and Structural Arrays One of the strenghts of MATLAB is the capabilty to handle collection of numbers called ARRAYS. MATLAB refers to scalars,
ECE 1304 Introduction to Electrical and Computer Engineering
Modelling and Simulating Social Systems with MATLAB
BIL 104E Introduction to Scientific and Engineering Computing
Chapter 3 Arrays and Vectors
Computer Simulation Lab
Other Kinds of Arrays Chapter 11
INTRODUCTION TO BASIC MATLAB
Seminar 1 for DCSP Using Matlab.
MATLAB DENC 2533 ECADD LAB 9.
User Defined Functions
Digital Image Processing using MATLAB
Introduction to MATLAB [Vectors and Matrices] Lab 2
Fourth Year – Software Engineering
Communication and Coding Theory Lab(CS491)
Introduction to MATLAB
Introduction to Matlab
Announcements P3 due today
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
-seminar 1 for digital signal processing
月夜憶舍弟 戍鼓斷人行,邊秋一雁聲。 露從今夜白,月是故鄉明。 有弟皆分散,無家問死生。 寄書長不達,況乃未休兵。 杜甫
Computer Simulation Lab
Introduction to Matlab
CHAPTER 3 Built-in MATLAB Functions
Presentation transcript:

Built-in MATLAB Functions Chapter 3 Welcome to MATLAB for Engineers – Chapter Three. In this chapter we’ll explore a number of the functions built into MATLAB.

Objectives After studying this chapter you should be able to: Use a variety of common mathematical functions Understand and use trigonometric functions in MATLAB Compute and use statistical and data analysis functions Generate uniform and Gaussian random-number matrices Understand the computational limits of MATLAB Recognize and be able to use the special values and functions built into MATLAB

3.1 Using Built-in Functions MATLAB uses function names consistent with most major programming languages For example sqrt sin cos log Sin and cos are also standard function names, as is l-o-g for natural logarithm.

Function Input can be either scalars or matrices Let’s take a look at the square root function.

Function Input can be either scalars or matrices Let’s take a look at the square root function.

Using Predefined Functions Functions consist of Name Input argument(s) Output In MATLAB sqrt(4) sqrt (x) = result All functions consist of three basic parts ans = 2

Some functions require multiple inputs Remainder function returns the remainder in a division problem For example the remainder of 10/3, is 1

Some functions return multiple results size function determines the number of rows and columns

You can assign names to the output The variable names are arbitrary – choose something that makes sense in the context of your problem

Nesting Functions

3.2 Using the Help Feature 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

From the Command Window

From the Help Menu

The windowed help function can also be accessed using the doc command

3.3 Elementary Math Functions 3.3.1 Common Computations abs(x) absolute value sign(x) plus or minus exp(x) ex log(x) natural log log10(x) log base 10 As in most computer languages, log(x) is the syntax for the natural log – there is no ln function defined in MATLAB

3.3.2 Rounding Functions round(x) fix(x) floor(x) ceil(x)

3.3.3 Discrete Mathematics factor(x) gcd(x,y) greatest common denominator lcm(x) lowest common multiple rats(x) represent x as a fraction factorial(x) nchoosek(n,k) primes(x) isprime(x)

3.4 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

3.5 Data Analysis Functions max(x) min(x) mean(x) median(x) sum(x) prod(x) sort(x) sortrows(x) std(x) var(x)

3.5.1 Max and Min When the max function is used with a vector (either a row or a column), it returns the maximum value in the vector

When x is a matrix, the max is found for each column

max value index number where the max value occurs The max function can also be used to determine where the maximum occurs

Vector of maximums Vector of row numbers

3.5.4 Sorting Values It’s easy to sort data in MATLAB, using the sort function The default is to sort in ascending order

To sort in descending order, just add the word ‘descend’ in the second input field

MATLAB is column dominant, so when sort is used with a 2-D matrix, each column is sorted in ascending order

The sortrows function allows you to sort entire rows, based on the value in a specified column. The default sorting column is #1

In this example the matrix is sorted in ascending order, based on the second column

Notice that this is a different strategy than that used by the sort function! To sort based on descending order, place a negative sign in front of the column number

3.5.5 Determining Matrix Size size(x) number of rows and columns length(x) biggest dimension numel(x) total number of elements

3.5.6 Variance and Standard Deviation std(x) var(x) Variance and standard deviation are statistical measures of variation in data. The definition of variance

Standard Deviation This is a representation of data that varies in what is called a normal distribution. It’s the bell curve, that’s often used by teachers to analyze student scores.

3.6 Random Numbers rand(x) rand(n,m) 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 MATLAB can generate random numbers that are distrubuted using two schemes . The first is an even distribution and uses the rand function

If you create a very large matrix of random numbers using the rand function, the average value will be 0.5 Notice that we created a 1 by 107 matrix, which required 2 inputs (rand(1,10e6)). If we had entered a single value (rand(10e6)) the result would have been a 1x107 by 1x107 matrix.

Gaussian Random numbers randn(n) Also called a normal distribution Generates numbers with a mean of 0 and a standard deviation of 1

First generate an array of 10 million gaussian random numbers Use MATLAB to take the mean, and notice that it is very close to 0 Use MATLAB to find the standard deviation, and notice that it is very close to 1

The hist function creates a histogram of the input data

To generate random numbers between other bounds… a and b are the upper and lower bounds r is the array of random numbers

Although the average is the same for each of these data sets, they have a different standard deviation

More about Manipulating Matrices Converts a two dimensional matrix to a single column

3.7 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

3.8 Computational Limits MATLAB’s computational range on most computers is: 10-308 10308 When you divide by 0, the computer returns Inf

Check the limits on your computer with these commands realmax realmin intmax intmin

When using very large or very small numbers the result may depend on the order of operation

3.9 Special Values and Miscellaneous 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.

Summary MATLAB contains a wide array of predefined functions Elementary Math Functions Trigonometric Functions Data Analysis Functions Random Numbers Complex Numbers

Summary The colon operator allows you to manipulate matrices

Summary Computational Limits Special Values and Functions