You are on page 1of 15

:

883110263

3.................................................................................................................................................... Tdma
tdma 4.......................................................................... C

.............................................................................................
6 tdma

8..................................................................................................................................................... penta
penta 8......................................................................... C

........................................................................................... penta
11

12................................................................................................................................................ bdsolv
bdsolv 12....................................................................... C

.......................................................................................... bdsolv
15

2
Tdma

Introduction
The tridiagonal matrix algorithm (TDMA), also known as the Thomas algorithm, is a simplified
form of Gaussian elimination that can be used to solve tridiagonal systems of equations. A
tridiagonal system may be written as

Where and . In matrix form, this system is written as

For such systems, the solution can be obtained in operations instead of required by
Gaussian Elimination. A first sweep eliminates the 's, and then an (abbreviated) backward
substitution produces the solution. Example of such matrices commonly arise from the
discretization of 1D problems (e.g. the 1D Poisson problem).

Algorithm :
The following algorithm performs the TDMA, overwriting the original arrays. In some situations
this is not desirable, so some prefer to copy the original arrays beforehand.

Forward elimination phase

for k = 2 step until n do

end loop (k)

Backward substitution phase

3
for k = n-1 stepdown until 1 do

end loop (k)

C tdma
#include <stdio.h>

#include <conio.h>

int main()

int n,i;

float a[100],b[100],c[100],v[100],x[100],m;

/**

* n - number of equations

* a - sub-diagonal (means it is the diagonal below the main diagonal) -- element a[1] is not used

* b - the main diagonal

* c - sup-diagonal (means it is the diagonal above the main diagonal) -- element c[n] is not used

* v - right part

* x - the answer

*/

printf("\n Enter dimensions: n:");

scanf("%d", &n);

for(i=1;i<=n;i++)

printf("enter b[%d]:",i);

scanf("%f",&b[i]);

for(i=2;i<=n;i++)

printf("enter a[%d]:",i);

scanf("%f",&a[i]);

4
}

for(i=1;i<=n-1;i++)

printf("enter c[%d]:",i);

scanf("%f",&c[i]);

for(i=1;i<=n;i++)

printf("enter v[%d]:",i);

scanf("%f",&v[i]);

for(i=2;i<=n;i++)

m=a[i]/b[i-1];

b[i]=b[i]-m*c[i-1];

v[i]=v[i]-m*v[i-1];

x[n]=v[n]/b[n];

printf("\nx[%d]=%6f",n,x[n]);

for(i=n-1;i>=1;i--)

x[i]=(v[i]-c[i]*x[i+1])/b[i];

printf("\nx[%d]=%6f",i,x[i]);

getch();

return 0;

5
: 1 100 .
.

:

=5
2

1 = 100 , T5 = 0

= 0.25


+1 2+1 + 1
+1
= +1
2 +1
+1
5 +1 2+1 + 1
+1
= +1
+1
5+1 11+1 + 51
+1
=

)(2 )(2
=2 53 112 = 600

)(2 )(2 )(2


=3 54 113 + 52 = 100

)(2 )(2
=4 5 0 114 + 53 = 100

11 5 0 2 600
5 11 5 3 = 100
0 5 11 4 100

1 = b2 = b3 = 11

c1 = c2 = 5

2 = 3 = 5

6
1 = 600 , 2 = 100 , 3 = 100

:
4 = 38.540329

3 = 64.788734

2 = 83.994881

7
penta
A VLSI algorithm for solving a special block-five-diagonal system of linear algebraic equations is
presented. The algorithm is considered for a VLSI parallel computational model where both the time of
the algorithm and the area of its design are components of the complexity estimations. The linear
system arises from the finite-difference approximation of the first biharmonic boundary value problem.
The algorithm computes the solution by a direct method based on Woodbury's formula (see G.H. Golub
and C.F. Van Loan, Matrix Computations, Johns Hopkins Univ. Press, Baltimore, 1989). For the problem
on an nn grid, the VLSI algorithm needs an area A=O(n 2log2n) and a time T=O(n log n). The global AT2-
complexity of this method is AT2=O(n4 log4n). This result represents the best upper bound for solving this
problem in VLSI. Moreover, this algorithmic design could serve as a preliminary step towards the
analysis and development of more detailed structures of specialized VLSI computer devices for solving
the biharmonic problem

C penta

// habibollah dehghan 883110263

// algorithm PENTA

#include <stdio.h>

#include <conio.h>

int main()

int n,i;

float a[100],b[100],c[100],v[100],x[100],e[100],f[100],m;

