0% found this document useful (0 votes)
9 views

Week 9 Matlab - Part 1

Uploaded by

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

Week 9 Matlab - Part 1

Uploaded by

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

Thinking Like

an Engineer
An Active Learning
Approach
Stephan, Bowman, Park, Sill, Ohland
Third Edition
Copyright © 2015
Pearson Prentice-Hall, Inc.
MATLAB is a programming and numeric computing
platform used by millions of engineers and scientists to
analyze data, develop algorithms, and create models.

What is the difference between .m and .MAT files?


.m extension contain MATLAB code, either in the form
of a script or a function. Files with a . mat extension
contain MATLAB formatted data, and data can be
loaded from or written to these files using the
functions load and save , respectively.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
To reset the window configuration,
use HOME > LAYOUT > DEFAULT

The Command Window shows (a) A list of your


A list of your commands you type at the prompt variables, their
MATLAB files will
or (b) output from a program. type, and value will
be located here. be located here.
The UP Arrow key will scroll through
This will show the your previous commands typed into clear
status of the the Command Window. erases all
program. If it says variables
"BUSY" and you want clc found in the
it to stop, hit Workspace.
CTRL + C erases everything in this window.

typing doc xx is a way to find


information about topic xx.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
This is where the file is
located on your computer.

This is the
current file.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
To create a To RUN the To "UNDOCK"
new Editor program, click this window and
(.m) file, here or use F5. make it separate
click here. from the main
interface, use
this button.
This interface example shows
the Editor Window "DOCKED" in
the main interface. You can
move the windows into any
configuration.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Variables are like small blackboards
We can write a number on them (or data of other
types)
We can change the number
We can erase the number

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
All names must consist only of letters, numbers, and the
underscore character (shown as _ displayed by holding “Shift” and
typing a hyphen).

Names can only begin with alphabetic letters (no numbers or


special characters).

Names cannot be longer than 63 characters.

Names in MATLAB are case sensitive: Frog and frog are different.

Names cannot have the same name as any other identifier


(program name, function name, built-in function, built-in constant,
reserved word, etc.), because MATLAB’s order of execution will
prevent the program from finding the correct item.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Do not choose the following variable names:
Lowercase or Uppercase letter O (o or O) = looks like the
number zero (0)
Lowercase letter L (l) = looks like the number one (1)

Use leading zeros!


Example: R = 0.25 R = .25

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Which of the following is not a valid variable name?

A. N30a

B. 20a

C. Hello_

D. i

E. K

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Which of the following is not a valid variable name?

A. N30a B
B. 20a

C. Hello_

D. i

E. K

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
The symbol EQUAL TO (=) does not mean EQUAL TO as in
algebraic expression; in MATLAB
= means "complete the tasks on the right-hand side,
then store in the left-hand side variable"

X = 5
Place the number "5"
into the variable "X"
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
The symbol EQUAL TO (=) does not mean EQUAL TO as in
algebraic expression; in MATLAB
= means "complete the tasks on the right-hand side,
then store in the left-hand side variable"

Y = 2 * XX
Multiply the current value of "X"
(5) by 2, and store the answer in
the variable "Y"
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
The symbol EQUAL TO (=) does not mean EQUAL TO as in
algebraic expression; in MATLAB
= means "complete the tasks on the right-hand side,
then store in the left-hand side variable"

Y = 8 + YY
Add 8 to the current value of "Y" (10), and store
the answer back into the variable "Y"

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Main Memory
Long list of memory locations
Each contains zeros and ones
Can change during program execution
Binary Digit or Bit
A digit that can only be zero or one
Byte
Each memory location has eight bits
Address
Number that identifies a memory location

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Some data is too large for a single byte

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Numeric data → consists of one or more numbers

Classified as integers and non-integers (floating point


numbers)

Default numeric type in MATLAB: double precision (even if


the value being stored has no fractional part)

Floating Point Formats:


Name Bytes Approx. Precision
Double 8 16 decimal digits
Single 4 7 decimal digits
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Scalar → a single numeric value
7 (integer)
-35.12 (float)
2.778 x 10³ (scientific notation)
2.4 + 3.92i (complex numbers)

1 X 1 MATRIX

To define a scalar, you simply use the assignment


operator (=) to place the desired value into a variable.
Age = 34 BigNum = 3.5E246
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
The following names are already defined as special
constants in MATLAB.

**AVOID using them for other purposes**

pi The constant pi(π) to 15 decimal places


i −1
j −1

NOTE: j is used by electrical engineers to avoid confusión


with electric current which usually uses i as the variable.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
For the most part, the mathematical operatiors used in
Microsoft Excel work the same way in MATLAB, including
parenthesis and priority of operators.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Function Description
single Convert to single precision
double Convert to double precision
inf Infinity
round Round to nearest integer
ceil Round toward positive infinity
floor Round toward negative infinity
sqrt Determine the square root
sin Sine of angle in radians
sind Sine of angle in degrees
exp Exponential function
log Natural logarithm
log10 Base 10 logarithm
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Assume variables N1 and N2 each contain a
single value (scalar). Place the results of the
calculation
−5 N2 N1 cos(πe )
in the variable NCalc.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Assume variables N1 and N2 each contain a
single value (scalar). Place the results of the
calculation
−5 N2 N1 cos(πe )
in the variable NCalc.
Ncalc = N1 * cos(pi * exp(-5 * N2));

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?

