You are on page 1of 97

MATLAB Environment

Chapter 2

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

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.

Objectives

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

100

200
300
400
500

100

200

300

400

500

After studying this chapter you should be able to
• 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
• Define and use simple matrices
• Name and use variables
• Understand the order of operations in MATLAB
• 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.

Objectives - continued

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

100

200
300

After studying this chapter you should be able to
• Express numbers in either floating-point or scientific
notation
• Adjust the format used to display numbers in the
command window
• Save the value of variables used in a MATLAB session
• Save a series of commands in an M-file

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.

by Holly Moore.5 -1 -0. NJ 07458. storage in a retrieval system.5 2 2. write to: Rights and Permissions Department.5 5 100 200 300 400 500 100 200 300 400 • Get started with MATLAB • Explore the MATLAB windows • Solve some problems using MATLAB • Learn how to save our work 500 MATLAB for Engineers 3E. or transmission in any form or by any means.In this chapter we’ll… Rate of Change -5 Rate of temperature change.5 time. Upper Saddle River. recording. mechanical.. Pearson Education. electronic. degrees/hour -4. hour 3 3.5 4 4.5 0 0 0. .5 -3 -2. photocopying. For information regarding permission(s).5 -4 -3.5 -2 -1. Upper Saddle River. or likewise. NJ. Inc..5 1 1. Inc. All rights reserved. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. © 2011 Pearson Education.

5 -2 -1.5 0 0 0.5 -1 -0. degrees/hour -4. photocopying.5 -3 -2..5 time.5 2 2. NJ 07458. © 2011 Pearson Education.5 -4 -3. Inc. or transmission in any form or by any means. NJ. Upper Saddle River. Pearson Education. Inc. For information regarding permission(s)..5 1 1. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 5 • In Windows or Apple operating systems click on the desktop icon • In Unix type MATLAB At the shell prompt 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. storage in a retrieval system.1 Getting Started Rate of Change -5 Rate of temperature change. Upper Saddle River. mechanical. electronic. by Holly Moore. . recording. hour 3 3. All rights reserved.5 4 4. write to: Rights and Permissions Department.Section 2. or likewise.

storage in a retrieval system.5 5 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. For information regarding permission(s). mechanical. recording..5 2 2. hour 3 3.5 1 1. Upper Saddle River. Inc. by Holly Moore. NJ. NJ 07458. Upper Saddle River.5 4 4.5 -3 -2. photocopying.5 time. or likewise.MATLAB opens to a default window configuration Rate of Change -5 Rate of temperature change. write to: Rights and Permissions Department. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -1 -0. electronic. Inc..5 -2 -1. All rights reserved. © 2011 Pearson Education. degrees/hour -4. Pearson Education. .5 0 0 0. or transmission in any form or by any means.5 -4 -3.

electronic. Upper Saddle River.5 0 0 0.5 4 4. storage in a retrieval system. write to: Rights and Permissions Department. Pearson Education. by Holly Moore. hour 3 3. NJ.. . recording. degrees/hour -4..5 -1 -0.5 -2 -1. For information regarding permission(s).Rate of Change -5 Rate of temperature change. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 1 1. photocopying. or likewise. All rights reserved. Inc.5 time.5 -4 -3.5 2 2. Upper Saddle River. or transmission in any form or by any means.5 -3 -2. mechanical. © 2011 Pearson Education. Inc. NJ 07458.5 5 100 200 300 400 500 100 200 300 400 500 • MATLAB uses a standard windows menu bar • To exit MATLAB use the close icon MATLAB for Engineers 3E.

5 -1 -0. For information regarding permission(s).5 -4 -3.5 0 0 0. storage in a retrieval system. mechanical. NJ 07458..5 time.5 4 4. recording. by Holly Moore. Inc.Section 2.5 1 1. Inc.. photocopying. All rights reserved. Upper Saddle River. © 2011 Pearson Education. or transmission in any form or by any means. hour 3 3.5 -2 -1. degrees/hour -4. electronic. commands and results. • They are not necessarily all open at once 500 MATLAB for Engineers 3E. . Upper Saddle River. NJ.5 5 100 200 300 400 500 100 200 300 400 • MATLAB uses several different windows to display data.5 2 2. Pearson Education. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.2 MATLAB Windows Rate of Change -5 Rate of temperature change.5 -3 -2. write to: Rights and Permissions Department. or likewise.

Upper Saddle River. storage in a retrieval system. degrees/hour -4. mechanical. Inc.. or mistakes transmission in any form or by any means.5 -4 -3.5 -3 -2.5 Workspace Window -2 -1.5 2 2. hour 3 3.5 1 1. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. NJ.5 time. Upper Saddle River. NJ 07458.5 4 4. recording. by Holly Moore.5 0 0 0. © 2011 Pearson Education. Pearson Education. write to: Rights and Permissions Department. . For information regarding permission(s). photocopying.5 5 Current Folder Window Lists files stored in the current directory 100 Command Window Enter commands at the prompt 200 MATLAB Windows 300 400 500 100 200 300 400 500 Command History Window Records all commands issued in the command window – including MATLAB for Engineers 3E. All rights reserved.5 -1 -0.Rate of Change -5 Rate of temperature change. Inc. electronic. or likewise..

All rights reserved. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. electronic.5 -4 -3. degrees/hour -4. . recording. NJ. © 2011 Pearson Education.5 -3 -2.5 -2 -1. mechanical. Inc.5 4 4.5 2 2..5 0 0 0. Inc. Pearson Education. or likewise. Upper Saddle River.5 5 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. write to: Rights and Permissions Department. NJ 07458.5 time.. photocopying.Let’s look at the windows one at a time Rate of Change -5 Rate of temperature change. hour 3 3. storage in a retrieval system. or transmission in any form or by any means.5 1 1. Upper Saddle River.5 -1 -0. by Holly Moore. For information regarding permission(s).

Upper Saddle River. .5 -3 -2.5 1 1.5 -1 -0. degrees/hour -4. mechanical. Pearson Education.5 0 0 0. Inc.5 -2 -1. storage in a retrieval system. write to: Rights and Permissions Department. Inc. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. by Holly Moore..5 -4 -3. or transmission in any form or by any means. Upper Saddle River. can’t edit any commands • You can retype them or use the arrow keys to retrieve commands and edit them before hitting enter again 500 MATLAB for Engineers 3E. NJ 07458. For information regarding permission(s). recording. © 2011 Pearson Education. All rights reserved. or likewise. hour 3 3. NJ.5 2 2.5 5 100 200 300 400 500 100 200 300 400 • Similar to a scratch pad Commandyou Window • Once you hit enter. electronic.5 time. photocopying.5 4 4.Command Window Rate of Change -5 Rate of temperature change..

Pearson Education. the command window is cleared • But the command history remains MATLAB for Engineers 3E.. or when you issue the clc Command History command. NJ. . or likewise. by Holly Moore.5 -4 -3.. mechanical. recording. or transmission in any form or by any means.5 -3 -2. For information regarding permission(s).5 -1 -0.5 0 0 0. electronic. All rights reserved.5 2 2. photocopying.5 time.5 5 100 200 300 400 500 100 200 300 400 500 • Records the commands you issue in the command window • When you exit the command window. storage in a retrieval system.5 -2 -1. Upper Saddle River. NJ 07458. hour 3 3. Inc.5 1 1.Command History Rate of Change -5 Rate of temperature change. Inc. Upper Saddle River. degrees/hour -4. © 2011 Pearson Education. write to: Rights and Permissions Department.5 4 4. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.

5 -2 -1. NJ. storage in a retrieval system. photocopying.5 -3 -2.5 1 1. by Holly Moore. recording. NJ 07458. or transmission in any form or by any means. Inc. degrees/hour -4. Inc. hour 3 3.5 -1 -0. All rights reserved. or likewise.5 2 2.. write to: Rights and Permissions Department. Upper Saddle River. © 2011 Pearson Education. . electronic.5 0 0 0.5 4 4.5 5 – Double click on a command 100 • It executes immediately 200 300 400 500 • You can transfer commands from the command history to the command window 100 200 300 400 500 – Click and drag into the command window • You can edit the command before executing MATLAB for Engineers 3E.5 time. Pearson Education.5 -4 -3. mechanical.Command History Rate of Change -5 Rate of temperature change. For information regarding permission(s).. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.

