联系方式

  • QQ:99515681
  • 邮箱:99515681@qq.com
  • 工作时间:8:00-21:00
  • 微信:codinghelp

您当前位置:首页 >> Java编程Java编程

日期:2024-03-06 09:33

MECH20042/AERO20542 Numerical Methods and Computing

Laboratory exercise 1: Direct methods for the solution of

tridiagonal systems of linear equations

Solution of systems of linear equations is one of the most frequently encountered problems in

numerical modelling and simulation. Efficient numerical methods, both in terms of the execution time

and memory storage are essential to complete this task. Sparse systems of linear equations arise in

many applications, such as finite element or finite volume solution of differential equations. Sparse

linear systems have coefficient matrices that are sparse, i.e., a large proportion of the elements are

equal to zero. Banded matrices are a special class of sparse matrices in which the non-zero coefficients

are concentrated about the main diagonal.

Storing sparse matrices in computer memory as two-dimensional arrays is inefficient, as many zero

elements are kept needlessly in computer memory. Banded matrices can be stored by their diagonals,

where each diagonal is stored as a one-dimensional array (a vector). With this setup a tridiagonal

matrix ?? of size ?? × ??


can be stored using three vectors as follows:

?? = [??11 ??22 ? ??????]

?? ∈ ??

??

,

?? = [??21 ??32 ? ????,???1]

?? ∈ ??

???1

,

?? = [??12 ??23 ? ?????1,??]

?? ∈ ??

???1

.

The Gaussian elimination technique applied to a tridiagonal system ???? = ?? is particularly simple,

because only the non-zero elements in the sub-diagonal held in vector ?? need to be eliminated. This

algorithm, known as the Thomas algorithm, proceeds as follows:

FORWARD ELIMINATION BACKSUBSTITUTION

?????? = ?????? ?

????,???1

?????1,???1

?????1,?? ???? =

????

??????

???? = ???? ?

????,???1

?????1,???1

?????1 ???? =

1

??????

(???? ? ????,??+1 ????+1)

?? = 2, … , ?? ?? = ?? ? 1, … ,1

TASK 1. Calculate the number of arithmetic operations that are required to solve a tridiagonal system

???? = ?? of size ?? using the Thomas algorithm. Based on this result, determine the asymptotic

complexity of the Thomas algorithm, and compare it to the asymptotic complexity of the standard

Gaussian elimination.

TASK 2. Rewrite the Thomas algorithm in terms of the arrays ??,??, and ?? introduced to store the matrix

?? efficiently.

TASK 3. Implement the Thomas algorithm from TASK 2 as a Python function. The input parameters to

the function should be the coefficient matrix ?? (stored as three arrays ??,??, and ??) and the right-hand

side vector ??. The output should be the solution vector ??. The coefficient matrix and the right-hand

side should be defined in the main script and passed to the function that solves the system.

TASK 4. Test your code by solving the linear system of size ?? = 10 with the values ?? = 2, and ?? = ?? =

?1. Set the right-hand side to ?? = ??. To verify the correctness of your code, compare the solution

vector obtained from the Thomas algorithm to that obtained by applying the direct solver

numpy.linalg.solve(). For the latter, the coefficient matrix should be assembled.

TASK 5. Solve five linear systems ???? = ?? with ?? = 2, ?? = ?? = ?1 and ?? = ?? varying the problem size

?? between 106

and 108

. Record the execution times in seconds for each case. To accomplish this task,

explore the Python function timer() from the package timeit (refer to the code for matrix

multiplication covered in lectures). Plot a graph where the obtained execution times are represented

as the function of the problem size ??. What are your conclusions about the cost of the Thomas

algorithm?


相关文章

版权所有:编程辅导网 2021 All Rights Reserved 联系方式:QQ:99515681 微信:codinghelp 电子信箱:99515681@qq.com
免责声明:本站部分内容从网络整理而来,只供参考!如有版权问题可联系本站删除。 站长地图

python代写
微信客服:codinghelp