0% found this document useful (0 votes)
37 views48 pages

Num Method 01 Introduction I MAE284 SP20

Uploaded by

Isaac Thales
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)
37 views48 pages

Num Method 01 Introduction I MAE284 SP20

Uploaded by

Isaac Thales
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/ 48

Lecture 1: Introduction

MAE 284
Numerical Methods
R. N. Tantaris

1
Welcome to
MAE 284
Numerical Methods!

2
Topics
• General notes
• Syllabus Review
• Introduction to Numerical Methods
• Matlab

3
General Notes

4
Recommended Book
• https://www.youtube.com/watch?v=yQq1-
_ujXrM

6
A note on Clickers
• If you purchased a clicker secondhand, you
may have issues setting it up.

7
Topics
• Introduction
• Syllabus
– Course description
– Policies
• Introduction to Numerical Methods
– Matlab
– Flowcharting and pseudocode
– Programming
• Basic Matlab
8
Introduction
• Welcome to numerical methods!
• Personal introduction
• Be sure your announcements on Canvas are set to “Notify me
right away”
• Canvas  Account  Notifications

9
A note on email
• Due to the number of emails I receive, it is
possible that one of your email slips through the
cracks.
• If I don’t return your email (or post an
announcement in response), it is simply due to it
accidentally being marked as being read (and
therefore addressed by me). If this happens, please
send the email again.
• My policy is to respond to every student email.
• Having said that, please be considerate and look at
the syllabus to see if your question is answered
there before emailing me.
A Note on Help via Email
• I understand that many of you may prefer to use email.
• Unfortunately, solving programming problems is much more
difficult and time consuming via email.
• Considering the large number of students in this class, it is
just not practical in general. However, there may be times
where it is the only way (e.g. you are snowbound, sick, at a
conference, etc.).
• If that is the case, we will work with you.
• Since every one writes programs a little differently, it is more
difficult to determine the source of the problem via email and
therefore takes longer.

11
A Note on Help via Email
Therefore, please be sure to include the following information in
your email:
1. The workshop or homework assignment you are working on
2. The page number (workshops) or problem number (homework)
3. Carefully describe both what you are doing and the problem you are
having. If you are getting an error message, please be sure to include a
screen shot. For example, suppose you write a function that is called by
your main program. When you run the function by itself, it works but
when you run your main program it generates an error. All of this
information should be provided in the email.
4. Attach ALL of the Matlab code used in solving the problem, not just a
section of the code. The problem may not be in the section you are
working on.
5. Anything else you think is relevant.
12
Textbook
I understand how expensive the book is and that the 3rd edition can be obtained for
far less $$ (or free). The 4th edition is required for the course. If you decide to use
the 3rd edition and there is a difference between the versions, you will be
responsible. For example, suppose I assign a problem out of the book for
homework. If you complete the problem from the 3rd edition and it is not the same
as the 4th edition, you will not get credit for the problem.

You might also want to consider this: in my academic experience and my 20+
years of experience in industry, I have not found a better book. Even though the
school provides the class textbook for the classes I teach, I bought the textbook for
my personal use (and I assure you it was not a trivial cost to me).

If it was me, I would consider the purchase of the book not in terms of the class but
rather as the purchase of an excellent reference book for a common engineering tool
(Matlab and Numerical Methods techniques). While online references can be
helpful, I have found that they do not go into the detail required to apply these
concepts and techniques to real world engineering problems.

Thinking about your textbooks as references that can be useful in your engineering
career is something that I encourage you to do in general for all of your classes. 13
Syllabus Review

14
Syllabus
Be sure to read the entire Syllabus
You may have questions on a quiz
• Instructor/TA info • Course Overview
• Class meeting times • Grading
• Canvas Announcements • Workshops
• Course Description • Homework
• Required Materials • Clickers
• Prerequisites • Quizzes/Exams
• Objectives • Canvas Dropbox
• Matlab • Common HW Issues
15
Syllabus
• Canvas Modules and Gateway Quizzes
• Homework Policy
• Thor and Quiz/Exam Rules
• Makeup Quiz/Exam Policy
• Attendance Policy
• Phone/Laptop/Notepad Policy
• Safety and Emergency Information
• Americans with Disabilities Act
16
Syllabus
• You are responsible for time-critical announcements made on
Canvas
• If you drop a co-requisite, you will be dropped from this class
• Required: Matlab 2019a
• Don’t use Symbolic Toolbox or functions not covered in class.
• Forgetting your clicker, dead batteries, etc. aren’t valid excuses.
• Canvas drop-box deadlines are final and Canvas time rules.
• Excused absences do not cover late submissions.
• Gateway quizzes must be passed before drop boxes open.
• Grading stops with a MATLAB error: no further questions will
be graded even if you have the correct code.
• Read Makeup Exam/Quiz Policy, Attendance Policy, and
Phone/Laptop/NotePad Policy 17
Course Description
• This course covers three main topics:
1. the Matlab programming language,
2. basic structured programming, and
3. numerical methods (using Matlab).
• To cover this material, the course has two
main components:
1. Class lectures and
2. Computer labs.
18
Course Description - Lectures
• Class Lectures
1. introduce Matlab commands
2. present theory of structured programming
3. present theory of numerical methods.
• The theory is demonstrated with selected
examples.
• If you don’t understand something, ask
questions in lecture, in lab, during office hours,
and/or help sessions! 19
Course Description - Labs
• Computer labs will typically have three parts:
1. Brief review of theory and detailed demonstration
of the concepts used via sample problems
2. Hands on demonstration of how to implement the
solution to the sample problems (i.e. how to
code). May include a 2nd problem to solve on
your own (Clicker question).
3. Free time to ask questions on workshops,
homework, etc.
20
Course Description - Grading
Homework Assignments (6) 15 %
Clicker-Response (lab and lecture) 5%
Quizzes (6) 20 %
Exam 1 20 %
Exam 2 20 %
Final Exam (comprehensive) 20 %
Total 100 %
A typical final grading scheme is listed below.
A 90 – 100
B 80 – 90
C 70 – 80
D 60 – 70
F < 60 21
Phone/Electronics Policy
• No phones usage in class lecture or lab.
• All phones must be silenced and out of sight.
• Any other electronic devices must be solely
used for classroom activities (taking notes,
reviewing notes, etc.)

