Docsity
Docsity

Prepare for your exams
Prepare for your exams

Study with the several resources on Docsity


Earn points to download
Earn points to download

Earn points by helping other students or get them with a premium plan


Guidelines and tips
Guidelines and tips

Linear Algebra in Hydrology: Gaussian Elimination & Jacobi Iterations for Equation Solving, Study notes of Geology

Lab notes for students in the hydrology program at new mexico tech, focusing on linear algebraic quantitative methods in hydrology. It includes instructions for writing codes to perform gaussian elimination and jacobi iterations to solve systems of linear algebraic equations. These methods are essential for understanding and solving real-world hydrological problems.

Typology: Study notes

Pre 2010

Uploaded on 08/08/2009

koofers-user-q18
koofers-user-q18 🇺🇸

10 documents

1 / 2

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
New Mexico Tech Hyd 510
Hydrology Program Lab Notes. 5 Linear Algebraic
Quantitative Methods in Hydrology Equations and Solvers
-5.10-
Linear Equations: Exercises in building solvers
1. Write a code to perform Gaussian Elimination
Given a square (nxn) non-symmetric coefficient matrix A, and (nx1) load vector b, write a Gaussian Elimination
code to solve the system of linear algebraic equations1 Ax=b for unknown vector x. A suggested pseudo-code
(generic algorithm outline) is:
Input n, an nxn matrix A, and an nx1 vector b
Forward Elimination
for j= 1 to n-1
for i = j+1 to n
m
ij = aij/ajj
a
ij = 0; bi = bi – mij*bj
for k = j +1 to n
a
ik = aik – mij * ajk
Backsubstitution
for i= n downto 1
x
i = bi
for j = i+1 to n
x
i = xi – aij*xj
x
i = xi/aii
Output Solution vector x
2. Write a code to perform Jacobi iterations
Given a square (nxn) non-symmetric coefficient matrix A, and (nx1) load vector b, write an code to solve the
system of linear algebraic equations Ax=b for unknown (nx1) vector x using Jacobi iteration.
,...1,0 &,...2,1for ,
1
1
1==
=
=
+knixab
a
x
n
ij
j
jiji
ii
k
i
To start this process you need an initial guess, 0
i
x, for each value of x. If the problem is sufficiently well behaved,
and for decent initial guesses, the method converges. We need a stopping criteria, to stop the process when the
solution is “sufficiently close”. Let’s use a comparison of old and new values of x. If, for any i, the absolute value
1 Note the shift in the notation for the vector of unknowns, from z to x. It is traditional to use x for this purpose, as
in the text, Chapter 20, so I’ve made the shift in this assignment.
pf2

Partial preview of the text

Download Linear Algebra in Hydrology: Gaussian Elimination & Jacobi Iterations for Equation Solving and more Study notes Geology in PDF only on Docsity!

New Mexico Tech Hyd 510 Hydrology Program Lab Notes. 5 Linear Algebraic Quantitative Methods in Hydrology Equations and Solvers

Linear Equations: Exercises in building solvers

1. Write a code to perform Gaussian Elimination Given a square (nxn) non-symmetric coefficient matrix A , and (nx1) load vector b , write a Gaussian Elimination code to solve the system of linear algebraic equations 1 Ax=b for unknown vector x. A suggested pseudo-code (generic algorithm outline) is:

Input n, an nxn matrix A , and an nx1 vector b

Forward Elimination for j= 1 to n- for i = j+1 to n mij = aij /ajj aij = 0; bi = bi – mij *bj

for k = j +1 to n aik = aik – mij * ajk

Backsubstitution for i= n downto 1 xi = bi for j = i+1 to n xi = xi – aij *xj xi = xi /aii

Output Solution vector x

2. Write a code to perform Jacobi iterations

Given a square ( n x n ) non-symmetric coefficient matrix A , and ( n x1) load vector b , write an code to solve the system of linear algebraic equations Ax=b for unknown ( n x1) vector x using Jacobi iteration.

,for 1 , 2 ,... & 0 , 1 ,...

1

≠=

+ b a x i n k

a

x

n

jji

i ij j ii

k i

To start this process you need an initial guess, x i^0 , for each value of x. If the problem is sufficiently well behaved,

and for decent initial guesses, the method converges. We need a stopping criteria, to stop the process when the solution is “sufficiently close”. Let’s use a comparison of old and new values of x. If, for any i , the absolute value

(^1) Note the shift in the notation for the vector of unknowns, from z to x. It is traditional to use x for this purpose, as in the text, Chapter 20, so I’ve made the shift in this assignment.

New Mexico Tech Hyd 510 Hydrology Program Lab Notes. 5 Linear Algebraic Quantitative Methods in Hydrology Equations and Solvers

of the difference x ki +^1 − xik exeeds the roundoff error of the machine/language ( eps in MATLAB) we will

continue to iterate (there are many other possible criteria). We also need to specify the maximum number of iterations we will allow, in order to insure that the method doesn’t run forever. Call this number maxit.

A suggested pseudo-code is: Input Input n, A , b , x^0 , eps, maxit

Initialization,Check Matrix Condition (zeros on diagonal) for i= 1 to n if |aii | < eps, then print ‘algorithm fails because |a (^) ii | < eps’ and exit print b , x^0 , eps, maxit k=0; x =x^0 ;

Perform Iterations

10 while k ≤ maxit

k = k+ for i = 1 to n xoldi = xi for i = 1 to n sum = 0 for j = 1 to n

if j ≠ i, then sum = sum + a ij *xoldj

xi = (bi - sum)/aii

Check convergence for i = 1 to n

if x ik +^1 − xik ≥eps xi , then return to 10

Backsubstitution (see Gaussian Elimination Example)

Output

Print k, x , and exit (inside k loop) Print ‘ Algorithm failed to converge’ if k exceeds maxit and exit