Solving a Tridiagonal System of Equations

Click For Summary
SUMMARY

This discussion focuses on solving a tridiagonal system of equations using matrix representation. The process involves entering coefficients (r1, r2, r3, ...) and constants (b1, b2, b3, ...) into arrays, followed by implementing a verification step to check the accuracy of the computed solutions. A sample code structure is provided, utilizing nested loops to perform matrix multiplication and compare the results against the original constants. The solution is confirmed if the difference between the computed and expected values is zero or negligible.

PREREQUISITES
  • Understanding of tridiagonal matrices and their properties
  • Familiarity with matrix multiplication algorithms
  • Proficiency in a programming language capable of handling arrays (e.g., Fortran, Python)
  • Knowledge of numerical methods for solving systems of equations
NEXT STEPS
  • Implement matrix multiplication in your chosen programming language
  • Explore numerical methods for solving tridiagonal systems, such as the Thomas algorithm
  • Learn about error analysis in numerical solutions to verify accuracy
  • Investigate optimization techniques for handling large tridiagonal matrices
USEFUL FOR

Mathematicians, software developers, and engineers working on numerical analysis, particularly those dealing with systems of equations and matrix computations.

just physics
Messages
4
Reaction score
0
we have to write a code to solve system of equations by writing them in matricies (tridiagonal matrix) form ...
the first step is to enter the coefficients of the variables (r1,r2,r3,...) and then the answers to the equations (b1,b2,b3,...) by using array , and print the equations in the form:
r1X1+r2X2=b1
r1X1+r2X2+r3X3=b2
i made the code and i get the answers but i have to insert a code to check the answers that i get i.e: if x1=1 ,x2=6 ,r1=1,r2=2,b1=13
then the program print
1*1+2*6=13
i can't make this step can any1 help me please :(
 
Last edited:
Physics news on Phys.org
You have solved Ax=b where you have the 9 members of matrix A, three members of vector b and the the three roots making up vector x.

Write a code that multiplies matrix A (which you'll have to populate with appropriate numbers) by roots x and compare to vector b. The multiplication can be done with two nested do loops such as

do 2 i=1,3
p=0.0
do 1 j=1,3
p=p+a(i,j)*x(j)
1 continue
q=b(i)-p
write(6,100)i,q
2 continue
100 format(1i5,1f10.5)

If q is zero or some very small number, then you've solved it correctly. I am assuming you can use dimension statements correctly.
 

Similar threads

  • · Replies 2 ·
Replies
2
Views
5K
  • · Replies 2 ·
Replies
2
Views
3K
  • · Replies 7 ·
Replies
7
Views
2K
  • · Replies 13 ·
Replies
13
Views
2K
  • · Replies 0 ·
Replies
0
Views
3K
  • · Replies 18 ·
Replies
18
Views
3K
  • · Replies 6 ·
Replies
6
Views
4K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
Replies
19
Views
4K