display

advertisement
MECE 102: Engineering Mechanics
Lab
A First Year Course in
Newtonian Mechanics, Experimentation,
and Computer Tools
Created by the Faculty of the Mechanical Engineering
Department in the Kate Gleason College of Engineering at RIT
Week 13 Lecture
Programming Skills
• This week we will:
• Investigate programming Loops utilizing
For Loops
 Iterated Loop
While Loop  Conditional Loop
• Use Matlab and LabView to program an algorithm to
calculate sin q
iCLICKER:
Which of the following concepts is NOT relevant to
utilize for this week’s Programming activities?
• Select your Answer:
A.
B.
C.
D.
E.
Recursion
Algorithm
Newton’s 2nd Law
Flow Chart
None of the above
iCLICKER:
Which of the following concepts is NOT relevant to
utilize for this week’s Programming activities?
• Select your Answer:
A.
B.
C.
D.
E.
Recursion
Algorithm
Newton’s 2nd Law
Flow Chart
None of the above
ASSUME: Problem A: Calculus description of sine function
Recall from Calculus:
Our goal is to write code that approximates the sine function:
FORMULATE: Problem A: State the Known and Desired Information
Approximate sin q by using a known finite number of terms, N.
CHART: Problem A: Flow Chart of Finite Sum Algorithm
CHART: Problem A: Flow Chart of Finite Sum Algorithm
This block
defines
variables
and
initializes
values.
CHART: Problem A: Flow Chart of Finite Sum Algorithm
This block
defines
variables
and
initializes
values.
Finite
number of
Loops set
“a priori”
CHART: Problem A: Flow Chart of Finite Sum Algorithm
This block
defines the
FOR iterated
loop and sine
equation
CHART: Problem A: Flow Chart of Finite Sum Algorithm
CONDITIONAL
evaluation of
Loop
EXECUTE: Problem A: Calculating the Finite Sum employing Recursion
The calculation of the sine equation can be expanded as:
Where each term can be written as Ti
EXECUTE: Problem A: Calculating the Finite Sum employing Recursion
Starting at i = 0, the first 6 terms can be written as:
Use of
Recursive
relationship
to calculate
terms
EXECUTE: Problem A: Calculating the Finite Sum employing Recursion
Using the concept of a Recursive relationship, we can
efficiently write each new term, Ti, as a function of the
preceding term, Ti-1 :
EXECUTE: Problem A: Matlab FOR loop example code
The following code are examples of utilizing a FOR loop:
for i from start to stop do
body of program
end_for
for i from start to stop step stepwidth do
body of program
end_for
FORMULATE: Problem B: State the Known and Desired Information
Approximate sin q by using a convergence criteria
of relative error.
iCLICKER:
The value of acceptable error, e, is NOT dependent
on the limit of the computer system analyzing the
program.
• Select your Answer:
A. True
B. False
iCLICKER:
The value of acceptable error, e, is NOT dependent
on the limit of the computer system analyzing the
program.
• Select your Answer:
A. True
B. False
The value of the acceptable error, e, should be
chosen to be small enough for engineering
accuracy, however large enough to avoid issues
with the computer accuracy limit.
ASSUME: Problem B: Identify the Convergence Criteria Relationship
The WHILE loop will terminate once the relative error is less than
some acceptable error limit, e. This is known as the convergence
criteria of relative error.
Conversion accuracy issue …..
Convert [101011.01101]base 2 to a base 10 number ….
Conversion accuracy issue …..
Convert [39]base 10 to a base 2 number ….
Conversion accuracy issue …..
Convert [39.9]base 10 to a base 2 number ….
iCLICKER:
Approximately how many significant digits of
accuracy are associated with a 64 bit computer?
• Select your Answer:
A.
B.
C.
D.
~ 2 significant digits
~ 7 significant digits
~14 significant digits
~ 21 significant digits
iCLICKER:
Approximately how many significant digits of
accuracy are associated with a 64 bit computer?
• Select your Answer:
A.
B.
C.
D.
~ 2 significant digits
~ 7 significant digits
~14 significant digits
~ 21 significant digits
CHART: Problem B: Flow Chart of Conditional Sum Algorithm
CHART: Problem B: Flow Chart of Conditional Sum Algorithm
This block
defines
variables
and
initializes
values.
CHART: Problem B: Flow Chart of Conditional Sum Algorithm
This block
defines
variables
and
initializes
values.
Acceptable
error
defined
“a priori”
CHART: Problem B: Flow Chart of Conditional Sum Algorithm
This block
defines the
WHILE loop
and sine
equation
CHART: Problem B: Flow Chart of Conditional Sum Algorithm
CONDITIONAL
evaluation of
Loop
EXECUTE: Problem B: Relative Error
For an alternating series summation, we can estimate the
error, e, between successive terms as the magnitude of the
last term in the sequence.
EXECUTE: Problem B: Matlab WHILE loop example code
The following code are examples of utilizing a WHILE loop:
while condition do
body of program
end_while
This loop evaluates its body while a specified condition is
TRUE.
LabVIEW Video
Homework
• Uniform Circular Motion Lab Report due tonight!
• Prior to LAB tomorrow
• Read section 13.2 of the textbook
• Watch LAB Videos
• Complete the on-line LAB quiz in myCourses
• Attempt to solve Homework problem 13.1 in your
logbook before RECITATION.
• This is a Programming extension of the work in Chapter 13
• Include in your Logbook your algorithmic Flow Chart, Computer
program code, and an example of your Output.
Download