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

Math 209: Numerical Analysis

Math 209 is a numerical analysis course that uses the SciLab programming tool. The course covers numerical methods for root finding, interpolation, integration, differentiation, and applications. Students will implement numerical methods in SciLab programs and gain experience analyzing and predicting errors in numerical solutions. Assessment includes tests, a final exam, homework assignments involving both non-programming and programming problems in SciLab.

Uploaded by

Kish Nvs
Copyright
© Attribution Non-Commercial (BY-NC)
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)
82 views

Math 209: Numerical Analysis

Math 209 is a numerical analysis course that uses the SciLab programming tool. The course covers numerical methods for root finding, interpolation, integration, differentiation, and applications. Students will implement numerical methods in SciLab programs and gain experience analyzing and predicting errors in numerical solutions. Assessment includes tests, a final exam, homework assignments involving both non-programming and programming problems in SciLab.

Uploaded by

Kish Nvs
Copyright
© Attribution Non-Commercial (BY-NC)
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/ 31

Math 209: Numerical Analysis

1
Website
http://courses.gdeyoung.com

Description
A study of numerical methods for root finding, interpolation,
approximation, integration, differentiation, divided differences, and
applications, using the computer.

2
Objectives
• For students to obtain an intuitive and working understanding
of 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
Programming
• The programming tool that will be used for some assignments
and 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.
– SciLab’s build in documentation

4
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
Homework/Programs
• 25% of course Grade.
• Announced at end of class
• Please keep up. Late homework is significantly penalized
• Homework–nonprograming: follow guidelins in syallbus–Use
cover Sheet.

6
• Homework–programing
– 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
The Main Problem
How to computationally solve mathematical problems?

8
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
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 DE’s

10
Computers ability
• Addition
• Subtraction
• Multiplication
Computer only has a finite set of numbers to work with—Exact
representation is impossible!
What is the error?

11
SciLab

Adapted from

ftp://ftp.math.uiowa.edu/pub/atkinson/ENA Materials
/Overheads/matlab lect.pdf

12
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
• 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, to
evaluate
2 5 3
y = 6 − 4x + 7x + 3x +
x+2
use
y = 6 - 4*x + 7*x*x - 3*xˆ5 + 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
• 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
• The statement
t = [a:h:b]

with h > 0 creates a row vector of the form


t = [a; a + h; a + 2h; : : : ]

giving all values a + jh that are less than b. When h is


omitted, it is assumed to be 1. Thus
n = 1:5

creates the row vector


n = [1; 2; 3; 4; 5]

16
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 various
rows of a matrix.

17
For a column vector,
b = [1 3 -6]’
results in the column vector
 
1
 
 3 
 
−6

18
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 5
 
0 0
 
−4 −1

19
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
ARRAY OPERATIONS
Matrix 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
   
1 −2   4 −5 −3
  2 −1 3  
G=  2 −1
 = 5
 −4 3 
−1 2 3
−3 2 −8 7 −3

A nonstandard notation: H = 3 + F; results in the computation


    
1 1 1 +2 −1 3 5 2 6
H=3     =  
1 1 1 −1 2 3 2 5 6

21
COMPONENTWISE OPERATIONS
SciLab also has component-wise operations for multiplication,
division and exponentiation. These three operations are denoted by
using 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
The expression
y = 6 - 4*x + 7*x*x - 3*xˆ5 + 3/(x+2);
can be evaluated at all of the elements of an array x using the
command
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
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
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
SPECIAL ARRAYS
eye(3,3) results in the 3 3 identity matrix,
 
1 0 0
 
0 1 0
 
0 0 1

In zeros, ones and eye of the above the argument may be replaced
with a matrix, the size of the result is the size of the matrix.

26
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, of
length 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
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
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
FUNCTIONS
To create a function, we proceed similarly, but now there are input
and output parameters. Consider a function for evaluating the
polynomial
p(x) = a1 + a2 x + a3 x2 + +an xn−1
SciLab does not allow zero subscripts for arrays. The following
function would be stored under the name polyeval.sci. no The
coeffcients {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
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

You might also like