electronic. Inc. © 2011 Pearson Education. or transmission in any form or by any means.5 1 1. degrees/hour -4. Inc.5 5 Workspace Window 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.. mechanical. Pearson Education. . Upper Saddle River. photocopying.5 time. by Holly Moore. All rights reserved. NJ.Workspace Window Rate of Change -5 Rate of temperature change. Upper Saddle River.5 2 2.. storage in a retrieval system. hour 3 3.5 4 4. recording. NJ 07458. or likewise.5 -2 -1.5 0 0 0. write to: Rights and Permissions Department.5 -3 -2.5 -4 -3.5 -1 -0. For information regarding permission(s). This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.

NJ 07458. NJ. Upper Saddle River. Upper Saddle River.. . For information regarding permission(s).5 4 4.5 -3 -2.. Pearson Education. Inc.5 -4 -3.Rate of Change -5 Rate of temperature change. 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.5 -1 -0.5 -2 -1. mechanical. by Holly Moore.5 time. © 2011 Pearson Education.5 1 1. recording. Inc. they are listed in the workspace window MATLAB for Engineers 3E. All rights reserved. degrees/hour -4.5 0 0 0. electronic. or likewise. write to: Rights and Permissions Department.5 5 100 200 300 400 500 100 200 300 400 500 When you define variables in the command window. hour 3 3. photocopying. or transmission in any form or by any means.5 2 2.

5 2 2.. or transmission in any form or by any means.5 0 0 0. For information regarding permission(s). hour 3 3.5 4 4. . or likewise. All rights reserved.. Pearson Education.5 time.5 -2 -1.5 5 Scalar 100 Vector 200 300 400 500 100 200 300 400 500 2-D Matrix MATLAB for Engineers 3E. Inc. © 2011 Pearson Education.5 -4 -3.5 -3 -2. mechanical.5 1 1. write to: Rights and Permissions Department. degrees/hour -4.Rate of Change -5 Rate of temperature change. by Holly Moore. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -1 -0. NJ 07458. storage in a retrieval system. NJ. Upper Saddle River. photocopying. recording. Upper Saddle River. Inc. electronic.

.5 1 1.Current Directory/Folder Rate of Change -5 Rate of temperature change. hour 3 3. photocopying. Inc.5 -2 -1. For information regarding permission(s).5 2 2. Inc.5 time. degrees/hour -4. NJ.5 0 0 0.5 5 100 200 300 400 500 100 200 300 400 500 • The current folder window is a list of files • When you try to load information from a file or try to save information – MATLAB uses the current folder MATLAB for Engineers 3E.5 -3 -2. .5 4 4. © 2011 Pearson Education.5 -4 -3. or transmission in any form or by any means. or likewise. storage in a retrieval system.. NJ 07458. All rights reserved. Pearson Education. write to: Rights and Permissions Department. mechanical. Upper Saddle River. by Holly Moore. electronic. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Upper Saddle River. recording.5 -1 -0.

or likewise.5 4 4. Upper Saddle River.. mechanical. Inc. or transmission in any form or by any means. All rights reserved. Inc.5 1 1.5 -3 -2. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. © 2011 Pearson Education. hour 3 3. electronic. by Holly Moore.5 -1 -0.5 2 2.. For information regarding permission(s). photocopying. Pearson Education.Document Window Rate of Change -5 Rate of temperature change.5 5 100 200 300 400 500 100 200 300 400 500 • If you double click on any variable in the workspace window MATLAB launches a document window containing the array editor • You can edit variables in the array editor MATLAB for Engineers 3E. Upper Saddle River. NJ. write to: Rights and Permissions Department.5 -4 -3. NJ 07458.5 -2 -1. storage in a retrieval system.5 0 0 0. recording.5 time. . degrees/hour -4.

.. recording. or transmission in any form or by any means. photocopying. Upper Saddle River. Pearson Education. Inc. electronic. For information regarding permission(s). This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -3 -2.5 -1 -0.5 5 The Document Window displays the variable editor 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. hour 3 3. NJ 07458. write to: Rights and Permissions Department.5 time.5 2 2. Inc.5 1 1.5 -4 -3. Upper Saddle River.5 4 4.5 0 0 0. NJ. All rights reserved. degrees/hour -4. by Holly Moore. mechanical. storage in a retrieval system. or likewise.New Variable Icon Rate of Change -5 Rate of temperature change. © 2011 Pearson Education. .5 -2 -1.

or likewise. storage in a retrieval system. electronic. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. degrees/hour -4.5 0 0 0. hour 3 3. Upper Saddle River. by Holly Moore. © 2011 Pearson Education.5 -1 -0. Upper Saddle River.5 -2 -1. For information regarding permission(s).5 2 2.5 4 4. or transmission in any form or by any means..5 1 1. NJ 07458. All rights reserved.5 time. NJ.. recording.5 -4 -3. Inc. Pearson Education. photocopying.5 -3 -2. mechanical.Figure Window Rate of Change -5 Rate of temperature change. . Inc. write to: Rights and Permissions Department.5 5 100 • When Figures are created a new window opens • It’s extremely easy to create graphs in MATLAB 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.

. Upper Saddle River.5 5 First create a vector of x values – then a corresponding vector of y values 100 200 300 400 500 100 200 300 400 500 Note: The semicolon suppresses the output from each command MATLAB for Engineers 3E. write to: Rights and Permissions Department. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Pearson Education. recording. photocopying. or likewise. degrees/hour -4. mechanical.5 -2 -1.5 0 0 0.5 -4 -3. or transmission in any form or by any means. hour 3 3. Upper Saddle River. NJ.5 1 1.Rate of Change -5 Rate of temperature change. Inc.. Inc. For information regarding permission(s). .5 2 2. storage in a retrieval system.5 4 4. by Holly Moore.5 -1 -0.5 -3 -2. All rights reserved. electronic. NJ 07458. © 2011 Pearson Education.5 time.

5 5 Matlab makes it easy to modify graphs by adding •Titles •Axis labels 100 •Legends 200 •Other types of annotations 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. All rights reserved. NJ 07458. Inc. Pearson Education. Inc.5 -4 -3. or likewise. write to: Rights and Permissions Department.5 -1 -0. Upper Saddle River.5 -2 -1.5 0 0 0. storage in a retrieval system. © 2011 Pearson Education. hour 3 3. Upper Saddle River.5 time.5 -3 -2. recording. or transmission in any form or by any means. electronic. photocopying. mechanical. NJ. degrees/hour -4.5 4 4. For information regarding permission(s)..5 1 1.5 2 2.Rate of Change -5 Rate of temperature change.. by Holly Moore. . This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.

degrees/hour -4. or transmission in any form or by any means.. NJ. write to: Rights and Permissions Department.5 -4 -3. Upper Saddle River.Editing Window Rate of Change -5 Rate of temperature change. All rights reserved.5 -2 -1. mechanical. For information regarding permission(s).5 time.5 0 0 0.5 1 1.5 5 100 200 300 400 500 100 200 300 400 500 • This window allows you to type and save a series of commands without executing them • There are several ways to open an editing window – From the file menu – With the new file icon MATLAB for Engineers 3E. electronic. Upper Saddle River.5 2 2. NJ 07458.5 4 4. Pearson Education. or likewise.5 -3 -2. hour 3 3. Inc.. recording. storage in a retrieval system. photocopying. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. by Holly Moore.5 -1 -0. © 2011 Pearson Education. . Inc.

5 0 0 0.5 -2 -1. Upper Saddle River. or transmission in any form or by any means. All rights reserved. electronic.5 1 1. or likewise. recording. Upper Saddle River. hour 3 3. © 2011 Pearson Education. Inc. .5 -4 -3. NJ. write to: Rights and Permissions Department. For information regarding permission(s). NJ 07458.5 4 4. Inc.. photocopying. degrees/hour -4.5 time.Rate of Change -5 Rate of temperature change.5 2 2. 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.5 -1 -0..5 5 100 Open an editing window from the file menu or with the new file icon 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.5 -3 -2. by Holly Moore. mechanical. Pearson Education.

5 0 0 0.5 2 2.5 time. NJ 07458.5 -2 -1. mechanical. photocopying. degrees/hour -4... © 2011 Pearson Education. write to: Rights and Permissions Department.Rate of Change -5 Rate of temperature change. storage in a retrieval system. . All rights reserved. or transmission in any form or by any means. electronic. Upper Saddle River. For information regarding permission(s). NJ.5 1 1.5 -3 -2. recording. hour 3 3.5 5 New file icon 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Pearson Education.5 -4 -3. Inc.5 -1 -0.5 4 4. or likewise. by Holly Moore. Upper Saddle River. Inc.