22
Changes from Previous Semesters

• 3 exams instead of 2
• Approximately Twice as many questions on
quizzes/exams (100% Canvas)
• First two exams cover same material as the preceeding
two quizzes.
• Workshops not graded but required for functions and
quiz/exam questions (and number of workshops reduced).
• Lab lecture posted before lab, code after lab
• Clickers (must have in lecture and lab)

23
Student Success Center
• https://www.uah.edu/ssc

• https://uah.instructure.com/courses/28557

24
Introduction to
Numerical Methods

25
Course Overview
Linear Algebra

MATLAB
Numerical Methods Flow Diagrams

Root Finding Matrix Operations Programming

Vector Operations
26
Course Introduction
• Engineers are in essence problem solvers.
• They are asked to take a problem, analyze it, and then formulate
the safest, and most economical solution in a timely manner.
• Many of these problems require formulation of mathematical
models that describe the problem in order to find an appropriate
solution.
• Many of these models do not have closed-form solutions, so a
numerical solution must be used.
• With rapid advancements in software and PC’s, very powerful
tools are available to help formulate these numerical solutions.
• In this class we will learn how to use one of the most powerful
tools in an engineer’s toolbox to solve engineering problems! 27
Numerical Methods
• A numerical method (algorithm) is a well-defined
procedure to solve a problem.
• It is formally a type of effective method in which a
list of well-defined instructions for completing a task
will, when given an initial state, proceed through a
well-defined series of successive states, eventually
terminating in an end-state.
• A means of determining a solution when it can’t “just
be solved for” (deterministic or closed form solution).

28
Types of Solutions

• We will talk about two types of solutions in


the class
1. Analytical solution (or closed form solution or
deterministic solution)
2. Numerical solution (i.e. using Numerical
Methods)

29
Types of Solutions

• Analytical :
5𝑥 = 45 ⟹ 𝑥 = 9

• But what if the equation to be solved is


𝑥 3 = cos 𝑥
• For this problem, we need to use a Numerical
Method
30
Numeric Method Example
• Deterministic: 5  x  17

• Numerical Method (Newton Raphson)


x  cos x
3
  f ( x)  x  cos x
3
 
Guess Result
0.459697694131860
 1.000000000000000
1

0.5 0.051068542074257
 0.865614370022862
  
f ( x)
0 0.5 1 1.5 
x 
0.846550326921688
y 0.000922980852269
 0.5 0.000000319511424
 0.846192904231802
0.000000000000038
 0.846192780415855
1
  
x 0.000000000000000
 0.846192780415840 31
Types of Solutions
• When we say analytical solution we are NOT
using the general sense of the word (relating to
or using analysis or logical reasoning )
• An analytical solution is a solution obtained
by typical math operations (integrating,
differentiating, factoring, using methods
studied in Diff. Eq. class, etc.)
• An analytical solution is an exact solution or
true solution (as opposed to an approximation).
32
Types of Solutions
• Ideally we would always obtain an analytical
solution.
• As we demonstrated in the previous example,
it is not always possible to obtain an analytical
solution
• When that is the case, we will use numerical
methods to obtain a numerical solution.
• In general, a numerical solution is not an exact
solution – it is an approximation!
33
Flowcharting
Factorial
• Flowcharts are used
in designing or
documenting a
process or program
• Consist primarily of
processing steps
(rectangles) and
decision steps
(diamonds)

34
Pseudocode
• Computer-like implementation Singularity Function
of a flow chart without using a 0 if n  0

