0% found this document useful (0 votes)
158 views21 pages

Introduction To MATLAB For Engineers, Third Edition

Optimization using MATLAB

Uploaded by

Nauman Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
158 views21 pages

Introduction To MATLAB For Engineers, Third Edition

Optimization using MATLAB

Uploaded by

Nauman Khan
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPT, PDF, TXT or read online on Scribd
You are on page 1/ 21

PowerPoint to accompany

IntroductiontoMATLAB
forEngineers,ThirdEdition
William J. Palm III

Chapter 1
An Overview of MATLAB

Copyright 2010. The McGraw-Hill Companies, Inc.

The Default MATLAB Desktop, Fig. 1.1-1, page 5

1-1

Entering Commands and Expressions


MATLAB retains your previous keystrokes.
Use the up-arrow key to scroll back back through
the commands.
Press the key once to see the previous entry, and
so on.
Use the down-arrow key to scroll forward. Edit a
line using the left- and right-arrow keys the
Backspace key, and the Delete key.
Press the Enter key to execute the command.

1-2

Scalar arithmetic operations


Table 1.11, page 8

1-3

An Example Session, Pages 7-8

1-4

>>8/10
ans=
0.8000
>>5*ans
ans=
4
>>r=8/10
r=
0.8000
>>r
r=
0.8000
>>s=20*r
s=
16

Order of precedence
Table 1.12, page 9

1-5

Examples of Precedence, Page 9


>>8+3*5
ans=
23
>>8+(3*5)
ans=
23
>>(8+3)*5
ans=
55
>>4^2
12
8/4*2
ans=
0
>>4^2
12
8/(4*2)
ans=
3

1-6

Examples of Precedence, Page 9 Continued

>>3*4^2+5
ans=
53
>>(3*4)^2+5
ans=
149
>>27^(1/3)+32^(0.2)
ans=
5
>>27^(1/3)+32^0.2
ans=
5
>>27^1/3+32^0.2
ans=
11

1-7

Commands for managing the work session


Table 1.13, Page 12

1-8

Special variables and constants


Table 1.14, Page 14

1-9

Complex Number Operations, Pages 14-15


The number c1 = 1 2i is entered as follows:
c1 = 12i.
An asterisk is not needed between i or j and
a number, although it is required with a
variable, such as c2 = 5 i*c1.
Be careful. The expressions
y = 7/2*i
and
x = 7/2i
give two different results:
y = (7/2)i = 3.5i
and
x = 7/(2i) = 3.5i.
1-10

Numeric display formats. Table 1.15, Page 15

The Desktop Menus and Toolbar. Figure 1.2-1, page 16

1-11

Arrays
The numbers 0, 0.1, 0.2, , 10 can be assigned to the
variable u by typing u=0:0.1:10.
To compute w = 5 sin u for u = 0, 0.1, 0.2, , 10, the
session is;
>>u=0:0.1:10;
>>w=5*sin(u);
The single line, w=5*sin(u), computed the formula
w = 5 sin u 101 times.

1-12

Array Index

>>u(7)
ans=
0.6000
>>w(7)
ans=
2.8232
Use thelengthfunction to determine how
many values are in an array.
>>m=length(w)
m=
101

1-13

Polynomial Roots, Page 20

To find the roots of x3 7x2 + 40x 34 = 0, the session


is
>>a=[1,7,40,34];
>>roots(a)
ans=
3.0000+5.000i
3.00005.000i
1.0000
The roots are x = 1 and x = 3 5i.

1-14

Some commonly used mathematical functions


Table 1.31, Page 21

1-15

When you type problem1,


1. MATLAB first checks to see if problem1 is
a variable and if so, displays its value.
2. If not, MATLAB then checks to see if
problem1 is one of its own commands, and
executes it if it is.
3. If not, MATLAB then looks in the current
directory for a file named problem1.m
and executes problem1 if it finds it.
4. If not, MATLAB then searches the
directories in its search path, in order,
for problem1.m and then executes it if
found.

1-16

System, directory, and file commands


Table 1.32,Page 23

1-17

A graphics window showing a plot. Figure 1.3-1, page 24.

1-18

Some MATLAB plotting commands


Table 1.33, Page 25

1-19

Linear Algebraic Equations, Page 26


6x+12y+4z=70
7x2y+3z=5
2x+8y9z=64

>>A=[6,12,4;7,2,3;2,8,9];
>>B=[70;5;64];
>>Solution=A\B
Solution=
3
5
2
The solution isx=3,y=5,andz=2.
1-20

You might also like