'/N Enter Number of Equation:': For For End End For For End For End End For For End End
This document describes a program that uses the Thomas algorithm method to solve simultaneous equations. The program takes user input to build the coefficient matrix and constant vector, applies the Thomas algorithm to solve for the unknown variables, and outputs the results. It prompts the user to enter the number of equations, accepts input to populate the matrix and constant vector row by row, performs Gaussian elimination steps to transform the matrix, and calculates and displays the solution values.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0 ratings0% found this document useful (0 votes)
36 views2 pages
'/N Enter Number of Equation:': For For End End For For End For End End For For End End
This document describes a program that uses the Thomas algorithm method to solve simultaneous equations. The program takes user input to build the coefficient matrix and constant vector, applies the Thomas algorithm to solve for the unknown variables, and outputs the results. It prompts the user to enter the number of equations, accepts input to populate the matrix and constant vector row by row, performs Gaussian elimination steps to transform the matrix, and calculates and displays the solution values.
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2
Batch- T2
PROGRAM TO SOLVE SIMULTANEOUS EQUATIONS BY
THOMAS ALGORITHM METHOD
n=input('\n Enter number of equation :');
for i=1:n for j=1:n a(i,j)=input('\n Enter Matrix Element :'); end b(i,1)=input('\n Enter Constant:'); end for i=2:n fact=a(i,i-1)/a(i-1,i-1); for j=1:n a(i-1,j)=a(i-1,j)*fact; end b(i-1)=b(i-1)*fact; for j=1:n a(i-1,j)=a(i-1,j)*fact; end b(i-1)=b(i-1)*fact; end for i=1:n dig=a(i,i); for j=1:n a(i,j)=a(i,j)/dig; end b(i)=b(i)/dig; end res(n)=b(n); i=n-1:1:1 res(i)=b(i); for j=i:n-1 res(i)=res(i)-res(j+1)*a(i,j+1); end i=1:n fprintf('\n Value of x%d=%f',i,res(i));
PROGRAM OUTPUT
Enter number of equation :4
Enter matrix element row-wise :1 Enter matrix element row-wise :2 Enter matrix element row-wise :0 Enter matrix element row-wise :0 Enter matrix element row-wise :-1 Enter matrix element row-wise :1 Enter matrix element row-wise :2 Enter matrix element row-wise :0 Enter matrix element row-wise :0 Enter matrix element row-wise :1 Enter matrix element row-wise :3 Enter matrix element row-wise :1 Enter matrix element row-wise :0 Enter matrix element row-wise :0 Enter matrix element row-wise :2 Enter matrix element row-wise :2 Enter the second matrix element:4 Enter the second matrix element:1 Enter the second matrix element:7 Enter the second matrix element:8 Value of x1=0.000000 Value of x2=0.000000 Value of x3=0.000000 Value of x4=6.000000