RTP = 3^2 + 1

Q = sqrt(-9)
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?

RTP = 3^2 + 1 RTP contains 10

Q = sqrt(-9) Q contains 0 + 3i
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Default numeric display: four decimal places unless the
value has no fractional part.

Numbers with fractional parts and magnitudes between


10,000 and 0.001 will be displayed with up to three digits
to the left of the decimal point and four decimal places.

For values outside this range, MATLAB will display the


value in scientific notation.

100 * pi → 314.1593 pi/1000 → 0.0031


1000 * pi → 3.1416e+03 pi/10000 → 3.1416e-04
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Values with no fractional part and a magnitude less than
10¹⁰ will display as an integer
123123123 → 123123123

Larger values will display with five sig figs in scientific


notation, as in the previous slide.
1231231231 → 1.2312e+09

REMEMBER: Even if a number has no fractional part, it


will be stored as a double precision floating point number.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Vector → numeric values organized into a single row or a
single column.
−1
Examples: [3.5 −38 1] 0
3.2
1 x N MATRIX N x 1 MATRIX

N is an integer greater than 1.

**In these two cases N = 3.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
As with scalars, the method for defining a vector is to use
the assignment operator (=).

1. How do we tell MATLAB that we are defining a vector


and not a scalar?
2. How do we tell MATLAB whether we are creating a row
or a column vector?
3. How do we distinguish individual values from each
other?

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
How do we tell MATLAB that we are defining a vector and
not a scalar?

The first character following the assignment operator is [


(open square bracket).

Once we have entered all the numbers, we end with ]


(close square bracket).

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
How do we tell MATLAB whether we are creating a row or
a column vector?
How do we distinguish individual values from each other?

A space or comma delimiter creates a row.

A semicolon delimiter creates a column.

Ex. If we separate the values with semicolons, they will be


placed in a column vector.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?

Pair = [23 4.3];

CTrio = [0; 0; 97];

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?
Pair contains the
Pair = [23 4.3]; row vector [23 4.3]

CTrio contains the


CTrio = [0; 0; 97]; 𝟎
column vector 𝟎
𝟗𝟕
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
If you need to convert a row vector to a column vector, or
viceversa, use the apostrophe or single quote to
transpose it.

V = [6, -9, 3];


VT = V’;
6
V will contain [6 -9 3] VT will contain −9
3

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Create a vector containing a set of equally spaced values
by using the colon delimiter. (Brackets are optional.)

X = 0: 0.25: 100
This generates a vector from 0 to 100, in increments of 0.25
Vector = Start value: Increment: End value
Y = 0: 100
This generates a vector from 0 to 100, in increments of 1
Vector = Start value: End value
**Default increment is 1 if it is not specified
Countdown = 5: -1: 0
This generates a vector with decreasing value, dependent on the increment.
Vector = Maximum value (Start value): decrease increment: minimum value

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?

LSeq = 1:5;

Miss = 1:5:20;

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?

LSeq contains [1 2 3 4 5]
LSeq = 1:5;
You could also enter LSeq = [1: 5];

Miss = 1:5:20; Miss contains [1 6 11 16]


The sequence will stop in the last value
BEFORE it exceedes the stated end value.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
When addition and subtraction involves a vector, there
are two cases:
1. A scalar and a vector
2. Two equal size vectors

If you attempt to add two vectors that are not the same
size, you will get angry red letters indicating an error!

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?
Assume V1 = [2 5 9]; V2 = [3 0]; V3 = [4 -7 0];

D1 = V1 – 4;

S1 = V1 + V3;

E1 = V1 + V2;

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?
Assume V1 = [2 5 9]; V2 = [3 0]; V3 = [4 -7 0];

D1 = V1 – 4; D1 contains [-2 1 5]

S1 contains [6 -2 9]
S1 = V1 + V3;

E1 = V1 + V2; Error! Matrix dimensions


must agree.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Two cases:
1. A vector multiplied or divided by a scalar: each
element of the vector is multiplied or divided by the
scalar
NOTE: If you attempt to divide a scalar by a vector, you will get
angry red letters
2. A vector multiplied or divided by an equal length
vector: corresponding elements of the two vectors are
multiplied and divided
NOTE: This requires an element-wise operator, or dot operator.
The * or / operator must be preceded by a period (.)
If you attempt an element-wise multiplication or division of
vectors of different size, you will get angry red letters
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?
Assume V1 = [2 5 9]; V2 = [3 0]; V3 = [4 -7 0];

P1 = V2 * 300;

Q2 = V3 ./ V1;

R3 = 5 / V1;

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What is stored in the variable when each line of MATLAB
code below is executed?
Assume V1 = [2 5 9]; V2 = [3 0]; V3 = [4 -7 0];

P1 = V2 * 300; P1 contains [900 0]

