Solving a Tridiagonal System of Equations

In summary, the conversation discusses the process of writing a code to solve a system of equations by using matrices, specifically a tridiagonal matrix form. The first step is to input the coefficients of the variables and the answers to the equations using an array. Then, the equations are printed in the proper form. However, there is a need to check the accuracy of the solutions obtained. The suggested code involves multiplying the matrix A with the roots x and comparing it to the vector b using nested do loops. If the result is zero or a small number, then the solutions are correct.
  • #1
just physics
4
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
  • #2
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.
 

Related to Solving a Tridiagonal System of Equations

1. What is a tridiagonal system of equations?

A tridiagonal system of equations is a set of simultaneous equations where the variables only appear in the main diagonal and the diagonals immediately above and below it. In other words, the non-zero coefficients are confined to three diagonals in the matrix representation of the system.

2. Why is solving a tridiagonal system important?

Solving a tridiagonal system is important because it often arises in practical applications, particularly in numerical analysis and computational physics. It is also computationally efficient and can provide accurate solutions to a wide range of problems.

3. What methods can be used to solve a tridiagonal system of equations?

There are several methods that can be used to solve a tridiagonal system of equations, including Gaussian elimination, Thomas algorithm, and LU decomposition. Each method has its own advantages and disadvantages, so the choice of method depends on the specific problem at hand.

4. How does the Thomas algorithm work?

The Thomas algorithm, also known as the tridiagonal matrix algorithm, is a specialized form of Gaussian elimination that takes advantage of the tridiagonal structure of the system. It involves forward elimination to reduce the system to upper triangular form, followed by back substitution to obtain the solution. This method is particularly efficient for larger systems.

5. Are there any tips for solving a tridiagonal system efficiently?

Yes, there are a few tips that can help with efficiently solving a tridiagonal system. These include using a method specifically designed for tridiagonal systems, reducing the system to a smaller size if possible, and using a computer program or calculator to perform the calculations accurately and quickly.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
18
Views
2K
  • Programming and Computer Science
Replies
2
Views
5K
  • Programming and Computer Science
Replies
2
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
13
Views
2K
  • Engineering and Comp Sci Homework Help
Replies
16
Views
1K
  • Linear and Abstract Algebra
Replies
2
Views
885
  • Precalculus Mathematics Homework Help
Replies
4
Views
2K
  • Precalculus Mathematics Homework Help
Replies
6
Views
4K
  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
1
Views
2K
Back
Top