Download as pdf or txt
Download as pdf or txt
You are on page 1of 97

MATLAB Environment

Rate of Change
-5
Rate of temperature change, degrees/hour

-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 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 Objectives
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

After studying this chapter you should be able to


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Start the MATLAB program and solve simple problems


in the command window
• Understand MATLAB’s use of matrices
• Identify and use the various MATLAB windows
100

200
• Define and use simple matrices
300 • Name and use variables
• Understand the order of operations in MATLAB
400

500
100 200 300 400 500

• Understand the difference between scalar, array and


matrix calculations in MATLAB

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 Objectives - continued
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

After studying this chapter you should be able to


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Express numbers in either floating-point or scientific


notation
• Adjust the format used to display numbers in the
command window
100
• Save the value of variables used in a MATLAB session
• Save a series of commands in an M-file
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 In this chapter we’ll…
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Get started with MATLAB


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Explore the MATLAB windows


• Solve some problems using
100

200
MATLAB
• Learn how to save our work
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.
Section 1.1
Getting Started
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• In Windows operating systems click on


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

the desktop icon

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.
MATLAB opens to a default
window configuration
Rate of Change
-5
Rate of temperature change, degrees/hour

-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 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
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

• MATLAB uses a
-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

standard
windows menu
bar
100

200

300
• To exit MATLAB
400
use the close
500

icon
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.
Section 1.2
MATLAB Windows
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• MATLAB uses several different


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

windows to display data,


commands and results.
100

200
• They are not necessarily all open
300

400
at once
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
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5
Workspace Window
0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

Current Folder
Window
Lists files stored in the Command Window
current directory
100 Enter commands at the prompt
200

300

400 MATLAB Windows


500

Command
100 200 300 400 500

History Window
Records all commands
issued in the command
window – including
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
mistakes
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.
Let’s look at the windows
one at a time
Rate of Change
-5
Rate of temperature change, degrees/hour

-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 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 Command Window
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Similar to a scratch pad


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• Once you hit Command


enter, you can’t edit any
Window

commands
100
• You can retype them or use the arrow
200

300
keys to retrieve commands and edit
400

500
them before hitting enter again
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 Command History
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Records the commands you issue


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

in the command window


• When you exit the command
100

200
window, or when you issue
Command History
the clc
300

400
command, the command window
500
100 200 300 400 500
is cleared
• But the command history remains

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 Command History
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• You can transfer commands from


-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 command history to the


command window
– Double click on a command
• It executes immediately
100

200

– Click and drag into the command


300

400

500
100 200 300 400 500
window
• You can edit the command before
executing

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 Workspace Window
Rate of temperature change, degrees/hour

-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

Workspace Window

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
Rate of temperature change, degrees/hour

-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

When you define variables


in the command window,
they are listed in the
100

200

300

400

500
100 200 300 400 500
workspace window

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
Rate of temperature change, degrees/hour

-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

Scalar
100

200 Vector
300

400

500
100 200 300 400 500

2-D
Matrix

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 Current Directory/Folder
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The current folder window is a list


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

of files
• When you try to load information
100
from a file or try to save
information – MATLAB uses the
200

300

400

500
100 200 300 400 500
current folder

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 Document Window
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• If you double click on any variable


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

in the workspace window


MATLAB launches a document
100
window containing the array
editor
200

300

400

500
100 200 300 400 500
• You can edit variables in the array
editor

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.
New Variable
-5
Rate of Change Icon
Rate of temperature change, degrees/hour

-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 Document Window


100

200
displays the variable
300

400
editor
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 Figure Window
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• When Figures are created a new


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

window opens
• It’s extremely easy to create
100

200
graphs in MATLAB
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
Rate of temperature change, degrees/hour

-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

First create a vector of x


values – then a
corresponding vector of
100
y values
200

300

400

500
100 200 300 400 500
Note: The semicolon
suppresses the output from
each command

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
Rate of temperature change, degrees/hour

-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 makes it easy to modify


graphs by adding
•Titles
•Axis labels
•Legends
100

200

300
•Other types of annotations
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 Editing Window
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• This window allows you to type


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

and save a series of commands


without executing them
100

200
• There are several ways to open
300

400
an editing window
500
100 200 300 400 500
– From the file menu
– With the new file icon

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
Rate of temperature change, degrees/hour

-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
Open an editing window
300
from the file menu or with
400 the new file icon
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
Rate of temperature change, degrees/hour

-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

New file icon

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
Rate of temperature change, degrees/hour

-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

Save and Run

100

200

300

400

500
100 200 300 400 500
Write your code in the editing window,
then run it using the Save and Run icon

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.
Section 1.3
-5
Rate of Change

