EGR 115 Introduction to Computing for Engineers Introduction to Computer Programming Wednesday 27...
-
Upload
jade-haynes -
Category
Documents
-
view
222 -
download
0
Transcript of EGR 115 Introduction to Computing for Engineers Introduction to Computer Programming Wednesday 27...
EGR 115 Introduction to Computing for Engineers
Introduction to Computer Programming
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
Lecture Outline
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• Introduction to Programming Why learn programming? A first example How to access MATLAB
Slide 2 of 12
Introduction to Computer ProgrammingWhy Learn Programming?
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• As engineers it is often more cost effective for us to “simulate” complex systems before implementation Simulate = computer programming!!! Testing on a simulated system is cheaper than building
hardware A system failure on a simulated system is less catastrophic
than failure of hardware!! The fidelity of the simulation determines the accuracy of the
results Most complex systems involve significant software (i.e.,
programming!!) Analyzing the results of a test often involves programming!!
Slide 3 of 12
Introduction to Computer ProgrammingWhy Learn Programming?
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• It is often faster to write a program to automate a tedious/repetitive task (10x faster!!)
• Embedded computers are everywhere Modern automobiles contain up to 50 microprocessors
o They all require programming!!
• The software that runs the Boeing 787 has approximately 7 million lines of code
• Programming is a critical skill for engineers today and even more so tomorrow The Chevrolet Volt has more lines of code than a Boeing
787!!! Future version will have up to 100 M lines of code!!
Slide 4 of 12
Introduction to Computer ProgrammingA First Example:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• A First Example Problem: Design the suspension for an small car.
o Select the shock absorber and spring so that the oscillations “diminish” after about 4 seconds.
Consider just one corner (i.e. 1 wheel)o Viscous damping of shock is “c”o Spring constant is “k”o Displacement is “X”o External force is “F”
Mathematical dynamic model
( ) ( ) ( ) ( )F t m X t c X t k X t
F
X
Slide 5 of 12
Introduction to Computer ProgrammingA First Example:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• Solution to the differential equation can be written as: Response to a step-force of magnitude ‘F”
where: , , , and
• If we assume: a mass of 20 kg (i.e., m = 20) spring constant of 1,000 (k = 1,000)
• Select a suitable shock absorber (i.e., damping const. c)
1( ) 1 nt
n
FX t e Sin t
k
Slide 6 of 12
Introduction to Computer ProgrammingA First Example:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• Develop a “simple” MATLAB program to simulate the displacement vs time (i.e., system’s response)
Defi
ne
cons
tant
s
Com
pute
pa
ram
eter
s
Calc
ulat
e re
spon
se
Plot
re
sults
Slide 7 of 12
Introduction to Computer ProgrammingA First Example:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• Results:
C = 10C = 100C = 50
Looks like a shock with damping of 50 N / (m/s) will do the job!!!
0 1 2 3 4 5 6 7 8 9 100
0.002
0.004
0.006
0.008
0.01
0.012
0.014
0.016
0.018
0.02Step Response of Car Suspension: F=10, m=20, k=1000, & c=10
Time in Sec
X in
met
ers
0 1 2 3 4 5 6 7 8 9 100
0.002
0.004
0.006
0.008
0.01
0.012
0.014Step Response of Car Suspension: F=10, m=20, k=1000, & c=100
Time in Sec
X in
met
ers
0 1 2 3 4 5 6 7 8 9 100
0.002
0.004
0.006
0.008
0.01
0.012
0.014
0.016Step Response of Car Suspension: F=10, m=20, k=1000, & c=50
Time in Sec
X in
met
ers
Slide 8 of 12
Introduction to Computer ProgrammingHow to Access MATLAB:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
1. MATLAB can be found on ERAU computers at: All Programs College of Engineering MATLAB We are currently using version 2013b
2. MATLAB can also be accessed via ERNIE: For home use (slow)
3. Can be purchasedfrom the bookstorefor ~$99
Slide 9 of 12
Introduction to Computer ProgrammingThe Advantages & Disadvantages of MATLAB:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
Advantages Disadvantages
Ease of use• Interpreted, allows interactive prototyping,
and debugging
Speed• The interpreted nature of MATLAB
makes it inherently slower to execute than some other languages
• Tools exist to speed up MATLAB code above interpreted speed
• Speed is frequently not important in experimental code
Platform Independence• Same MATLAB code can be executed on a
broad range of machines and will provide identical results
Predefined Functions• Library of common operations (e.g., sin, …)• Toolboxes for specific applications
Cost• Typically 10X more expensive• MATLAB is not an open standard and
is a single-source vendor (i.e. MathWorks Inc.)
Device-Independent Plotting• Allows visualization of results across many
platforms (e.g., MAC, Linux, …)
Graphical User Interface• Can develop GUI for programs
Memory• MATLAB typically uses more memory
than comparable programming languages
MATLAB Compiler• Stand-alone & Java-like p-code
Slide 10 of 12
Introduction to Computer ProgrammingHistory of MATLAB:
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• MATLAB is an acronym for MATrix LABoratory Simplifies programming with arrays (i.e., matrices and
vectors)
• Development of MATLAB was begun by Dr. Cleve Moler, a CS professor from UNM, in the late 70’s. For teaching programming to engineers
• MathWorks was founded in 1984 In 2004 MATLAB had over 1 million users
Slide 11 of 12
Next Lecture
Wednesday 27 Aug 2014 EGR 115 Introduction to Computing for Engineers
• Introduction to MATLAB The Environment Using MATLAB as a Calculator
Slide 12 of 12