Inc. Inc. For information regarding permission(s).. by Holly Moore. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -4 -3.Rate of Change -5 Rate of temperature change. © 2011 Pearson Education.5 time. recording. All rights reserved. photocopying. hour 3 3.5 5 Save and Run 100 200 300 400 500 100 200 300 400 500 Write your code in the editing window.5 2 2. Pearson Education. NJ. write to: Rights and Permissions Department.5 4 4. degrees/hour -4. electronic. or likewise.5 -3 -2.5 1 1. or transmission in any form or by any means. .5 -1 -0. NJ 07458. mechanical. then run it using the Save and Run icon MATLAB for Engineers 3E..5 -2 -1.5 0 0 0. Upper Saddle River. storage in a retrieval system.

Upper Saddle River.5 2 2. photocopying. hour 3 3. Inc..5 -3 -2. mechanical.5 -4 -3.5 1 1. Upper Saddle River. write to: Rights and Permissions Department.5 0 0 0.3 Solving Problems with MATLAB Rate of Change -5 Rate of temperature change. All rights reserved. degrees/hour -4. storage in a retrieval system.5 -2 -1.5 -1 -0. NJ 07458. recording.5 4 4.Section 2. or likewise.5 time. electronic. NJ. For information regarding permission(s). This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Pearson Education.. © 2011 Pearson Education. Inc. .5 5 100 200 300 400 500 100 200 300 400 500 • We’ve already solved some simple problems • We need to understand how MATLAB works to solve more complicated problems MATLAB for Engineers 3E. or transmission in any form or by any means. by Holly Moore.

NJ. mechanical. hour 3 3. storage in a retrieval system. © 2011 Pearson Education.5 5 100 200 300 400 500 100 200 300 400 500 • MATLAB allows you to assign a value to a variable • A=3 • Should be read as A is assigned a value of 3 • Use the variables in subsequent calculations MATLAB for Engineers 3E. degrees/hour -4.5 -3 -2.5 2 2.5 4 4. write to: Rights and Permissions Department. recording.5 time. .. by Holly Moore.5 1 1. Pearson Education. photocopying. All rights reserved. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -4 -3. NJ 07458.5 -1 -0.5 0 0 0.5 -2 -1.Variables Rate of Change -5 Rate of temperature change. Upper Saddle River.. or transmission in any form or by any means. Inc. For information regarding permission(s). Upper Saddle River. or likewise. electronic. Inc.

or transmission in any form or by any means.. photocopying. NJ 07458. © 2011 Pearson Education. by Holly Moore. Inc.Naming Variables Rate of Change -5 Rate of temperature change..5 5 100 200 300 400 500 100 200 300 400 500 • All names must start with a letter • They may contain letters. Upper Saddle River.5 1 1. degrees/hour -4.5 4 4. recording.5 -4 -3.5 0 0 0. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 time. . or likewise. numbers and the underscore ( _ ) • Names are case sensitive • There are certain keywords you can’t use MATLAB for Engineers 3E. Inc. storage in a retrieval system. mechanical. Upper Saddle River.5 -3 -2. write to: Rights and Permissions Department.5 -2 -1. Pearson Education. For information regarding permission(s). NJ. All rights reserved. electronic.5 2 2.5 -1 -0. hour 3 3.

5 0 0 0. write to: Rights and Permissions Department.5 1 1.5 -3 -2. hour 3 3. Inc. photocopying. © 2011 Pearson Education.5 -1 -0. mechanical.5 5 100 200 300 400 500 100 200 300 400 500 ans = 'break' 'case' 'catch' 'classdef' 'continue' 'else' 'elseif' 'end‘ 'for‘ 'function' 'global' 'if' 'otherwise' 'parfor' 'persistent' 'return‘ ‘spmd’ 'switch' 'try' 'while' Keywords are not acceptable variable names MATLAB for Engineers 3E. Inc. NJ 07458. 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.. Upper Saddle River. or likewise. Pearson Education.5 iskeyword -2 -1.5 time.. recording. All rights reserved. electronic. or transmission in any form or by any means.Use the iskeyword function for a list of keywords Rate of Change -5 Rate of temperature change. Upper Saddle River.5 -4 -3.5 4 4. . degrees/hour -4. For information regarding permission(s). by Holly Moore. NJ.5 2 2.

mechanical. storage in a retrieval system. NJ 07458. or transmission in any form or by any means.5 -4 -3. Upper Saddle River. NJ. degrees/hour -4. hour 3 3. by Holly Moore.5 -2 -1.5 2 2. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction...5 1 1. Upper Saddle River. Inc.5 -3 -2. or likewise.5 5 100 200 300 400 500 100 200 300 400 500 • MATLAB will let you use built-in function names as variables – but it’s a really bad idea • sin = 3 changes sin from a function to a variable name • clear sin resets sin back to a function MATLAB for Engineers 3E.5 -1 -0.5 4 4. photocopying. All rights reserved.5 time. write to: Rights and Permissions Department. . © 2011 Pearson Education. For information regarding permission(s). electronic. Inc.5 0 0 0.You can reassign function names Rate of Change -5 Rate of temperature change. recording. Pearson Education.

storage in a retrieval system. © 2011 Pearson Education. recording.5 4 4. Upper Saddle River.5 time.5 5 100 200 300 400 500 100 200 300 400 500 • • • • • • • • • • • • test Test ifx x my-book my_book Thisisoneverylongnamebutisitstillallowed?x x 1stgroup group_one zzaAbc z34wAwy?12# x x sin bad log idea MATLAB for Engineers 3E. photocopying.. write to: Rights and Permissions Department. electronic.5 -1 -0. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. NJ.5 -3 -2. Inc.2 Which of these names are allowed in MATLAB? Rate of Change -5 Rate of temperature change. Upper Saddle River. by Holly Moore. Pearson Education. mechanical. degrees/hour -4. or transmission in any form or by any means.Practice Exercise 2. Inc.5 -2 -1. NJ 07458.5 1 1.5 -4 -3. or likewise. All rights reserved.5 0 0 0. hour 3 3.5 2 2. .. For information regarding permission(s).

or transmission in any form or by any means. Pearson Education. NJ 07458. NJ. © 2011 Pearson Education. storage in a retrieval system.2. For information regarding permission(s).5 -3 -2. photocopying. recording.5 0 0 0. by Holly Moore.5 -1 -0.5 1 1.5 -2 -1..3. write to: Rights and Permissions Department. Upper Saddle River. electronic. Inc. .5 4 4. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Upper Saddle River..5 5 – Matrix with one row and one column 100 200 • Vector (One dimensional matrix) 300 400 500 • Group of numbers arranged into rows and columns • Single Value (Scalar) 100 200 300 400 500 – One row or one column • Matrix (Two dimensional) MATLAB for Engineers 3E. degrees/hour -4. mechanical.5 -4 -3. or likewise.5 2 2.2 Matrices in MATLAB The basic data type Rate of Change -5 Rate of temperature change. Inc.5 time. All rights reserved. hour 3 3.

write to: Rights and Permissions Department.5 -1 -0.. degrees/hour -4.Scalar Calculations Rate of Change -5 Rate of temperature change. . Inc.5 5 • You can use MATLAB like you’d use a calculator Command Prompt 100 200 300 >> 9 + 10 ans=19 400 500 100 200 300 400 500 Result MATLAB for Engineers 3E.5 -3 -2.5 -4 -3.5 1 1. All rights reserved. NJ.5 time. by Holly Moore. Upper Saddle River.5 -2 -1. electronic. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. photocopying. © 2011 Pearson Education. For information regarding permission(s).5 2 2.5 4 4. storage in a retrieval system.. Pearson Education. NJ 07458. recording. or likewise. or transmission in any form or by any means. Upper Saddle River.5 0 0 0. hour 3 3. mechanical. Inc.

. recording. by Holly Moore.. Upper Saddle River. electronic. All rights reserved.5 -4 -3. degrees/hour -4. or likewise. NJ.5 2 2.5 -2 -1.5 0 0 0. storage in a retrieval system. or transmission in any form or by any means. mechanical.5 time.Assignment Operator Rate of Change -5 Rate of temperature change. Inc.. For information regarding permission(s).5 1 1.5 -3 -2. NJ 07458. hour 3 3.5 -1 -0. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 5 100 200 300 400 500 100 200 300 400 • To define a variable a we might type a=1+2 which should be read as: “a is assigned a value of 1+2 “ 500 MATLAB for Engineers 3E. © 2011 Pearson Education. Pearson Education.5 4 4. Upper Saddle River. write to: Rights and Permissions Department. photocopying. Inc.