n
particular program’s syntax. x xa  0 if x  xa
Function Inputs: ( x  xa) n if n  0 and x  xa
x – current position
xa – singularity position
n – exponent of function
x = current position
yes no xa = singularity position
is n<0 ?
n = exponent of function
yes if n<0 then
val = 0 is x<xa ? val = 0
elseif x < xa then
no val = 0
val = (x-xa)^n val = 0
else
val = (x-xa)^n
Function Outputs:
end if
val return val 35
Programming
• Translating pseudocode into the syntax of a particular
language
Pseudocode
MATLAB
x = current position
xa = singularity position
n = exponent of function
if n<0 then
val = 0
elseif x < xa then
val = 0
else
val = (x-xa)^n
end if
return val
36
Matlab

37
Matlab Overview
• Matlab is the basic program and has many
built-in functions (e.g. trigonometry, matrix,
exponential/logarithmic, etc.)
• Matlab has additional “toolboxes” that can be
added (e.g. aerospace, communications,
financial, control, video/image processing, and
many more). https://www.mathworks.com/products.html
• Matlab $2200, Toolboxes $1000 - $22,000
each (2017)
38
Matlab Can Do Almost Anything!
Type help Type help
Toolbox _____ Toolbox _____
Aerospace aero File Import/Export iofun
Communications comm Programming Language lang
Control control Matrix Functions matfun
Curve Fitting curvefit Operators and Special Characters ops
Data Analysis and Fourier Transforms datafun Optimization and Root Finding optimfun
Demonstrations demo Plot Editing Tools plottools
Elementary Math Functions elfun Polynomial and Interpolation
Elementary Matrices and Matrix Functions polyfun
Functions elmat Random Number Functions randfun
Differential Equation Solvers funfun Plot Annotation and Editing scribe
General Purpose general Sparse Matrx Functions sparfun
Two Dimensional Plots graph2d Specialized Math Functions specfun
Three Dimensional Plots graph3d Specialized Graphic Functions specgraph
General Plotting Functions graphics Character String Functions strfun
Graphical User Interface (GUI) Tool guide Execute Operating System Command system
Help Commands helptools Time and Date Functions timefun
Image Processing images Create Timeseries Object timeseries
Advanced Image Processing and I/O imagesci GUI Functions uitools 39
Introduction
• We will learn MATLAB by using it to numerically solve a
variety of typical simple engineering problems.
• MATLAB has emerged as a powerful tool that is ubiquitous in
the engineering community.
• MATLAB programming skills, such as logical, relational,
conditional, and loop structures, are applicable to other
programming languages such as Python, Java, JavaScript, Perl,
C, C++, ADA, BASIC, Fortran, and Pascal.
• MATLAB is much easier to use than other programming
languages.
• AND plotting is easy!
Download and install MATLAB free on your laptop from chargerware
on the UAH website: http://chargerware.uah.edu/home/matlab
• NOTE: use this URL, Google may take you to the wrong page. 42
Learning Matlab
• The best way to learn Matlab is by USING IT!
• If you have little or no experience with Matlab,
a good place to start is Matlab’s onramp:
https://www.mathworks.com/training-
schedule/matlab-onramp

43
Learning Matlab
• You can use Matlab to check your hand
calculations in any class.
• You can write Matlab programs to automate
common calculations
– enter forces as vectors to calculate resultant force
– constant acceleration equations
– quadratic equation
– calculate your grade in a class
• Matlab has an app!
44
Variables
• Variables are containers for information which store
the information for later use.
• The information is stored in a particular location in
the computer memory.
• The variable name tells the computer the location.
• Variables can contain:
– Number(s): constant, vector, or matrix
– strings of text (characters), and
– other types of data.

45
Variables

• MATLAB variable requirements:


– May consist of numbers and/or
– upper and lower case Roman letters
– can use the underscore, _ (use in place of space)
– MUST start with a letter

46
Variables
• Valid variable names:
Apple Temperature_2 MaxTemp
apple A_very_long_variable_name Velocity_2b

• Invalid variable names:

Max Temp Max-Temp 2b_Velocity

• Limited to 63 characters (can be longer but MATLAB will


ignore additional characters)
• Use the equal sign, = , to assign data to variable

47
Common MATLAB Windows
• Command window
– Enter commands and
data
• Graphics window
– Display plots/graphs
• Edit window
– Used to create/edit
M-files

48
Current Folder
shows available
Matlab Basics Workspace window
variables that have been
files. defined

Function dropdown
menu more
information on
available commands
Detail window showing
first comment and
function usage
Command Window
Command history
Used to
shows all previous
communicate with
keystrokes
MATLAB through
various commands
Assignments
• Read text chapter 1 (and 2).
• Homework # 1 is due Wednesday, January 22nd before
11:59 pm (Canvas clock)
– Remember, no late submissions will be accepted!
• First five workshop due dates (not graded and not
submitted):
– 1 and 2: Jan. 8th
– 3: Wed, Jan. 13th
– 4: Mon, Jan. 15th
– 5: Wed, Jan. 20th
• All assignments are included in the schedule and will
not be announced in the future. 50

You might also like