Solving Problems with MATLAB


Rate of temperature change, degrees/hour

-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

• We’ve already solved some


simple problems
100

200
• We need to understand how
300

400
MATLAB works to solve more
500
100 200 300 400 500
complicated problems

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 Variables
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• MATLAB allows you to assign a


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

value to a variable
• A=3
100

200
• Should be read as A is assigned a
300

400
value of 3
• Use the variables in subsequent
500
100 200 300 400 500

calculations
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 Naming Variables
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• All names must start with a letter


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• They may contain letters,


numbers and the underscore ( _ )
100

200
• Names are case sensitive
• There are certain keywords you
300

400

can’t use
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.
Use the iskeyword function
for a list of keywords
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1
iskeyword
-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

ans =
'break' 'global'
'case' 'if'
'catch' 'otherwise'
'classdef' 'parfor'
100
'continue' 'persistent'
200
'else' 'return‘
300

'elseif' ‘spmd’
400

'end‘ 'switch'
'try'
500

'for‘
100 200 300 400 500

'function' 'while'

Keywords are not acceptable variable names

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 reassign function
names
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• MATLAB will let you use built-in


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

function names as variables – but


it’s a really bad idea
100

200
• sin = 3 changes sin from a
300

400
function to a variable
500
100 200 300 400 500
name
• clear sin resets sin back to a
function
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.
Practice Exercise 1.2
Which of these names are allowed
-5
Rate of Change

in MATLAB?
Rate of temperature change, degrees/hour

-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
• Test
• if
x
• x
my-book
100
• my_book
200
• x
Thisisoneverylongnamebutisitstillallowed?

300

400
1stgroup
x
500
• group_one

100 200 300 400 500

zzaAbc
• z34wAwy?12#
x x
• sin
bad
• log
idea
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
1.3.2 Matrices in MATLAB
The basic data type
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Group of numbers arranged into


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

rows and columns


• Single Value (Scalar)
100

200
– Matrix with one row and one column
• Vector (One dimensional matrix)
300

400

– One row or one column


500
100 200 300 400 500

• Matrix (Two dimensional)


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 Scalar Calculations
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• You can use MATLAB like you’d


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

use a calculator

100 Command
200
Prompt
300

400

500
100 200 300 400 500
>> 9 + 10
ans=19
Result
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 Assignment Operator
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• To define a variable a we might


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

type
a=1+2
100
which should be read as:
“a is assigned a value of 1+2 “
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.
How is the assignment operator
-5
Rate of Change
different from an equality?
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

• In algebra the equation


-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

x=3+5
means that both sides are the same
• In computers when we say
100
x=3+5
200

300
we are telling the machine to store the
400
value on the right hand side of the
500
100 200 300 400 500
equation in a memory location, and to
name that location 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
Rate of Change Is that really different?
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Yes!!!
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• In algebra this is not a true statement


x=x+1
100
• In computers (assignment statements)
200

300
it means replace the value in the
400

500
memory location named x, with a new
value equal to x+1
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 Order of Operation
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Same as you’ve learned in math


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

class
• Same as your calculator
100

200
– Parentheses first
300

400
– Exponentiation
– Multiplication / division
500
100 200 300 400 500

– Addition / subtraction

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 Order of Operation
Rate of temperature change, degrees/hour

-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

5*(3+6) = 45

5*3+6 = 21
100

200
White space does not matter!!!
300

400

500

5*3 + 6 = 21
100 200 300 400 500

Adding a space around + and – signs makes the


expression more readable

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 Parentheses
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Use only ( )
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• { } and [ ] mean something


different
100

200
• MATLAB does not assume
300

400
operators
500
100 200 300 400 500

5 * (3+4) not 5(3+4)

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 Compute from left to right
Rate of temperature change, degrees/hour

-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

5*6/6*5 = 25

5*6/(6*5) = 1
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
Here’s an example
Find the surface area of a cylinder
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1
r = radius h = height
-0.5

0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5 r=5 h = 10

π r2
2π r * h
100

π r2
200

300

400

500
100 200 300 400 500

SA  2r  2rh  2r (r  h) 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.
-5
Rate of Change Array Operations
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Using MATLAB as a glorified


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

calculator is OK, but its real


strength is in matrix manipulations
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
Rate of temperature change, degrees/hour

-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 create a row vector, enclose a list of values


in brackets
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
Rate of temperature change, degrees/hour

-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
You may use either a space or a
comma as a “delimiter” in a row
300

400

500
vector
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
Rate of temperature change, degrees/hour