5 2 2.5 0 0 0.5 5 100 200 300 400 500 100 200 300 400 500 • In algebra the equation x=3+5 means that both sides are the same • In computers when we say x=3+5 we are telling the machine to store the value on the right hand side of the equation in a memory location. Inc. write to: Rights and Permissions Department. or transmission in any form or by any means.How is the assignment operator different from an equality? Rate of Change -5 Rate of temperature change. degrees/hour -4.5 time. electronic. NJ. Pearson Education. Upper Saddle River.5 -1 -0. by Holly Moore. photocopying. . For information regarding permission(s). Inc.5 -4 -3.. storage in a retrieval system. All rights reserved. Upper Saddle River..5 -2 -1. and to name that location x MATLAB for Engineers 3E.5 4 4. hour 3 3.5 -3 -2. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. recording.5 1 1. NJ 07458. or likewise. mechanical. © 2011 Pearson Education.

5 -3 -2.5 -1 -0.5 time. Pearson Education. recording. with a new value equal to x+1 MATLAB for Engineers 3E. © 2011 Pearson Education. Inc. Upper Saddle River. NJ 07458. For information regarding permission(s). hour 3 3.5 -2 -1. Inc. write to: Rights and Permissions Department.. All rights reserved.5 4 4. mechanical. or likewise. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 2 2. degrees/hour -4. photocopying. NJ.5 5 100 200 300 400 500 100 200 300 400 500 • Yes!!! • In algebra this is not a true statement x=x+1 • In computers (assignment statements) it means replace the value in the memory location named x. .Is that really different? Rate of Change -5 Rate of temperature change.5 1 1. electronic.5 0 0 0. storage in a retrieval system. Upper Saddle River. or transmission in any form or by any means.5 -4 -3. by Holly Moore..

All rights reserved. recording. Pearson Education.5 -2 -1.5 2 2. photocopying.5 -4 -3.5 4 4..5 0 0 0. electronic. hour 3 3. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -1 -0. For information regarding permission(s).5 -3 -2.5 1 1. degrees/hour -4. mechanical. . or likewise. by Holly Moore. storage in a retrieval system. write to: Rights and Permissions Department.5 time. NJ.Order of Operation Rate of Change -5 Rate of temperature change. © 2011 Pearson Education. or transmission in any form or by any means.. NJ 07458. Upper Saddle River. Upper Saddle River. Inc. Inc.5 5 100 200 300 400 500 100 200 300 400 500 • Same as you’ve learned in math class • Same as your calculator – Parentheses first – Exponentiation – Multiplication / division – Addition / subtraction MATLAB for Engineers 3E.

Order of Operation

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

5*(3+6)

= 45

5*3+6

= 21

100

White space does not matter!!!

200
300
400
500

100

200

300

400

500

5*3 + 6

= 21

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.

Parentheses

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

100

200
300
400
500

100

200

300

400

• Use only ( )
• { } and [ ] mean something
different
• MATLAB does not assume
operators

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.

Compute from left to right

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

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.

electronic. photocopying.5 -3 -2. or likewise. Inc.5 -1 -0. hour 3 3. 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. by Holly Moore. © 2011 Pearson Education.5 4 4. Upper Saddle River. . Inc.5 5 r = radius r=5 h = height h = 10 π r2 2π r * h 100 200 π r2 300 400 500 100 200 300 400 500 SA  2r  2rh  2r (r  h) 2 MATLAB for Engineers 3E. All rights reserved. Upper Saddle River. mechanical. NJ. or transmission in any form or by any means. NJ 07458..5 -2 -1.5 0 0 0. recording.5 time.5 2 2. For information regarding permission(s). Pearson Education.5 1 1.Here’s an example Find the surface area of a cylinder Rate of Change -5 Rate of temperature change. write to: Rights and Permissions Department.5 -4 -3. degrees/hour -4..

© 2011 Pearson Education. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. For information regarding permission(s).Array Operations Rate of Change -5 Rate of temperature change. Inc. hour 3 3. NJ. . but its real strength is in matrix manipulations 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.5 4 4. Upper Saddle River. Pearson Education.5 2 2. Inc. All rights reserved. photocopying. or likewise. write to: Rights and Permissions Department. by Holly Moore.5 5 • Using MATLAB as a glorified calculator is OK.5 time.5 0 0 0. storage in a retrieval system. electronic.. Upper Saddle River.5 1 1. degrees/hour -4. or transmission in any form or by any means.5 -4 -3. recording. mechanical.5 -3 -2.5 -2 -1.. NJ 07458.5 -1 -0.

5 2 2. recording. storage in a retrieval system. Inc.5 -2 -1..5 time. mechanical. For information regarding permission(s).5 5 To create a row vector. Inc. NJ. write to: Rights and Permissions Department.5 -1 -0.5 -3 -2. by Holly Moore. electronic. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 1 1. or likewise. degrees/hour -4. All rights reserved.5 4 4. .Rate of Change -5 Rate of temperature change. Pearson Education. or transmission in any form or by any means. Upper Saddle River. photocopying. hour 3 3..5 0 0 0.5 -4 -3. NJ 07458. © 2011 Pearson Education. enclose a list of values in brackets 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.

All rights reserved. hour 3 3. Pearson Education. storage in a retrieval system. degrees/hour -4. photocopying.5 time. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. or transmission in any form or by any means. mechanical. . recording. Upper Saddle River. NJ 07458. For information regarding permission(s).5 1 1.5 0 0 0.5 4 4. Upper Saddle River.. by Holly Moore.5 -4 -3..5 2 2.5 -2 -1.5 -3 -2. © 2011 Pearson Education. Inc.5 -1 -0. NJ. electronic. write to: Rights and Permissions Department.5 5 100 You may use either a space or a comma as a “delimiter” in a row vector 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.Rate of Change -5 Rate of temperature change. Inc. or likewise.

5 -4 -3.5 time. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. degrees/hour -4. electronic. or likewise. NJ. write to: Rights and Permissions Department. or transmission in any form or by any means. mechanical.5 0 0 0.Rate of Change -5 Rate of temperature change. by Holly Moore. Upper Saddle River..5 -2 -1. For information regarding permission(s). Upper Saddle River. recording..5 4 4. Inc. All rights reserved. © 2011 Pearson Education.5 -3 -2. Pearson Education.5 2 2. .5 -1 -0. NJ 07458. photocopying. storage in a retrieval system.5 1 1. hour 3 3. Inc.5 5 100 Use a semicolon as a delimiter to create a new row 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.

© 2011 Pearson Education.5 5 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. mechanical. by Holly Moore.5 time. Upper Saddle River.Rate of Change -5 Rate of temperature change. storage in a retrieval system.5 -1 -0. For information regarding permission(s). recording.5 -3 -2..5 1 1. hour 3 3.5 2 2.5 0 0 0. electronic. or likewise. All rights reserved. write to: Rights and Permissions Department. or transmission in any form or by any means. Inc. NJ.5 -2 -1. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. photocopying. NJ 07458.5 -4 -3.. degrees/hour -4. Pearson Education. . Inc.5 4 4. Upper Saddle River.

Inc. electronic. Upper Saddle River. recording. by Holly Moore.. mechanical.5 5 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..5 4 4. photocopying. if you enter each row on a separate line.Rate of Change -5 Rate of temperature change. Upper Saddle River.5 time.5 -1 -0. or likewise.5 0 0 0.5 -3 -2. or transmission in any form or by any means.5 2 2. For information regarding permission(s). The semicolons are optional MATLAB for Engineers 3E. NJ. NJ 07458. degrees/hour -4.5 -2 -1. Inc. storage in a retrieval system. All rights reserved. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. © 2011 Pearson Education. write to: Rights and Permissions Department. hour 3 3. Pearson Education.5 1 1.5 -4 -3. .

All rights reserved. NJ 07458.5 5 100 200 300 400 500 100 200 300 400 500 • While a complicated matrix might have to be entered by hand. Upper Saddle River. electronic.5 -1 -0.5 2 2. or transmission in any form or by any means.5 -3 -2. or likewise.Shortcuts Rate of Change -5 Rate of temperature change. . degrees/hour -4. © 2011 Pearson Education. mechanical.5 4 4. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. photocopying. Inc. NJ. recording. write to: Rights and Permissions Department.5 0 0 0. The command b= 1:5 or the command b = [1:5] both return a row matrix MATLAB for Engineers 3E. Inc.5 -4 -3.5 -2 -1.5 time. hour 3 3... storage in a retrieval system. For information regarding permission(s). Pearson Education. evenly spaced matrices can be entered much more readily. by Holly Moore. Upper Saddle River.5 1 1.

