Hi Fred,
your system is small (5x5) so don't consider it sparse.
Consider it as full with some zeros in it.
SLV-type
Getting away from matrices, I assume you have a linear system of 5 equations in
5 unknowns (x1,x2,x3,x4,x5) = x that you want to find.
You will also have 5 right hand sides (b1,b2,b3,b4,b5) = b.
In matrix terms: solve Ax = b where A is a 5x5 matrix
Suppose you had
- Code: Select all
x1 + 2*x3 + 3*x5 = 8
x2 - 5*x4 = 9
7*x2 + 4*x5 = 5
6*x1 + 2*x4 = 2
x3 + x4 + x5 = 3
then you could have a data file like
1.0 0.0 2.0 0.0 3.0
0.0 1.0 0.0 -5.0 0.0
0.0 7.0 0.0 0.0 4.0
6.0 0.0 0.0 2.0 0.0
0.0 0.0 1.0 1.0 1.0 : matrix a
8.0 9.0 5.0 2.0 3.0 : rhs b
Try something simple first
- Code: Select all
double precision a(5,5), b(5)
integer ipiv(5), info
read(5,*) (a(i,1:5),i=1,5)
read(5,*) b(1:5)
call dgesv(5,1,a,5,ipiv,b,5,info)
if (info==0) print*,'solution :', b(1:5)
Scaling: if your system contains very big numbers and/or very small numbers then
scaling would be a good idea (see dgesvx) . But, go for smple first.