-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
Use a semicolon as a delimiter to create a
new row
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
Rate of temperature change, degrees/hour

-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 a semicolon as a delimiter to create a


new row
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
Rate of temperature change, degrees/hour

-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
Hint: It’s easier to keep track of how many
values you’ve entered into a matrix, if you
enter each row on a separate line. The
semicolons are optional

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 Shortcuts
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• While a complicated matrix might have


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

to be entered by hand, evenly spaced


matrices can be entered much more
readily. The command
100

200 b= 1:5
300

400

500
or the command
100 200 300 400 500

b = [1:5]
both return a row matrix
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
Rate of temperature change, degrees/hour

-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
The default increment is 1, but if you
want to use a different increment put
it between the first and final values

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.
To calculate spacing
between elements use…
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• linspace
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• logspace

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
Rate of temperature change, degrees/hour

-4.5

-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
number of elements in
the array
Initial value in the
Final value in the
array
array
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
Rate of temperature change, degrees/hour

-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

number of elements in
the array
100 Initial value in the
200
array expressed Final value in the
300
as a power of 10 array expressed
400
as a power of 10
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
Rate of temperature change, degrees/hour

-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

It is a common mistake to enter the


initial and final values into the
logspace command, instead of
entering the corresponding power of
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
Rate of Change Hint
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• You can include mathematical


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

operations inside a matrix


definition statement.
100

200
• For example
300

400

500

a = [0: pi/10: pi]


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.
Mixed calculations between
scalars and arrays
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• Matrices can be used in many


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

calculations with scalars


• There is no confusion when we
perform addition and subtraction
100

200
• Multiplication and division are a little
300
different
• In matrix mathematics the
400

500
100 200 300 400 500

multiplication operator (*) has a very


specific meaning

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
Rate of temperature change, degrees/hour

-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 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
Rate of temperature change, degrees/hour

-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

Addition between arrays is


performed on
corresponding elements

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
Rate of temperature change, degrees/hour

-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

Multiplication between
arrays is performed on
corresponding elements if
the .* operator is used
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
Rate of temperature change, degrees/hour

-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 interprets * to mean matrix


multiplication. The arrays a and b are
not the correct size for matrix
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.

multiplication in this example


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 Array Operations
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Array multiplication
-1

-0.5

0
0 0.5 1 1.5 2 2.5
time, hour
3 3.5 4 4.5 5
.*
• Array division ./
• Array exponentiation .^
100

200

300

400 In each case the size of the arrays must match


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 matrix capability of MATLAB makes it
-5
Rate of Change

easy to do repetitive calculations


Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• For example, assume you have a


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

list of angles in degrees that you


would like to convert to radians.
100 – First put the values into a matrix.
– Perform the calculation
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
Rate of temperature change, degrees/hour

-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 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
Rate of temperature change, degrees/hour

-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 Either the * or the .* operator can be


300
used for this problem, because it is
400
composed of scalars and a single
matrix
500
100 200 300 400 500

The value of pi is built into MATLAB as


a floating point number, called pi
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 More about pi
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Because pi is an irrational number, it


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

can not be expressed exactly with a


floating point representation
• The MATLAB constant, pi, is really
100

200 an approximation.
300

400

500
• If you find sin(pi) MATLAB returns a
very small number.
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 Transpose
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The transpose operator changes


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

rows to columns or vice versa.

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
Rate of temperature change, degrees/hour

-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
The transpose operator
500
100 200 300 400 500
makes it easy to create
tables

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
Rate of temperature change, degrees/hour

-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

table =[degrees;radians]’ would have given


the same result

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
Rate of temperature change, degrees/hour

-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 transpose
100
operator works on
200
both one dimensional
300 and two dimensional
400 arrays
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 Number Display
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Scientific Notation
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

– Although you can enter any number in


decimal notation, it isn’t always the best
way to represent very large or very small
100 numbers
– In MATLAB, values in scientific notation
200

300

400

500
are designated with an e between the
100 200 300 400 500

decimal number and exponent. (Your


calculator probably uses similar notation.)

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
Rate of temperature change, degrees/hour

-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
It is important to omit blanks between
200
the decimal number and the exponent.
300 For example, MATLAB will interpret
400
6.022 e23
500
100 200 300 400 500
as two values (6.022 and 1023 )

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 Display Format
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Multiple display formats are available


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• No matter what display format you


choose, MATLAB uses double
precision floating point numbers in its
100

200 calculations
300

400

500
• MATLAB handles both integers and
decimal numbers as floating point
100 200 300 400 500

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
Rate of Change Default
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The default format is called short


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• If an integer is entered it is
displayed without trailing zeros
100