5 4 4.5 0 0 0. Inc.5 1 1. write to: Rights and Permissions Department. recording. storage in a retrieval system. . © 2011 Pearson Education.5 5 100 200 300 400 500 100 200 300 400 500 The default increment is 1.5 -1 -0.5 -2 -1. NJ. NJ 07458.5 -3 -2.5 2 2. hour 3 3. Upper Saddle River. All rights reserved. or likewise. For information regarding permission(s).. but if you want to use a different increment put it between the first and final values MATLAB for Engineers 3E. or transmission in any form or by any means. Pearson Education. photocopying. mechanical. electronic. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 time.Rate of Change -5 Rate of temperature change. degrees/hour -4. Upper Saddle River. by Holly Moore..5 -4 -3. Inc.

5 time. All rights reserved. . mechanical. storage in a retrieval system.5 2 2. Upper Saddle River. or likewise. recording.5 0 0 0. or transmission in any form or by any means. hour 3 3. © 2011 Pearson Education. degrees/hour -4. photocopying. For information regarding permission(s). Inc.5 -2 -1.5 -1 -0.5 5 • linspace • logspace 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. NJ. by Holly Moore. NJ 07458.5 4 4.5 1 1. electronic. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Upper Saddle River.5 -3 -2.To calculate spacing between elements use… Rate of Change -5 Rate of temperature change.. Pearson Education.. write to: Rights and Permissions Department. Inc.5 -4 -3.

NJ. All rights reserved.5 time. Upper Saddle River. mechanical.5 -2 -1.. photocopying. Inc.5 1 1.Rate of Change -5 Rate of temperature change.5 2 2. degrees/hour -4.5 -1 -0. hour 3 3. or likewise. Pearson Education. write to: Rights and Permissions Department. Upper Saddle River. or transmission in any form or by any means.5 0 0 0.5 -3 -2. storage in a retrieval system.5 -4 -3.5 number of elements in the array 5 Initial value in the array Final value in the array 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. For information regarding permission(s). recording..5 4 4. by Holly Moore. electronic. Inc. NJ 07458. © 2011 Pearson Education. .

5 4 4. electronic.5 -2 -1.5 5 number of elements in the array Initial value in the array expressed as a power of 10 100 200 300 400 500 100 200 300 400 Final value in the array expressed as a power of 10 500 MATLAB for Engineers 3E. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Upper Saddle River. recording. write to: Rights and Permissions Department.5 2 2. or transmission in any form or by any means. Inc. All rights reserved.5 0 0 0. NJ 07458.Rate of Change -5 Rate of temperature change..5 -1 -0. © 2011 Pearson Education.5 time. Inc. NJ. by Holly Moore.5 1 1. or likewise. photocopying. For information regarding permission(s).5 -3 -2. degrees/hour -4. Upper Saddle River. mechanical..5 -4 -3. . storage in a retrieval system. Pearson Education. hour 3 3.

5 0 0 0.5 4 4. Inc. hour 3 3. degrees/hour -4..5 2 2. Pearson Education. NJ. photocopying.Rate of Change -5 Rate of temperature change. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 1 1. Upper Saddle River. write to: Rights and Permissions Department.5 5 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. Inc. . For information regarding permission(s). electronic.5 -1 -0.. All rights reserved. or likewise. mechanical. storage in a retrieval system. recording.5 time.5 -2 -1.5 -3 -2. by Holly Moore. or transmission in any form or by any means. Upper Saddle River. © 2011 Pearson Education.5 -4 -3. NJ 07458. instead of entering the corresponding power of 10 MATLAB for Engineers 3E.

Pearson Education.Hint Rate of Change -5 Rate of temperature change. NJ. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. by Holly Moore. Upper Saddle River. electronic. Inc..5 time.5 -2 -1. recording. mechanical.5 -4 -3.. NJ 07458.5 2 2. photocopying.5 -1 -0. hour 3 3. For information regarding permission(s). or likewise. • For example 200 300 400 500 100 200 300 400 500 a = [0: pi/10: pi] MATLAB for Engineers 3E. . degrees/hour -4. All rights reserved. storage in a retrieval system. Upper Saddle River. or transmission in any form or by any means. write to: Rights and Permissions Department. © 2011 Pearson Education.5 1 1. Inc.5 5 100 • You can include mathematical operations inside a matrix definition statement.5 4 4.5 -3 -2.5 0 0 0.

.. NJ 07458. recording. electronic.. by Holly Moore.5 0 0 0.Mixed calculations between scalars and arrays Rate of Change -5 Rate of temperature change. Upper Saddle River.5 -1 -0.5 5 100 200 300 400 500 100 200 300 400 500 • Matrices can be used in many calculations with scalars • There is no confusion when we perform addition and subtraction • Multiplication and division are a little different • In matrix mathematics the multiplication operator (*) has a very specific meaning MATLAB for Engineers 3E. For information regarding permission(s).5 1 1. write to: Rights and Permissions Department.5 -3 -2. Pearson Education.5 time.5 2 2. Upper Saddle River. storage in a retrieval system. degrees/hour -4. or likewise.5 -2 -1. hour 3 3. mechanical.5 4 4. NJ. Inc. All rights reserved. Inc. or transmission in any form or by any means. © 2011 Pearson Education. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -4 -3. photocopying.

Inc.5 1 1. .5 2 2. or likewise.. storage in a retrieval system. photocopying. mechanical.5 5 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. NJ. Inc. Upper Saddle River. hour 3 3. All rights reserved. Pearson Education. For information regarding permission(s). NJ 07458.5 -3 -2.. Upper Saddle River. or transmission in any form or by any means.5 4 4. © 2011 Pearson Education.5 time.5 0 0 0.5 -1 -0. electronic. write to: Rights and Permissions Department. recording.Rate of Change -5 Rate of temperature change.5 -2 -1. degrees/hour -4.5 -4 -3. by Holly Moore. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.

mechanical. write to: Rights and Permissions Department.5 2 2.. NJ. or likewise. Inc.5 time..5 4 4. storage in a retrieval system.5 0 0 0.5 -1 -0. degrees/hour -4. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 -2 -1. NJ 07458.5 -4 -3. Pearson Education. photocopying.Rate of Change -5 Rate of temperature change. electronic. Upper Saddle River. Upper Saddle River.5 -3 -2. hour 3 3.5 5 Addition between arrays is performed on corresponding elements 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. All rights reserved. by Holly Moore.5 1 1. recording. For information regarding permission(s). or transmission in any form or by any means. © 2011 Pearson Education. . Inc.

5 -2 -1.. by Holly Moore.5 5 Multiplication between arrays is performed on corresponding elements if the .5 -4 -3. © 2011 Pearson Education. For information regarding permission(s).5 -3 -2. Upper Saddle River. recording. Upper Saddle River. or likewise.5 1 1. or transmission in any form or by any means.Rate of Change -5 Rate of temperature change.5 4 4. NJ 07458. photocopying. degrees/hour -4.5 time. Inc.5 0 0 0.5 -1 -0. write to: Rights and Permissions Department. All rights reserved. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. mechanical. electronic. Inc. . hour 3 3. storage in a retrieval system.* operator is used 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.5 2 2. Pearson Education. NJ..

5 2 2. electronic..5 -2 -1. Inc. or likewise.5 -3 -2.Rate of Change -5 Rate of temperature change. Inc. © 2011 Pearson Education. Upper Saddle River. storage in a retrieval system. NJ. mechanical.5 5 100 200 300 400 500 100 200 300 400 500 MATLAB interprets * to mean matrix multiplication.5 0 0 0. All rights reserved. Upper Saddle River. Pearson Education.5 1 1. recording. For information regarding permission(s). hour 3 3. by Holly Moore. or transmission in any form or by any means.5 -1 -0. photocopying. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.. . The arrays a and b are not the correct size for matrix multiplication in this example MATLAB for Engineers 3E.5 4 4.5 -4 -3.5 time. degrees/hour -4. NJ 07458. write to: Rights and Permissions Department.

. . Upper Saddle River. © 2011 Pearson Education.. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 2 2.^ 100 200 300 In each case the size of the arrays must match 400 500 100 200 300 400 500 MATLAB for Engineers 3E. All rights reserved.* . write to: Rights and Permissions Department. NJ 07458. Inc. electronic. by Holly Moore. Pearson Education.5 0 0 0. or transmission in any form or by any means.Array Operations Rate of Change -5 Rate of temperature change. hour 3 3.5 -1 -0. photocopying./ . For information regarding permission(s). or likewise. recording.5 5 • Array multiplication • Array division • Array exponentiation .5 4 4.5 -4 -3. mechanical. storage in a retrieval system. Inc.5 1 1.5 time.5 -2 -1. degrees/hour -4. NJ.5 -3 -2.