Q2 = V3 ./ V1; Q2 contains [2 -1.4 0]

R3 = 5 / V1; Error! Matrix dimensions


must agree.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
A matrix, or array, consists of numbers organized into
rows and columns.

All numeric data in MATLAB (scalars and vectors) are


matrices.

MATrix LABoratory

To define a matrix, combine the methods used to create


row and column vectors: specify the first row with
elements separated by commas or spaces, then use a
semicolon to move to the next row.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?

M1 = [0 -4 3; -2 6 0.2];

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?

M1 = [0 -4 3; -2 6 0.2];

C𝐫𝐞𝐚𝐭𝐞𝐬 𝐭𝐡𝐞 𝟐 𝐱 𝟑 𝐦𝐚𝐭𝐫𝐢𝐱


𝟎 −𝟒 𝟑
M1 =
−𝟐 𝟔 𝟎. 𝟐

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
A single quote (‘) will transpose a matrix by swapping rows
and columns:

The first row of the original matrix becomes the first


column of the transposed matrix, the second row
becomes the second column, etc.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?
0 −4 3
Assume M1 =
−2 6 0.2

T1 = M1’;

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?
0 −4 3
Assume M1 =
−2 6 0.2

T1 = M1’; This will transpose the M1


matrix, and store it in T1:
𝟎 −𝟐
T1 = −𝟒 𝟔
𝟑 𝟎. 𝟐

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Two cases:
1. A scalar and a matrix: the scalar is added or
subtracted to each element of the matrix
2. Two equal size matrices: corresponding elements of
the two matrices are added or subtracted.
NOTE: If you attempt to add two non-scalar matrices that are
not the same size, you will get angry red letters.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?
3 0.5 0 9 −4
Assume ExM1 = ExM2 =
5 −7 2 8 3.7

D1 = 7 – ExM1;

E1 = ExM1 + ExM2;

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?
3 0.5 0 9 −4
Assume ExM1 = ExM2 =
5 −7 2 8 3.7

D1 = 7 – ExM1; D1 =
𝟒 𝟔. 𝟓 𝟕
𝟐 𝟏𝟒 𝟓

E1 = ExM1 + ExM2;
Error! Matrix dimensions
must agree.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Multiplication:
1. A scalar and a matrix: The scalar is multiplied by each
element of the matrix.
2. Two equal size matrices multiplied on an element-by-
element basis.
NOTE: This requires an element-wise operator, or dot operator.
The * operator must be preceded by a period (.)
Division:
3. The only case we will consider is division of a matrix
by a scalar. Each element of the matrix is divided by
the scalar.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?
3 0.5 0 9 −4
Assume ExM1 = ExM2 =
5 −7 2 8 3.7

D1 = 7 – ExM1;

E1 = ExM1 + ExM2;

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
What matrix is formed by the following commands?
3 0.5 0 9 −4
Assume ExM1 = ExM2 =
5 −7 2 8 3.7

D1 = 7 – ExM1; D1 =
𝟒 𝟔. 𝟓 𝟕
𝟐 𝟏𝟒 𝟓

E1 = ExM1 + ExM2;
Error! Matrix dimensions
must agree.

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Complete the algorithm template to solve the following
The maximum radius a falling liquid drop can have without breaking
apart is given by the equation:

R=
g
where σ is the liquid surface tension, g is the acceleration due to gravity, and ρ is
the density of the liquid.

Use this expression to determine the surface tension in units of


J
joules per meter squared .
m2

As a test case, consider the maximum radius of a drop is 0.25 inches


[in] and the specific gravity of the liquid is 0.79.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Include units with numerical values using inline
Input max comments. Be sure your units work!
radius (R) [in] % Set input variables & constants
R = 0.25; % [in]
Input SG [-] SG = 0.79; % [-]
Be sure to define constants; do not use numbers like 9.8
within the program. Similar to Excel: absolute references
Set density water
𝛒𝐰𝐚𝐭𝐞𝐫 = 1000 kg/m3
rho_w = 1000; % [kg/m^3]
Set gravity g = 9.8; % [m/s^2]
g = 9.8 m/s2

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
% Convert R: [in]-->[cm]-->[m]
Convert R
1 [in] = 2.54 [cm] R = R * 2.54 / 100;
100 [cm] = 1 [m] Unit conversions should appear as actual conversion factors.
Do not multiply these together before entering!

Calculate
% Calculate density of acetone
𝛒 = 𝐒𝐆 𝛒𝐰𝐚𝐭𝐞𝐫 rho_a = SG * rho_w; % kg/m^3

Note here the calculation of density is a deliberate step;


don't skip over the "easy" steps.
Calculate
% Calculate the surface tension
𝛔 = 𝐑𝟐 𝐠 𝛒
1 [J/m2] = 1 [kg /s2] sigma = R^2 * g * rho_a
% kg/s^2=J/m^2

Thinking Like an Engineer An Active Learning Approach


Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.
Thinking Like an Engineer An Active Learning Approach
Stephan, Bowman, Park, Sill, Ohland 3rd Edition Copyright © 2015 Pearson Prentice-Hall, Inc.

You might also like

pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy