Você está na página 1de 30

1

Chapter 2
Data Types, Operators, and Expressions
2.1 Numerical Data Types
2.2 Character Data Type
2.3 Logical Data Type
2.4 Arrays
2.5 Sums, Products, Minima, and Maxima
2.6 Arithmetic Operators
2.7 Relational and Logical Operators
2.8 String Manipulations
2.9 Expressions
2.10 Example: Function Approximations
2.11 Example: Series Solution of a Laplace Equation
2.12 Example: Deflection of Beams
2.13 Example: Vibrations of Supported Machines
2.14 Additional Exercise Problems
2

2.1 Numeric Data Types


3

2.1 Numeric Data Types (Continued)


Concepts Functions
Screen output format format short
Double-precision floating-point numbers format compact
Single-precision floating-point numbers format long
Integer numbers single
Two’s complement representation int16
Unsigned integer number int8
Binary representation of double numbers uint8
intmax
intmin
ans

0 1 0 0 0 0 0 0 0 0 1111 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
4

2.2 Character Data Type


5

2.2 Character Data Type (Continued)


Concepts Functions
Characters char
ASCII codes whos
Conversion between characters
and numbers
String: row vector of characters

Example: ASCII Codes


6

2.3 Logical Data Type

Concepts
Logical values Functions
Relational operators
Logical operators logical
Conversion between logical true
values and numbers false
7

2.4 Arrays
Concepts
Zero-dimensional arrays: scalars
One-dimensional arrays: row vectors and column vectors
Two-dimensional arrays: matrices
Three-dimensional arrays
First dimension: row dimension
Second dimension: column dimension
Third dimension: page dimension

Functions
ones
linspace
8

2.4 Arrays (Continued)

Functions
zeros
size
length
end

Concepts
Subscript indexing & linear indexing
Size and length of an array
9

2.4 Arrays (Continued)

Concepts Functions
Colon: the entire column/row reshape
[]: empty data
10

2.4 Arrays (Continued)


Concepts
Concatenation
of arrays
Flipping of
matrices

Functions
horzcat
vertcat
fliplr
flipud
11

2.5 Sums, Products, Minima, and Maxima

Functions
sum
cumsum
prod
cumprod
diff
min
max
12

2.6 Arithmetic Operators


13

2.6 Arithmetic Operators (Continued)


14

2.6 Arithmetic Operators (Continued)


15

2.7 Relational and Logical Operators

Functions
find
isequal
16

2.8 String Manipulations

Functions
echo
disp
num2str
sprintf
deblank
17

2.8 String Manipulations (Continued)


Example: A Simple Calculator

Functions
strcmp
break
18

2.9 Expressions
a b c abc
= = = = 2R
sin α sin β sin γ 2A
abc
R=
(a + b + c)(a − b + c)(b − c + a)(c − a + b)

Example: Law of Sines

Functions
sind
asind
19

2.9 Expressions (Continued)

a 2 = b 2 + c 2 − 2bc cos α

Example: Law of Cosines

An expression is a syntactic combination of data (constants or


variables; scalars, vectors, matrices, or higher-dimensional Function
arrays), functions (built-in or user-defined), operators
acosd
(arithmetic, relational, or logical), and special characters.
20

2.10 Example: Function Approximation

x3 x5 x7
Taylor series: sin x = x − + − + ...
3! 5! 7!
21

2.10 Example: Function Approximation


(Continued)

x 2 k−1
sin x = ∑ (−1) k+1

k=1 (2k − 1)!

Using For-Loop
22

2.10 Example: Function Approximation


(Continued)

x 2 k−1
sin x = ∑ (−1) k+1

k=1 (2k − 1)!

Vector Expressions
23

2.10 Example: Function Approximation


(Continued)

x 2 k−1
sin x = ∑ (−1) k+1

k=1 (2k − 1)!

Matrix Expressions
24

2.10 Example: Function Approximation


(Continued)

x 2 k−1
sin x = ∑ (−1) k+1

k=1 (2k − 1)!

Multiple Curves
25

2.11 Example: Series Solution of a Laplace


Equation
∂2 φ ∂2 φ
+ 2 =0 BCs: φ (x,0) = φ (x,1) = φ (1, y) = 0 φ (0, y) = y(1− y)
∂x 2
∂y

1− cos(kπ ) − kπ x
φ (x, y) = 4 ∑ e sin(kπ y)
k=1 (kπ ) 3
26

2.12 Deflection of Beams


y
Rx 3 F
y = −θ x + − < x − a >3
6EI 6EI
Fa F wh 3
θ= (2L − a)(L − a), R = (L − a), I =
x 6EIL L 12
0, if x ≤ a
< x − a >3 =
(x − a)3 , if x > a
27

2.13 Example: Vibrations of Supported


Machines
Undamped Free Vibrations
k
mx + kx = 0, BCs: x(0) = δ , x(0) = 0 x(t) = δ cos ω t ω=
m
28

2.13 Example: Vibrations of Supported


Machines (Continued)
mx + cx + kx = 0, BCs: x(0) = δ , x(0) = 0
Damped Free Vibrations
ct
− c
x(t) = δ e 2m
(cos ω d t + sin ω d t)
2mω d
2
c
ω d = ω 1−
cc
29

2.13 Example: Vibrations of Supported


Machines (Continued)
Harmonically Forced Vibrations

mx + cx + kx = F sin ω f t

Steady-State Response

x(t) = xm sin(ω f t − ϕ )

F k
xm =
( ) ( )
2
+ 2 ( c cc ) ω f ω
2 2
1− ω f ω

ϕ = tan −1
(
2 ( c cc ) ω f ω )
( )
2
1− ω f ω
30

2.13 Example: Vibrations of Supported


Machines (Continued)

Você também pode gostar