5 time.5 4 4. – Perform the calculation 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. recording. storage in a retrieval system.5 2 2.5 5 • For example. NJ 07458.5 -4 -3..5 -1 -0.5 0 0 0. NJ. – First put the values into a matrix. assume you have a list of angles in degrees that you would like to convert to radians. Pearson Education. mechanical. Upper Saddle River. or likewise. photocopying. by Holly Moore. degrees/hour -4. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.The matrix capability of MATLAB makes it easy to do repetitive calculations Rate of Change -5 Rate of temperature change. hour 3 3. Inc. For information regarding permission(s). Upper Saddle River.5 1 1.. .5 -3 -2. © 2011 Pearson Education. or transmission in any form or by any means. Inc. electronic.5 -2 -1. write to: Rights and Permissions Department. All rights reserved.

hour 3 3. All rights reserved. degrees/hour -4.5 time. mechanical.5 4 4.Rate of Change -5 Rate of temperature change.5 -1 -0. or likewise. by Holly Moore. write to: Rights and Permissions Department.5 5 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.5 2 2. Inc. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.. NJ 07458.5 0 0 0. NJ.. Upper Saddle River. Upper Saddle River. . or transmission in any form or by any means.5 -2 -1.5 -4 -3. recording. © 2011 Pearson Education. Inc.5 -3 -2. storage in a retrieval system. photocopying. For information regarding permission(s).5 1 1. electronic. Pearson Education.

NJ.5 1 1. Pearson Education. Upper Saddle River. called pi MATLAB for Engineers 3E.5 -2 -1.5 5 100 200 300 400 500 100 200 300 400 500 Either the * or the .5 -3 -2. . mechanical. Inc.Rate of Change -5 Rate of temperature change. NJ 07458. because it is composed of scalars and a single matrix The value of pi is built into MATLAB as a floating point number. All rights reserved. degrees/hour -4.5 -1 -0.* operator can be used for this problem. by Holly Moore. © 2011 Pearson Education. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction..5 0 0 0..5 -4 -3. For information regarding permission(s).5 time. or likewise.5 4 4. write to: Rights and Permissions Department. storage in a retrieval system. electronic. recording. Upper Saddle River. photocopying. Inc.5 2 2. hour 3 3. or transmission in any form or by any means.

NJ.5 2 2. recording.5 time.5 -2 -1. write to: Rights and Permissions Department.5 -4 -3. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.. pi. Pearson Education. • If you find sin(pi) MATLAB returns a very small number. is really an approximation. Upper Saddle River. mechanical.5 -3 -2. hour 3 3. © 2011 Pearson Education. Inc.More about pi Rate of Change -5 Rate of temperature change. All rights reserved.5 0 0 0. photocopying. electronic.5 4 4.5 -1 -0. MATLAB for Engineers 3E. or transmission in any form or by any means. or likewise. .5 5 100 200 300 400 500 100 200 300 400 500 • Because pi is an irrational number. NJ 07458. degrees/hour -4.. Upper Saddle River. For information regarding permission(s). by Holly Moore. Inc. storage in a retrieval system. it can not be expressed exactly with a floating point representation • The MATLAB constant.5 1 1.

or likewise. mechanical. .5 -1 -0.5 -2 -1. Inc.5 time. Pearson Education. 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. by Holly Moore. or transmission in any form or by any means. hour 3 3.5 -3 -2. All rights reserved. degrees/hour -4. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.. electronic. storage in a retrieval system. photocopying. recording.5 4 4. © 2011 Pearson Education.5 5 • The transpose operator changes rows to columns or vice versa. NJ 07458.5 -4 -3.5 2 2. Upper Saddle River. For information regarding permission(s).. NJ. Inc.Transpose Rate of Change -5 Rate of temperature change.5 1 1. write to: Rights and Permissions Department.5 0 0 0.

