Professional Documents
Culture Documents
TDMA Fortran C
TDMA Fortran C
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
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.
3
for k = n-1 stepdown until 1 do
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
* c - sup-diagonal (means it is the diagonal above the main diagonal) -- element c[n] is not used
* v - right part
* x - the answer
*/
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
=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
// 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
* b - Main diagonal
* x - the answer
*/
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
* x - the answer
*/
scanf("%d", &n);
scanf("%d", &m1);
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;
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];
q = q1;
i = j;
if( q == zero)
ifail = (-1);
goto akhar;
if(i /= k)
13
q = b[k];
b[k] = b[i];
b[i] = q;
q = a[k][j];
a[k][j] = a[i][j];
a[i][j] = q;
q = a[i][1]/a[k][1];
a[i][m2+m3] = zero;
l = (-1)*m1;
q = b[i];
x[i] = q;
i2 = i + m1;
q = q - a[i][k+m3]*x[k + i2];
x[i] = q/a[i][1];
printf("\nx[%d]=%6f",i,x[i]);
l = l + 1;
14
}
akhar:
getch();
//return ;
15