Docsity

Laboratory Assignment: Two-Dimensional Arrays Matrices | MATH 248, Lab Reports of Mathematics

Toggle sidebar
bg1
Math 248 Computers and Numerical Algorithms
(Pruett)
LABORATORY ASSIGNMENT
Two-Dimensional Arrays (Matrices)
Consider the linear system of equations U~x=~
dwhere Uis the square upper-
triangular matrix given below
1 2 3
0 4 5
0 0 6
(1)
and
~
d= [6,8,12]T(2)
C Write a small FORTRAN 90 program that declares Uto be a two-dimensional
array, initializes Uusing an array constant assignment (inside a RESHAPE
intrinsic function), and prints out the matrix U by rows.
C Add the additional statement
WRITE (*,*) U
near the end of your program, recompile, and re-run. What do you conclude
is the conventional (natural) ordering of 2D-array elements in FORTRAN
90? By rows or by columns?
B Write and compile a MODULE linear algebra containing
SUBROUTINE back substitution
that returns the solution~xof U~x=~
d, given an n×nupper-triangular matrix
Uand an n-vector ~
dRefer to Alg. 6.2 of the class notes.
A Modify your main program above to solve U~x=~
d. That is, CALL SUB-
ROUTINE back substitution for n=3, the matrix of Eq. 1, and the right-
hand-side vector of Eq 2. Print out the solution vector ~xand verify by hand
that it is correct.
A+ Add to your module SUBROUTINE residual, which receives n,U,~
d, and
~xas INTENT(IN) arguments and returns the residual n-vector ~ras an IN-
TENT(OUT) argument. Verify that your back-substitution algorithm is cor-
rect by CALLing the subroutine to compute the residual vector.

Partial preview of the text

Download Laboratory Assignment: Two-Dimensional Arrays Matrices | MATH 248 and more Lab Reports Mathematics in PDF only on Docsity!

Math 248 Computers and Numerical Algorithms

(Pruett)

LABORATORY ASSIGNMENT Two-Dimensional Arrays (Matrices)

Consider the linear system of equations U~x = ~d where U is the square upper- triangular matrix given below  

and d~ = [ 6 , 8 , 12 ]T^ (2)

C Write a small FORTRAN 90 program that declares U to be a two-dimensional array, initializes U using an array constant assignment (inside a RESHAPE intrinsic function), and prints out the matrix U by rows.

C Add the additional statement

WRITE (,) U

near the end of your program, recompile, and re-run. What do you conclude is the conventional (natural) ordering of 2D-array elements in FORTRAN 90? By rows or by columns?

B Write and compile a MODULE linear algebra containing

SUBROUTINE back substitution

that returns the solution ~x of U~x = d~, given an n × n upper-triangular matrix U and an n-vector d~ Refer to Alg. 6.2 of the class notes.

A Modify your main program above to solve U~x = d~. That is, CALL SUB- ROUTINE back substitution for n = 3, the matrix of Eq. 1, and the right- hand-side vector of Eq 2. Print out the solution vector ~x and verify by hand that it is correct.

A+ Add to your module SUBROUTINE residual, which receives n, U, ~d, and ~x as INTENT(IN) arguments and returns the residual n-vector ~r as an IN- TENT(OUT) argument. Verify that your back-substitution algorithm is cor- rect by CALLing the subroutine to compute the residual vector.