or likewise.5 -2 -1.5 2 2. or transmission in any form or by any means. All rights reserved. For information regarding permission(s).5 -4 -3.. Inc.5 -3 -2. electronic. NJ. Inc. mechanical. photocopying. hour 3 3. storage in a retrieval system.5 5 100 200 300 400 500 100 200 300 400 500 The transpose operator makes it easy to create tables MATLAB for Engineers 3E. .5 time.5 -1 -0.Rate of Change -5 Rate of temperature change.5 0 0 0. Upper Saddle River. Upper Saddle River. write to: Rights and Permissions Department. Pearson Education. degrees/hour -4..5 1 1.5 4 4. by Holly Moore. recording. © 2011 Pearson Education. NJ 07458. 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. NJ 07458. recording.radians]’ would have given the same result MATLAB for Engineers 3E. electronic.5 time. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. mechanical. Upper Saddle River. Pearson Education.5 5 100 200 300 400 500 100 200 300 400 500 table =[degrees. Inc. All rights reserved. or transmission in any form or by any means. by Holly Moore.5 2 2.5 1 1.5 -1 -0. degrees/hour -4. .5 -4 -3. Upper Saddle River.5 -3 -2.5 4 4. hour 3 3.5 0 0 0. NJ. © 2011 Pearson Education. or likewise. write to: Rights and Permissions Department.Rate of Change -5 Rate of temperature change.. photocopying. For information regarding permission(s). Inc.5 -2 -1.

5 -3 -2.Rate of Change -5 Rate of temperature change. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. NJ.5 5 The transpose operator works on both one dimensional and two dimensional arrays 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.. Pearson Education.5 -2 -1.5 -4 -3. For information regarding permission(s). Inc. Upper Saddle River. by Holly Moore. recording. Inc.5 1 1. electronic. mechanical. NJ 07458.5 time. hour 3 3. All rights reserved. or likewise. degrees/hour -4.5 4 4.5 0 0 0. or transmission in any form or by any means.5 -1 -0. photocopying. © 2011 Pearson Education. . storage in a retrieval system.5 2 2.. Upper Saddle River. write to: Rights and Permissions Department.

5 1 1. or likewise.5 -2 -1. or transmission in any form or by any means. hour 3 3. Inc. by Holly Moore.5 -1 -0. (Your calculator probably uses similar notation.5 0 0 0. electronic. it isn’t always the best way to represent very large or very small numbers – In MATLAB.) MATLAB for Engineers 3E.. recording. Pearson Education.5 time. All rights reserved.Number Display Rate of Change -5 Rate of temperature change. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. degrees/hour -4. photocopying.5 -3 -2.5 4 4. mechanical. write to: Rights and Permissions Department. .5 -4 -3. Upper Saddle River. storage in a retrieval system.. Inc. NJ. For information regarding permission(s). Upper Saddle River.5 5 100 200 300 400 500 100 200 300 400 500 • Scientific Notation – Although you can enter any number in decimal notation. NJ 07458. values in scientific notation are designated with an e between the decimal number and exponent.5 2 2. © 2011 Pearson Education.

5 5 100 200 300 400 500 100 200 300 400 500 It is important to omit blanks between the decimal number and the exponent. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. © 2011 Pearson Education. write to: Rights and Permissions Department. NJ.5 2 2. or likewise. recording. NJ 07458. or transmission in any form or by any means. . hour 3 3. electronic. MATLAB will interpret 6. Inc. storage in a retrieval system. degrees/hour -4. mechanical.5 -4 -3.5 4 4.Rate of Change -5 Rate of temperature change. photocopying.5 1 1.5 -3 -2. For example.5 0 0 0. Upper Saddle River. For information regarding permission(s).5 -1 -0.022 e23 as two values (6.022 and 1023 ) MATLAB for Engineers 3E..5 -2 -1. All rights reserved.. by Holly Moore.5 time. Inc. Pearson Education.

degrees/hour -4. NJ 07458. © 2011 Pearson Education.5 -2 -1. mechanical. by Holly Moore.5 5 100 200 300 400 500 100 200 300 400 500 • Multiple display formats are available • No matter what display format you choose.Display Format Rate of Change -5 Rate of temperature change.5 -3 -2. For information regarding permission(s).5 0 0 0. recording.5 2 2. or transmission in any form or by any means. Inc. hour 3 3. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. photocopying. storage in a retrieval system.. Inc.5 1 1. . write to: Rights and Permissions Department. Pearson Education. MATLAB uses double precision floating point numbers in its calculations • MATLAB handles both integers and decimal numbers as floating point numbers MATLAB for Engineers 3E. Upper Saddle River. electronic. NJ.5 -1 -0. Upper Saddle River.5 time.5 4 4..5 -4 -3. or likewise. All rights reserved.

or likewise. For information regarding permission(s). NJ 07458.5 5 100 200 300 400 500 100 200 300 400 500 • The default format is called short • If an integer is entered it is displayed without trailing zeros • If a floating point number is entered four decimal digits are displayed MATLAB for Engineers 3E...5 -2 -1. NJ. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. © 2011 Pearson Education. by Holly Moore. storage in a retrieval system.5 -4 -3. All rights reserved.5 0 0 0. Inc.5 time. write to: Rights and Permissions Department. photocopying.5 -1 -0.5 1 1. .5 2 2. hour 3 3. electronic. Pearson Education. Inc. recording. mechanical.Default Rate of Change -5 Rate of temperature change. or transmission in any form or by any means. degrees/hour -4. Upper Saddle River.5 4 4.5 -3 -2. Upper Saddle River.

recording. or transmission in any form or by any means..5 1 1. storage in a retrieval system. Upper Saddle River..5 5 100 200 300 400 500 100 200 300 400 500 • Changing the format affects all subsequent displays – format long results in 14 decimal digits – format bank results in 2 decimal digits – format short returns the display to the default 4 decimal digits MATLAB for Engineers 3E. Inc. electronic.5 time. or likewise. photocopying. Pearson Education. NJ 07458.5 0 0 0.5 -4 -3. mechanical. Inc. write to: Rights and Permissions Department.5 -3 -2. . This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. hour 3 3.5 4 4.Other formats Rate of Change -5 Rate of temperature change. NJ. For information regarding permission(s). by Holly Moore.5 2 2. All rights reserved. © 2011 Pearson Education. Upper Saddle River.5 -2 -1.5 -1 -0. degrees/hour -4.

© 2011 Pearson Education. or transmission in any form or by any means.5 0 0 0.5 -4 -3. by Holly Moore. storage in a retrieval system. hour 3 3. Upper Saddle River.5 4 4. write to: Rights and Permissions Department. All rights reserved.5 -3 -2. NJ 07458. For information regarding permission(s). This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. NJ.5 -2 -1. .Really Big and Really Small Rate of Change -5 Rate of temperature change. photocopying.. recording. Inc.5 -1 -0.5 5 100 200 300 400 500 100 200 300 400 500 • When numbers become too large or too small for MATLAB to display using the default format. mechanical. Pearson Education.5 time. degrees/hour -4. it automatically expresses them in scientific notation • You can force scientific notation with – format short e – format long e MATLAB for Engineers 3E. electronic. Inc.5 1 1..5 2 2. Upper Saddle River. or likewise.

5 0 0 0.5 time.5 -2 -1. mechanical. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. NJ 07458. Upper Saddle River. or transmission in any form or by any means. MATLAB for Engineers 3E. NJ..5 5 100 200 300 400 500 100 200 300 400 500 • For long and short formats. by Holly Moore.5 -1 -0. This scale factor is printed along with the scaled values.. © 2011 Pearson Education. All rights reserved.5 1 1. or very small. hour 3 3. storage in a retrieval system.Common Scale Factor Rate of Change -5 Rate of temperature change. write to: Rights and Permissions Department. electronic. recording. .5 -4 -3. Pearson Education. photocopying. Inc. a common scale factor is applied to the entire matrix if some of the elements become very large. or likewise.5 4 4. Inc.5 -3 -2. degrees/hour -4.5 2 2. For information regarding permission(s). Upper Saddle River.

Pearson Education. degrees/hour -4. or transmission in any form or by any means. or likewise.5 4 4. mechanical. hour 3 3. All rights reserved.Rate of Change -5 Rate of temperature change. recording.. Upper Saddle River. Upper Saddle River. electronic. For information regarding permission(s).5 time. by Holly Moore. NJ 07458. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. © 2011 Pearson Education. photocopying.. write to: Rights and Permissions Department.5 -3 -2.5 -1 -0.5 -4 -3.5 2 2. storage in a retrieval system.5 1 1.5 -2 -1. NJ.5 0 0 0. . Inc. Inc.5 5 100 200 Common Scale Factor 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.

write to: Rights and Permissions Department..5 -2 -1. storage in a retrieval system. © 2011 Pearson Education. For information regarding permission(s). photocopying.5 5 • format + • format rat 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. mechanical. hour 3 3. degrees/hour -4.Two other formats Rate of Change -5 Rate of temperature change.5 -3 -2.5 1 1. Pearson Education. NJ 07458. Inc.5 0 0 0. . Upper Saddle River.. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Inc.5 time. NJ. Upper Saddle River. electronic.5 2 2. All rights reserved. recording.5 -1 -0.5 -4 -3. by Holly Moore.5 4 4. or likewise. or transmission in any form or by any means.

write to: Rights and Permissions Department.5 5 – format compact – format loose – (default) 100 200 300 400 500 • The format command also allows us to control how tightly information is spaced in the command window 100 200 300 400 500 Notice that the value of A is still being displayed using the rat format. NJ. storage in a retrieval system. NJ 07458.. by Holly Moore.5 -4 -3. For information regarding permission(s). Inc. Upper Saddle River.5 -3 -2. . or transmission in any form or by any means. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. recording. Pearson Education. Upper Saddle River.Spacing in the command window Rate of Change -5 Rate of temperature change. degrees/hour -4. photocopying.5 2 2. because we haven’t changed it back to format short • Most of the examples in this presentation use format compact MATLAB for Engineers 3E.5 1 1. electronic. Inc.5 4 4.5 -2 -1. hour 3 3. mechanical. All rights reserved.5 time.5 0 0 0. © 2011 Pearson Education..5 -1 -0. or likewise.

or likewise. Inc. all that is saved are the values of the variables you have named 400 500 100 200 300 400 500 MATLAB for Engineers 3E. . All rights reserved. photocopying. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.Section 2. hour 3 3. For information regarding permission(s). Upper Saddle River.5 1 1. Inc. NJ. mechanical. write to: Rights and Permissions Department. degrees/hour -4. storage in a retrieval system.5 time. © 2011 Pearson Education.5 -1 -0.5 -4 -3.5 2 2. recording.5 4 4. or transmission in any form or by any means. electronic.5 0 0 0.5 -3 -2.. Upper Saddle River. Pearson Education. NJ 07458.4 Saving Your Work Rate of Change -5 Rate of temperature change. by Holly Moore.5 -2 -1..5 5 100 200 300 • If you save a MATLAB session performed in the command window.

5 time. For information regarding permission(s). This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 0 0 0. hour 3 3. © 2011 Pearson Education. . NJ 07458. NJ. Inc. write to: Rights and Permissions Department.. degrees/hour -4. Inc.5 -1 -0. Pearson Education.5 -3 -2. not the commands in the command window 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.Rate of Change -5 Rate of temperature change.5 4 4.5 1 1. photocopying. or transmission in any form or by any means. by Holly Moore.5 -2 -1.5 5 Variables are saved. recording. mechanical.5 -4 -3. Upper Saddle River. or likewise. storage in a retrieval system. Upper Saddle River. All rights reserved.. electronic.5 2 2.

5 -2 -1. Upper Saddle River.5 5 Save either by using the file menu or.5 time. mechanical..5 -4 -3.5 1 1. For information regarding permission(s). write to: Rights and Permissions Department. electronic. hour 3 3. © 2011 Pearson Education.. All rights reserved..5 0 0 0. Pearson Education. photocopying. 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. NJ.Rate of Change -5 Rate of temperature change. or likewise.5 -3 -2.5 2 2. or transmission in any form or by any means. recording. Inc. 100 Save with a command in the command window 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. NJ 07458. degrees/hour -4. Upper Saddle River. Inc. by Holly Moore.5 4 4.5 -1 -0. ..

you need to explicitly tell the program 100 200 save <file_name> <variable_list> -ascii 300 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. Inc. Pearson Education. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 4 4.dat. by Holly Moore. or likewise.. hour 3 3.5 time. photocopying. All rights reserved. © 2011 Pearson Education. Upper Saddle River.mat file Rate of Change -5 Rate of temperature change.5 0 0 0. . electronic.5 -4 -3. recording.5 -3 -2. NJ.5 -2 -1. mechanical.5 5 • If you want to save to another format. Upper Saddle River. such as .. storage in a retrieval system.5 -1 -0. or transmission in any form or by any means. write to: Rights and Permissions Department. NJ 07458. Inc. For information regarding permission(s).5 1 1.MATLAB automatically saves to a . degrees/hour -4.5 2 2.

Script M-files Rate of Change -5 Rate of temperature change. For information regarding permission(s). hour 3 3. or transmission in any form or by any means.5 time.5 5 100 200 300 400 500 100 200 300 400 500 • If you want to save your work. mechanical. by Holly Moore. © 2011 Pearson Education.5 -2 -1. degrees/hour -4.5 0 0 0.5 2 2. recording. Pearson Education. NJ. write to: Rights and Permissions Department. Inc.5 4 4. Upper Saddle River. NJ 07458. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. or likewise.. (the commands you entered) you need to create an M-file • File->New->M-file • Type your commands in the edit window that opens MATLAB for Engineers 3E.5 1 1. Inc.. electronic. . Upper Saddle River.5 -4 -3. storage in a retrieval system.5 -3 -2. All rights reserved. photocopying.5 -1 -0.

Inc. storage in a retrieval system. © 2011 Pearson Education.5 -1 -0. Pearson Education. electronic.5 2 2. Upper Saddle River. recording.5 -3 -2.5 1 1.Rate of Change -5 Rate of temperature change. NJ. Inc. .5 -2 -1. hour 3 3. degrees/hour -4.5 5 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.5 4 4. by Holly Moore. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 time. NJ 07458. mechanical. or transmission in any form or by any means. All rights reserved.. photocopying.. Upper Saddle River. write to: Rights and Permissions Department.5 0 0 0. or likewise.5 -4 -3. For information regarding permission(s).

© 2011 Pearson Education..5 0 0 0. or transmission in any form or by any means. Pearson Education.5 -3 -2.5 -1 -0. .Rate of Change -5 Rate of temperature change.5 1 1. hour 3 3. photocopying. by Holly Moore.. or likewise. storage in a retrieval system. recording. Inc. Inc. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. Upper Saddle River. For information regarding permission(s).5 -2 -1. NJ. All rights reserved. NJ 07458. Upper Saddle River.5 4 4.5 time. write to: Rights and Permissions Department.5 5 • The file can be saved into the current folder/directory • It runs in the command window 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. mechanical. electronic. degrees/hour -4.5 -4 -3.5 2 2.

write to: Rights and Permissions Department. Pearson Education. hour 3 3.5 -4 -3. Upper Saddle River. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 4 4.5 1 1. For information regarding permission(s). storage in a retrieval system.Rate of Change -5 Rate of temperature change.5 -1 -0. recording. or the file menu 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. NJ. photocopying. Inc.5 5 Save the file using the save icon. electronic.5 -2 -1.5 2 2.5 0 0 0.. NJ 07458. © 2011 Pearson Education.. Upper Saddle River. All rights reserved. degrees/hour -4. or likewise. by Holly Moore. Inc. mechanical.5 -3 -2. .5 time. or transmission in any form or by any means.

photocopying.5 2 2. write to: Rights and Permissions Department. hour 3 3. © 2011 Pearson Education.5 -1 -0. Pearson Education. mechanical.5 5 You can dock the editing window with the MATLAB desktop.. 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. Inc..5 1 1.5 4 4. Upper Saddle River. Upper Saddle River.5 -3 -2. recording. or transmission in any form or by any means. For information regarding permission(s). Inc.5 time. by Holly Moore. electronic.Rate of Change -5 Rate of temperature change. All rights reserved. degrees/hour -4. or likewise. NJ.5 -2 -1. .5 -4 -3. by using the docking arrow 100 200 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E. NJ 07458.5 0 0 0.

5 time. photocopying.5 0 0 0. Inc. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 1 1.Rate of Change -5 Rate of temperature change.5 5 100 200 This arrangement is often easier to use 300 400 500 100 200 300 400 500 MATLAB for Engineers 3E.. hour 3 3. © 2011 Pearson Education. or transmission in any form or by any means. .5 -4 -3. Inc. write to: Rights and Permissions Department.5 2 2.5 4 4. storage in a retrieval system. NJ. All rights reserved.5 -1 -0. Pearson Education. For information regarding permission(s). Upper Saddle River.5 -3 -2. or likewise.5 -2 -1. degrees/hour -4. by Holly Moore. mechanical. electronic. Upper Saddle River. NJ 07458. recording..

For information regarding permission(s). or likewise.5 1 1.5 -2 -1. Inc.m -1 -0.. the figure appears on top of the MATLAB desktop MATLAB for Engineers 3E. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. electronic. storage in a retrieval system.5 I saved this file as example. Upper Saddle River. hour 3 3. Pearson Education.5 5 Notice that it now appears in the current directory 100 200 300 400 500 100 200 300 400 500 When I execute the file. Upper Saddle River. write to: Rights and Permissions Department. by Holly Moore. photocopying.5 2 2.5 0 0 0.Rate of Change -5 Rate of temperature change. Inc. or transmission in any form or by any means. NJ.5 4 4. degrees/hour -4. . recording. © 2011 Pearson Education. All rights reserved. NJ 07458..5 -4 -3. mechanical.5 time.5 -3 -2.

photocopying. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 1 1.5 5 100 200 300 400 500 100 200 300 400 500 The figure window can also be docked onto the MATLAB desktop.5 time..5 -2 -1. NJ 07458.5 -4 -3. electronic. or transmission in any form or by any means. Inc. © 2011 Pearson Education. NJ. Pearson Education.5 -1 -0. using the docking arrow MATLAB for Engineers 3E.5 2 2.Rate of Change -5 Rate of temperature change. . Inc.5 -3 -2. For information regarding permission(s). All rights reserved.5 4 4. storage in a retrieval system. recording. Upper Saddle River. hour 3 3. or likewise. write to: Rights and Permissions Department.. degrees/hour -4. by Holly Moore.5 0 0 0. mechanical. Upper Saddle River.

. Inc. photocopying. All rights reserved. © 2011 Pearson Education. or transmission in any form or by any means. Pearson Education.5 1 1. recording. For information regarding permission(s). NJ. Upper Saddle River.5 time.5 4 4. Inc. mechanical. or likewise. storage in a retrieval system. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. hour 3 3. .Rate of Change -5 Rate of temperature change.5 -3 -2. electronic..5 0 0 0. by Holly Moore. but can be accessed with the tab MATLAB for Engineers 3E. write to: Rights and Permissions Department.5 2 2.5 -4 -3. degrees/hour -4.5 -1 -0.5 -2 -1. NJ 07458.5 5 100 200 300 400 500 100 200 300 400 500 Notice that the command history window is hidden underneath the figure. Upper Saddle River.

degrees/hour -4..5 0 0 0. or likewise. mechanical. Inc. NJ. storage in a retrieval system.5 time. hour 3 3.Comments Rate of Change -5 Rate of temperature change.5 5 100 200 300 400 500 100 200 300 400 500 • Be sure to comment your code – Add your name – Date – Section # – Assignment # – Descriptions of what you are doing and why MATLAB for Engineers 3E. .5 4 4.5 -2 -1. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction. write to: Rights and Permissions Department.5 -4 -3. Upper Saddle River. Upper Saddle River..5 -1 -0. or transmission in any form or by any means. photocopying. electronic. All rights reserved. © 2011 Pearson Education. Inc.5 -3 -2. by Holly Moore.5 1 1. Pearson Education.5 2 2. For information regarding permission(s). NJ 07458. recording.

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

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.

Cell Mode

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

100

200
300
400
500

100

200

300

400

500

• Enables the user to execute one
section of code at a time
• Especially useful as you debug
your code
•To use cell mode you must activate
the cell toolbar

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.

Cell Toolbar

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

100

Cell Dividers

200
300
400
500

100

200

300

400

500

Be sure to include a space
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.

NJ 07458. hour 3 3. photocopying.. recording. This material is protected by Copyright and written permission should be obtained from the publisher prior to any prohibited reproduction.5 0 0 0.5 2 2.5 -1 -0..5 1 1.5 4 4.5 5 100 200 300 400 500 100 200 300 400 500 • • • • • Introduced the MATLAB Windows Basic matrix definition Save and retrieve MATLAB data Create and use script M-files The use of cell mode MATLAB for Engineers 3E. storage in a retrieval system. © 2011 Pearson Education. Inc. Upper Saddle River.5 -2 -1. write to: Rights and Permissions Department. electronic. Pearson Education. .Summary Rate of Change -5 Rate of temperature change. All rights reserved. For information regarding permission(s). Inc. by Holly Moore. Upper Saddle River.5 -4 -3. mechanical. NJ.5 -3 -2. or likewise. degrees/hour -4.5 time. or transmission in any form or by any means.