of 31
8/8/2019 M209Introduction
1/31
Math 209: Numerical Analysis
1
8/8/2019 M209Introduction
2/31
Website
http://courses.gdeyoung.com
DescriptionA study of numerical methods for root finding, interpolation,
approximation, integration, differentiation, divided differences, and
applications, using the computer.
2
8/8/2019 M209Introduction
3/31
Objectives
For students to obtain an intuitive and working understandingof some numerical methods for the basic problems of numerical
analysis.
For students to gain some appreciation of the concept of error
and the need to analyze and predict it.
For students to develop some experience in the implementation
of numerical methods by using a computer.
3
8/8/2019 M209Introduction
4/31
Programming
The programming tool that will be used for some assignmentsand illustrations is SciLab.
http://www.scilab.org/
Examples of SciLab equivalents of the Text MatLab programs
can be found on the course web site.
Help for SciLab
SciLab for Dummies, PDF and HTML on website.
SciLabs build in documentation
4
8/8/2019 M209Introduction
5/31
Tests & Final
Tests: 50% and Final 25% of course grade. No late exams given
Announced at least one week before test date.
Format may vary.
5
8/8/2019 M209Introduction
6/31
Homework/Programs
25% of course Grade. Announced at end of class
Please keep up. Late homework is significantly penalized
Homeworknonprograming: follow guidelins in syallbusUse
cover Sheet.
6
8/8/2019 M209Introduction
7/31
Homeworkprograming
Email subject line: Subject: Math 209, Due Date:
yyyy/mm/dd, Section x.x Problem y Short programs (less than 2 pages) you must submit paper
copy in class
Email as attachements include description of your test run
and evidence of successful run.
Programs must include comments.
Programs MUST be syntax error free, that is load with no
errors.
7
8/8/2019 M209Introduction
8/31
The Main Problem
How to computationally solve mathematical problems?
8
8/8/2019 M209Introduction
9/31
The Main Problem
How to computationally solve mathematical problems?
What problems?
Mathematical models are becoming ubiquitous
Global Warming
Enviormental Impact Engineering Studies
Mine pit reclamation
Invasive speices
...
9
8/8/2019 M209Introduction
10/31
Commonality in the problems
Problems include numerical method in solving or exploring the
model.
Approximating functional relationships from data and theroy .
Root Finding f(x) = 0.
Solving linear systems.
Solving DEs
10
8/8/2019 M209Introduction
11/31
Computers ability
Addition Subtraction
Multiplication
Computer only has a finite set of numbers to work withExact
representation is impossible!What is the error?
11
8/8/2019 M209Introduction
12/31
SciLab
Adapted from
ftp://ftp.math.uiowa.edu/pub/atkinson/ENA Materials
/Overheads/matlab lect.pdf
12
8/8/2019 M209Introduction
13/31
About SciLab
SciLab designed for numerical computing as a free alternative
to MatLab. (Another free alternative is PerlPDL).
Strongly oriented towards use of arrays (one dimensional) and
matrices (two dimensional).
Graphics that are easy to use. (Once you get the hang of it)
It can be used interactively or by writing and executing scripts.
It is a procedural language, not an object-oriented language.
SciLab can be installed on Linux, Windows and Mac OS X
from http://www.scilab.org/.
SciLab comes with a SciPad (an editor) and a Scicos
13
8/8/2019 M209Introduction
14/31
SciLab also has a help feature with a built in broswer to
quickly find help various items.
SciLab is an interactive computer language. For example, toevaluate
y = 6 4x + 7x2 + 3x5 +3
x + 2use
y = 6 - 4*x + 7*x*x - 3*x5 + 3/(x+2);
There are many built-in functions, e.g.
exp(x), cos(x), sqrt(x), log(x)
The default arithmetic used in SciLab is double precision and
real. However, complex arithmetic appears automatically when
needed. sqrt(-4) results in an answer of 2i.
14
8/8/2019 M209Introduction
15/31
SciLab works very efficiently with arrays, and many tasks are
best done with arrays. For example, plot sin(x) and cos(x) on
the interval [0, 10].t = [0:.1:10];
x = cos(t);
y = sin(t);
plot2d(t,[x,y])
15
8/8/2019 M209Introduction
16/31
The statement
t = [a:h:b]
with h > 0 creates a row vector of the form
t = [ a ; a + h ; a + 2 h ; : : : ]
giving all values a + jh that are less than b. When h isomitted, it is assumed to be 1. Thus
n = 1:5
creates the row vector
n = [1; 2; 3; 4; 5]
16
8/8/2019 M209Introduction
17/31
ARRAYS
b = [1, 2, 3]
creates a row vector of length 3.
A = [1 2 3; 4 5 6; 7 8 9]
creates the square matrix
1 2 3
4 5 6
7 8 9
Spaces or commas can be used as delimiters in giving the
components of an array; and a semicolon will separate the variousrows of a matrix.
17
8/8/2019 M209Introduction
18/31
For a column vector,
b = [1 3 -6]
results in the column vector
1
3
6
18
8/8/2019 M209Introduction
19/31
ARRAY OPERATIONS
Addition: Do componentwise addition.
A = [1, 2; 3, -2; -6, 1];
B = [2, 3; -3, 2; 2, -2];
C = A + B;
results in the answer
3 50 0
4 1
19
8/8/2019 M209Introduction
20/31
ARRAY OPERATIONS
Multiplication by a constant: Multiply the constant times each
component of the array.
D = 2*A;
results in the answer
2 4
6 4
12 2
20
8/8/2019 M209Introduction
21/31
ARRAY OPERATIONSMatrix multiplication: This has the standard meaning.
E = [1, -2; 2, -1; -3, 2];
F = [2, -1, 3; -1, 2, 3];
G = E*F;
results in the answer
G =
1 2
2 1
3 2
2 1 31 2 3
=
4 5 3
5 4 3
8 7 3
A nonstandard notation: H = 3 + F; results in the computation
H = 3
1 1 1
1 1 1
+2 1 31 2 3
=
5 2 6
2 5 6
21
8/8/2019 M209Introduction
22/31
COMPONENTWISE OPERATIONS
SciLab also has component-wise operations for multiplication,
division and exponentiation. These three operations are denoted byusing a period to precede the usual symbol for the operation. With
a = [ 1 2 3 ] ; b = [ 2 - 1 4 ] ;
we have
a.*b = [2 -2 12]
a./b = [0.5 -2.0 0.75]
a.^3 = [1 8 27]
2.^a = [2 4 8]
b.^a = [2 1 64]
22
8/8/2019 M209Introduction
23/31
The expression
y = 6 - 4*x + 7*x*x - 3*x5 + 3/(x+2);
can be evaluated at all of the elements of an array x using thecommand
y = 6 - 4*x + 7*x.*x - 3*x.^5 + 3./(x+2);
The output y is then an array of the same size as x.
23
8/8/2019 M209Introduction
24/31
SPECIAL ARRAYS
A = zeros(2,3)
produces an array with 2 rows and 3 columns, with all components
set to zero, 0 0 0
0 0 0
24
8/8/2019 M209Introduction
25/31
SPECIAL ARRAYS
B = ones(2,3)
produces an array with 2 rows and 3 columns, with all components
set to 1, 1 1 1
1 1 1
25
8/8/2019 M209Introduction
26/31
SPECIAL ARRAYS
eye(3,3) results in the 3 3 identity matrix,
1 0 0
0 1 0
0 0 1
Inzeros
,ones
andeye
of the above the argument may be replacedwith a matrix, the size of the result is the size of the matrix.
26
8/8/2019 M209Introduction
27/31
ARRAY FUNCTIONS
There are many SciLab commands that operate on arrays, we
include only a very few here. For a vector x, row or column, oflength n , we have the following functions.
max(x) = maximum component of x
min(x) = minimum component of x
abs(x) = vector of absolute values of components of x
sum(x) = sum of the components of x
Use the help browser to find many other functions.
27
8/8/2019 M209Introduction
28/31
OTHER COMMANDS
clear: To remove the current variables from use.
clc: To clear the output screen.clf: To clear the graphics screen.
help command name
: Brief description of command name.
28
8/8/2019 M209Introduction
29/31
SCRIPT FILES
A list of interactive commands can be stored as a script file. For
example, store
t = 0:.1:10;
x = cos(t);
y = sin(t);
plot(t,x,t,y)
with the file name plot trig.sci. Then to loaded in to SciLab using
the file menu or loading it from SciPad.
29
8/8/2019 M209Introduction
30/31
FUNCTIONS
To create a function, we proceed similarly, but now there are inputand output parameters. Consider a function for evaluating the
polynomial
p(x) = a1 + a2x + a3x2 + +anx
n1
SciLab does not allow zero subscripts for arrays. The following
function would be stored under the name polyeval.sci. no Thecoeffcients {aj} are given to the function in the array named coef,
and the polynomial is to be evaluated at all of the components of
the array x.
30
8/8/2019 M209Introduction
31/31
function [value] = polyeval(x,coef);
//
// function value = polyeval(x,coef)
//
// Evaluate a polynomial at the points given
// in x. The coeficients are to be given in
// coef. The constant term in the polynomial
// is coef(1).
n = length(coef)
value = coef(n)*ones(x);
for i = n-1:-1:1
value = coef(i) + x.*value;
end
endfunction
31