Uploaded by dzaganianino

TTF5 Code 1

advertisement
Problem Statement: Linear System Solver with
Thomas Algorithm
You are tasked with creating a Python program that can solve a tridiagonal
system of linear equations of the form Ax = b using the Thomas algorithm.
The program should take as input a tridiagonal matrix A and a vector b, and
it should find and display the solution vector x.
Input
1. The user will provide the dimensions of the tridiagonal matrix A (number
of rows and columns), and then they will enter the values for the matrix
elements row by row.
2. The user will also input the values for the elements of the vector b.
Output
1. Your program should validate the input to ensure that the matrix is indeed
tridiagonal (non-zero values only in the main diagonal and its two adjacent
diagonals).
2. Implement the Thomas algorithm to solve the tridiagonal system of equations Ax = b. Display the values of x as the output.
3. Handle edge cases and provide appropriate error messages for cases where
the Thomas algorithm cannot be applied (e.g., if the input matrix is not
tridiagonal or if it’s singular).
4. Ensure that your program does not use built-in functions or libraries for
solving the system but instead implements the Thomas algorithm itself.
Programming Requirements
• Your program should be implemented in Python.
• The Thomas algorithm should be implemented to solve the tridiagonal
system of equations.
• Handle user input validation and provide clear error messages for invalid
input.
Implementation Guidelines
Here’s a high-level outline of the steps your Python program should follow:
1
#
n
A
b
Step 1: Input matrix A
= int(input("Enter the
= [] # Initialize the
= [] # Initialize the
and vector b
dimension of the matrix: "))
tridiagonal matrix
vector
# Step 2: Fill in the matrix A and vector b
# Step 3: Validate that A is a tridiagonal matrix
# Step 4: Implement the Thomas algorithm to solve Ax = b
# Step 5: Handle edge cases and display results
This problem will require you to implement the Thomas algorithm to solve
the tridiagonal system, and it’s a valuable exercise in numerical methods and
algorithm implementation. do not use built-in functions
2
Download