# CS3911 Introduction to Numerical Methods with Fortran Exam 2

Document Sample

```					CS3911 Intro. to Numerical Methods with Fortran Exam 2                1
CS3911 Introduction to Numerical Methods with
Fortran Exam 2
100 points – 6 pages

Name:

• Most of the following questions only require very short answers.
Usually a few concise and accurate sentences would be suﬃcient.
Please write to the point. If I don’t understand what you are
saying, I believe, in most cases, you don’t understand the subject.
• Justify your answer with a convincing argument. If there is no jus-
tiﬁcation when it is needed, you will receive ZERO point for that
question even though you have provided a correct answer. I con-
sider a good and correct justiﬁcation more important than only a
right answer. Thus, if you provide a very vague answer without a
• It is a requirement that each computed result must have ﬁve or
more signiﬁcant digits. Without observing this requirement, you
• Do those problems you know how to do ﬁrst. Otherwise, you
may not be able to complete this exam on time. If you follow our
classroom discussions and understand the most basic components,
you should be able to quickly complete more than 60% of this
exam. The remaining problems, however, test if you are able to
apply and use the basics properly.
CS3911 Intro. to Numerical Methods with Fortran Exam 2                                       2
1. Fortran 90, Accuracy and Reliability

(a) [6 points] What is the output of the following Fortran 90 program segment? Make sure
you will write down the answer properly.
INTEGER                           :: i, j, n = 4
CHARACTER(LEN=*), PARAMETER :: CROSS = ’+’, STAR = ’*’

DO i = 1, n
WRITE(*,*)       (CROSS, j=1,i-1), (STAR, j=i,n)
END DO

(b) [6 points] What is wrong in the following Fortran 90 program segment? Identify the
place and problem clearly and provide a convincing elaboration.
PROGRAM Exam_Problem
IMPLICIT NONE
INTEGER :: x, y
! --- other statements
CALL Test(x+2, y+5)
! --- other statement
CONTAINS
SUBROUTINE Test(p, q)
IMPLICIT NONE
INTEGER, INTENT(INOUT) :: p, q
INTEGER                    :: h
p = p*p + q*q
q = p - q
END SUBROUTINE Test
END PROGRAM Exam_Problem
(c) [10 points] The geometric mean of a set of positive numbers x1 , x2, . . ., xn is
√
n
x1 × x2 × · · · × xn = (x1 × x2 × · · · × xn )1/n

Develop a reliable way to compute the geometric mean. You are supposed to (1)
clearly write down your algorithm in Fortran 90 (just a short piece of code is
good enough) with a convicting elaboration, (2) show that your way indeed
computes the geometric mean accuracy and reliably, and (3) the trivial and
straightforward way does not work properly. Without doing so, you receive
zero point.
CS3911 Intro. to Numerical Methods with Fortran Exam 2                                    3
2. Linear Algebra

(a) [15 points] Find the LU-decomposition of the following matrix without pivoting. You
should show all computation steps. Only providing an answer and/or using
a wrong method receives zero point.
                  
1  1   0  2

   −1  1   1 −2 

A=                  
    1 −1   2  3 
0  2   7  6

(b) [6 points] Suppose a matrix A has the following LU-decomposition using 2 row swaps
and 3 column swaps. Compute the determinant of A.
                             
1             1 1     7 0
              
   0 1           2     4 0 

             ·             
   1 0 1              −1 6 
1 1 0 1                 3
CS3911 Intro. to Numerical Methods with Fortran Exam 2                                               4
(c) [12 points] Use Gauss-Seidel method to solve the following system of linear equations,
and ﬁll the table below with your results. The initial value (i.e., iteration 0) is x = y =
z = 0, and you only do two iterations (i.e., iterations 1 and 2).

4x + y + z = 1
x + 4y + z = 2
x + y + 4z = 4

Iteration               x                          y                   z

0                   0                          0                   0

1

2

(d) [20 points] Suppose a program read in the following system of linear equations:
                                                             
1 3                2                          1 0         1 3
                                                             
A·x = B     where A =            ,   B=            and A = L·U =           ·         
1 5                3                          1 1         0 2

and computed x = y = 1. This solution is inaccurate. Use the iterative reﬁnement
method to improve the accuracy of this “solution.” You have to show all computa-
tion steps using the given LU-decomposition, and explain how you get the
results. Otherwise (e.g., only providing an answer and/or asking me to guess
your intention from a bunch of numbers), you will receive zero point.
CS3911 Intro. to Numerical Methods with Fortran Exam 2                                           5
3. Interpolation
Suppose there are ﬁve data points (x0 , y0) = (−2, 0), (x1 , y1) = (−1, 3), (x2 , y2) = (0, 4),
(x3, y3) = (1, 3) and (x4, y4 ) = (2, 0). Do the following problems:

(a) [10 points] Given a polynomial of degree n as follows,

Pn (x) = a0 + a1 x + a2x2 + a3x3 + · · · + an xn

suggest an eﬃcient way to evaluate Pn (x) so that the complexity is O(n). You should
provide an algorithm and its complexity analysis. A method that does not

(b) [15 points] Find the Lagrange interpolating polynomial for the given data points. You
should show all computation steps. Only providing an answer and/or using
a wrong method receives zero point.
CS3911 Intro. to Numerical Methods with Fortran Exam 2   6

a          6
1 b          6
c         10
a         15
b          6
2
c         12
d         20
a         10
3
b         15
Total     100

```
DOCUMENT INFO
Shared By:
Categories:
Stats:
 views: 16 posted: 1/14/2010 language: English pages: 6
How are you planning on using Docstoc?