200
• If a floating point number is
300

400
entered four decimal digits are
displayed
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 Other formats
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Changing the format affects all


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

subsequent displays
– format long results in 14 decimal
100
digits
– format bank results in 2 decimal
200

300

digits
400

500
100 200 300 400 500

– format short returns the display to


the default 4 decimal digits
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
Really Big and Really Small
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• When numbers become too large or


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

too small for MATLAB to display using


the default format, it automatically
expresses them in scientific notation
• You can force scientific notation with
100

200

– format short e
300

400

– format long e
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 Common Scale Factor
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• For long and short formats, a


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

common scale factor is applied to


the entire matrix if some of the
100
elements become very large, or
very small. This scale factor is
200

300

printed along with the scaled


400

500
100 200 300 400 500

values.

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
Rate of temperature change, degrees/hour

-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
Common Scale
Factor
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 Two other formats
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• format +
-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

• format rat

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.
Spacing in the command
window
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

• The format command also allows


-1.5

-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

us to control how tightly


information is spaced in the
command window
– format compact
100

200

– format loose – (default)


300

400

Notice that the value of A is still


• Most of the examples in this
500
100 200 300 400 500

being displayed using the rat


format, because we haven’t
presentation use format compact changed it back to format short

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.
Section 1.4
Saving Your Work
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• If you save a MATLAB session


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

performed in the command


window, all that is saved are the
100
values of the variables you have
named
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
Rate of temperature change, degrees/hour

-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
Variables are saved,
200

300 not the commands in


400

500
the command window
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
Rate of temperature change, degrees/hour

-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

Save either by using the file menu or...


100

200
Save with a command in the
300

400
command window
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.
MATLAB automatically
saves to a .mat file
Rate of Change
-5
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• If you want to save to another


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

format, such as .dat, you need to


explicitly tell the program
100

200

300 save <file_name> <variable_list> -ascii


400

500
100 200 300 400 500

Again – Remember that the only things being saved are the
values stored in the workspace window – not the commands
from the command window

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 Script M-files
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• If you want to save your work,


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

(the commands you entered)


you need to create an M-file
100

200
• File->New->M-file
300

400
• Type your commands in the edit
window that opens
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
Rate of temperature change, degrees/hour

-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 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
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• The file can be saved into the


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

current folder/directory
• It runs in the command window
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
Rate of temperature change, degrees/hour

-4.5

-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
Save the file using
the save icon, or the
file menu

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
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

-1

-0.5

You can dock the editing


0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

window with the


MATLAB desktop, by
using the docking arrow

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
Rate of temperature change, degrees/hour

-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
This arrangement is
often easier to use
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
Rate of temperature change, degrees/hour

-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
I saved this file as
example.m
time, hour

Notice that it now appears


in the current directory

100

200

300

400

500
100 200 300 400 500
When I
execute the
file, the figure
appears on
top of the
MATLAB
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
desktop
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
Rate of temperature change, degrees/hour

-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

The figure window


can also be docked
onto the MATLAB
MATLAB for Engineers 3E, by Holly Moore. © 2011 Pearson Education, Inc., Upper Saddle River, NJ. All rights reserved.
desktop, using the
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:

docking arrow Rights and Permissions Department, Pearson Education, Inc., Upper Saddle River, NJ 07458.
Rate of Change
-5
Rate of temperature change, degrees/hour

-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

Notice that the command history


window is hidden underneath the
figure, but can be accessed with
the tab
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 Comments
Rate of temperature change, degrees/hour

-4.5

-4

-3.5

-3

-2.5

-2

-1.5

• Be sure to comment your code


-1

-0.5

0
0 0.5 1 1.5 2 2.5 3 3.5 4 4.5 5
time, hour

– Add your name


– Date
100
– Section #
200

300

400
– Assignment #
500
100 200 300 400 500
– Descriptions of what you are doing
and why

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
Rate of temperature change, degrees/hour

-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 % sign identifies comments

You need one on each line


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 Cell Mode
Rate of temperature change, degrees/hour

-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

• Enables the user to execute one


time, hour

section of code at a time


• Especially useful as you debug
100
your code
•To use cell mode you must activate
200

300

the cell toolbar


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 Cell Toolbar
Rate of temperature change, degrees/hour

-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
Cell Dividers
300

400 Be sure to include a space


500
100 200 300 400 500 after the %%

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 Summary
Rate of temperature change, degrees/hour

-4.5

-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
Introduced the MATLAB Windows
• Basic matrix definition
• Save and retrieve MATLAB data

100

200 Create and use script M-files


300

400

500
100 200 300 400 500
• The use of cell mode

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 might also like