/**

* n - Number of equations

* e - Lowest diagonal.Elements e[1] and e[2] are not used

* a - Lower diagonal.Element a[1] is not used

* b - Main diagonal

* c - Upper diagonal.Element c[n] is not used

* f - Uppermost diagonal.Elements f[n-1]and f[n] are not used.

* v - Right hand side of the system

* x - the answer

*/

printf("\n Enter dimensions: n:");

8
scanf("%d", &n);

for(i=3;i<=n;i++)

printf("enter e[%d]:",i);

scanf("%f",&e[i]);

for(i=2;i<=n;i++)

printf("enter a[%d]:",i);

scanf("%f",&a[i]);

for(i=1;i<=n;i++)

printf("enter b[%d]:",i);

scanf("%f",&b[i]);

for(i=1;i<=n-1;i++)

printf("enter c[%d]:",i);

scanf("%f",&c[i]);

for(i=1;i<=n-2;i++)

printf("enter f[%d]:",i);

scanf("%f",&f[i]);

for(i=1;i<=n;i++)

printf("enter v[%d]:",i);

scanf("%f",&v[i]);

for(i=2;i<=n-1;i++)

9
m=a[i]/b[i-1];

b[i]=b[i]-m*c[i-1];

v[i]=v[i]-m*v[i-1];

c[i]=c[i]-m*f[i-1];

m=e[i+1]/b[i+1];

a[i+1]=a[i+1]-m*c[i-1];

b[i+1]=b[i+1]-m*f[i-1];

v[i+1]=v[i+1]-m*v[i-1];

m=a[n]/b[n-1];

b[n]=b[n]-m*c[n-1];

x[n]=(v[n]-m*v[n-1])/b[n];

x[n-1]=(v[n-1]-x[n]*c[n-1])/b[n-1];

printf("\nx[%d]=%6f",n,x[n]);

printf("\nx[%d]=%6f",n-1,x[n-1]);

for(i=n-2;i>=1;i--)

x[i]=(v[i]-f[i]*x[i+2]-c[i]*x[i+1])/b[i];

printf("\nx[%d]=%6f",i,x[i]);

getch();

return 0;

10
11
) n (bdsolv
C n
// habibollah dehghan 883110263

// algorithm bdsolve

#include <stdio.h>

#include <conio.h>

#include <math.h>

#include <stdlib.h>

int main()

int n,m1,m2,m3,l,i,j,k,i2,ifail,p,s;

float a[100][100],b[100],x[100],q,q1,zero=0.0e0;

/**

* n - Number of equations

* m1 - Number of subdiagonals

* m2 - Number of superdiagonals

* b - Right hand side of the system

* a - Matrix of coefficients dimensioned

* x - the answer

*/

printf("\n Enter Number of equations : n:");

scanf("%d", &n);

printf("\n Enter Number of subdiagonals : m1:");

scanf("%d", &m1);

printf("\n Enter Number of superdiagonals : m2:");

scanf("%d", &m2);

for(i=1;i<=n;i++)

for(j=1;j<=n;j++)

printf("enter a[%d][%d]:",i,j);

scanf("%f",&a[i][j]);

12
}

for(i=1;i<=n;i++)

printf("enter b[%d]:",i);

scanf("%f",&b[i]);

ifail = 0;

// ! --- Elimination ---

l = m1;

for(k = 1;k<=n;k++)

q = a[k][1];

i = k;

if(l < n)

l = l + 1;

for(j = k + 1;j<=l;j++)

q1 = a[j][1];

if(abs(q1) > abs(q))

q = q1;

i = j;

if( q == zero)

ifail = (-1);

printf("\n Singular matrix A (Zero pivot)");

goto akhar;

if(i /= k)

13
q = b[k];

b[k] = b[i];

b[i] = q;

for(j = 1 ;j<=m2 + m3;j++)

q = a[k][j];

a[k][j] = a[i][j];

a[i][j] = q;

for(i =k + 1;i<=l ;i++)

q = a[i][1]/a[k][1];

b[i] = b[i] - q*b[k];

for(j =2;j<=m2 + m3 ;j++)

a[i][j-1] = a[i][j] - q*a[k][j];

a[i][m2+m3] = zero;

printf("\n successful factorization");

// ! --- Backsubstitution ---

l = (-1)*m1;

for(i = n ; i>=1 ;i--)

q = b[i];

x[i] = q;

i2 = i + m1;

for(k =1 - m1;k<=l ;k++)

q = q - a[i][k+m3]*x[k + i2];

x[i] = q/a[i][1];

printf("\nx[%d]=%6f",i,x[i]);

if(l < m2)

l = l + 1;

14
}

akhar:

getch();

//return ;

15

You might also like