Ch03 Functions 3rd Ed
Ch03 Functions 3rd Ed
Functions
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
Chapter 3
-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
80
Average = 50
Average = 50 80
# of students
60
Score
60
40
40
100 20
20
0 0
200 0 200 400 600 800 1000 0 20 40 60 80 100
Student Number Score
300
100 120
400 80
100
80 Average = 50
# of students
Average = 50
500 60
Score
100 200 300 400 500
60
40
40
20
20
0 0
0 200 400 600 800 1000 0 20 40 60 80 100
Student Number Score
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson
Education, Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change Objectives
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2
-1.5
-1
to:
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
3.1 Using Built-in Functions
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
For example
100 • sqrt
200
300
400
• sin
500
100 200 300 400 500
• cos
• log
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Function Input can be either
scalars or matrices
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Function Input can be either
scalars or matrices
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Using Predefined
Functions
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• Functions consist of
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• Name
• Input argument(s)
100
• Output In MATLAB
200
300
400
500
100 200 300 400 500
sqrt (x)= result sqrt(4)
ans = 2
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Some functions require
multiple inputs
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
10/3, is 1
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Some functions return
multiple results
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
You can assign names to
the output
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change Nesting Functions
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change
3.2 Using the Help Feature
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2
-1.5
-1
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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
From the Help Menu
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
The windowed help function
-5
-4.5
Rate of Change
can also be accessed using
the doc command
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
3.3 Elementary Math
Functions
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
300
400
500
100 200 300 400 500
• log(x) natural log
• log10(x) log base 10
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change 3.3.2 Rounding Functions
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• round(x)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• fix(x)
• floor(x)
• ceil(x)
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change
3.3.3 Discrete Mathematics
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
• factor(x)
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
• nchoosek(n,k)
300
400
• primes(x)
500
100 200 300 400 500
• isprime(x)
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change
3.4 Trigonometric Functions
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
• sin(x) sine
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• cos(x) cosine
• tan(x) tangent
• asin(x) inverse sine
100 • sinh(x) hyperbolic sine
200
300
• asinh(x) inverse hyperbolic sine
400
500
• sind(x) sine with degree input
• asind(x) inverse sin with degree
100 200 300 400 500
output
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change
3.5 Data Analysis Functions
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• max(x) • std(x)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• min(x) • var(x)
• mean(x)
100 • median(x)
•
200
300
sum(x)
400
500
100 200 300 400 500 • prod(x)
• sort(x)
• sortrows(x)
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
3.5.1 Max and Min
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
max value
200
300
400
500
100 200 300 400 500 The max function can also be used to
determine where the maximum occurs
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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
Vector of maximums
300
400
500
100 200 300 400 500
-4.5
Rate of temperature change, degrees/hour
-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
3.5.4 Sorting Values
400
500
100 200 300 400 500
-4.5
Rate of temperature change, degrees/hour
-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
To sort in descending order, just add the word
500
100 200 300 400 500
‘descend’ in the second input field
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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
-4.5
Rate of temperature change, degrees/hour
-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
500
-4.5
Rate of temperature change, degrees/hour
-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
-4.5
Rate of temperature change, degrees/hour
-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
200
300
400
500
100 200 300 400 500
To sort based on
descending order, place a
negative sign in front of the
column number
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change
3.5.5 Determining Matrix Size
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
and columns
• length(x) biggest dimension
100
200
400
500
elements
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
3.5.6 Variance and Standard
-5
-4.5
Rate of Change
Deviation
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• std(x)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• var(x) 2
x
100 2
k
200
300
2 k 1
400
N 1
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change Standard Deviation
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change 3.6 Random Numbers
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• rand(x)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
• Returns an n by m matrix of random
500
100 200 300 400 500 numbers
• These random numbers are
evenly distributed
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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
500
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• randn(n)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
of 0 and a standard deviation of 1
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
First generate an
-1
-0.5
0
array of 10 million
gaussian random
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
numbers
Use MATLAB to
take the mean, and
100
notice that it is very
200 close to 0
300
Use MATLAB to
400
500
deviation, and
notice that it is
very close to 1
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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
The hist function creates a
histogram of the input data
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
Rate of Change
To generate random
numbers between other
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
bounds…
-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
x b a r a
a and b are the upper and lower
400
500
100 200 300 400 500
bounds
r is the array of random numbers
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Test Scores Distribution of Test Scores
100 120
Rate of Change
-5
100
-4.5 80
Average = 50
Rate of temperature change, degrees/hour
-4
80
-3.5
Average = 50
# of students
-3
-2.5
60
Score
60
-2
-1.5
-1
-0.5
40
0
40
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
20
20
0 0
0 200 400 600 800 1000 0 20 40 60 80 100
Student Number Score
100 120
100
80
100
80 Average = 50
# of students
Average = 50
200 60
Score
300
60
40
400 40
500 20
100 200 300 400 500 20
0 0
0 200 400 600 800 1000 0 20 40 60 80 100
Student Number Score
Although the average is the same for each of these data sets,
they have a different standard deviation
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
More about Manipulating
Matrices
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• M(:)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change 3.7 Complex Numbers
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• complex(x,y)
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• real(A) used if A is a
complex
number
100
• imag(A)
200
300
• isreal(A)
imaginary
400
500
100 200 300 400 500
• conj(A)
real
• abs(A)
• angle(A)
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change 3.8 Computational Limits
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
300
400
• When you divide by 0, the
500
100 200 300 400 500
computer returns Inf
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Check the limits on your
-5
-4.5
Rate of Change
-4
-3.5
-3
-2.5
-2
-1.5
• realmax
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• realmin
• intmax
• intmin
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
When using very large or very small
-5
Rate of Change
numbers the result may depend on
the order of operation
-4.5
Rate of temperature change, degrees/hour
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
3.9 Special Values and
Miscellaneous Functions
Rate of Change
-5
-4.5
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
• pi
-1.5
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
• i,j
Hint: The function i is the
• Inf
most common of these
• NaN
100
200
• clock
functions to be
300
400
• date
unintentionally renamed
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change Summary
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
predefined functions
• Elementary Math Functions
100
• Trigonometric Functions
200
300
• Data Analysis Functions
400
500
• Random Numbers
100 200 300 400 500
• Complex Numbers
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change Summary
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
-0.5
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour
manipulate matrices
100
200
300
400
500
100 200 300 400 500
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.
-5
-4.5
Rate of Change Summary
Rate of temperature change, degrees/hour
-4
-3.5
-3
-2.5
-2
-1.5
• Computational Limits
-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 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited
reproduction, storage in a retrieval system, or transmission in any form or by any means, electronic, mechanical, photocopying,
recording, or likewise. For information regarding permission(s), write to: Rights and Permissions Department, Pearson Education,
Inc., Upper Saddle River, NJ 07458.