1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2000, 2010 Oracle and/or its affiliates.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * This file is part of OpenOffice.org.
11 * OpenOffice.org is free software: you can redistribute it and/or modify
12 * it under the terms of the GNU Lesser General Public License version 3
13 * only, as published by the Free Software Foundation.
15 * OpenOffice.org is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License version 3 for more details
19 * (a copy is included in the LICENSE file that accompanied this code).
21 * You should have received a copy of the GNU Lesser General Public License
22 * version 3 along with OpenOffice.org. If not, see
23 * <http://www.openoffice.org/license.html>
24 * for a copy of the LGPLv3 License.
26 ************************************************************************/
31 //---------------------------------------------------------------------------
32 double** mgcLinearSystemD::NewMatrix (int N
)
34 double** A
= new double*[N
];
38 for (int row
= 0; row
< N
; row
++)
40 A
[row
] = new double[N
];
43 for (int i
= 0; i
< row
; i
++)
47 for (int col
= 0; col
< N
; col
++)
52 //---------------------------------------------------------------------------
53 void mgcLinearSystemD::DeleteMatrix (int N
, double** A
)
55 for (int row
= 0; row
< N
; row
++)
59 //---------------------------------------------------------------------------
60 double* mgcLinearSystemD::NewVector (int N
)
62 double* B
= new double[N
];
66 for (int row
= 0; row
< N
; row
++)
70 //---------------------------------------------------------------------------
71 int mgcLinearSystemD::Solve (int n
, double** a
, double* b
)
73 int* indxc
= new int[n
];
76 int* indxr
= new int[n
];
81 int* ipiv
= new int[n
];
91 double big
, pivinv
, save
;
93 for (j
= 0; j
< n
; j
++)
96 for (i
= 0; i
< n
; i
++)
99 for (j
= 0; j
< n
; j
++)
103 for (k
= 0; k
< n
; k
++)
107 if ( fabs(a
[j
][k
]) >= big
)
114 else if ( ipiv
[k
] > 1 )
128 double* rowptr
= a
[irow
];
139 if ( a
[icol
][icol
] == 0 )
147 pivinv
= 1/a
[icol
][icol
];
149 for (k
= 0; k
< n
; k
++)
150 a
[icol
][k
] *= pivinv
;
153 for (j
= 0; j
< n
; j
++)
159 for (k
= 0; k
< n
; k
++)
160 a
[j
][k
] -= a
[icol
][k
]*save
;
161 b
[j
] -= b
[icol
]*save
;
166 for (j
= n
-1; j
>= 0; j
--)
168 if ( indxr
[j
] != indxc
[j
] )
170 for (k
= 0; k
< n
; k
++)
172 save
= a
[k
][indxr
[j
]];
173 a
[k
][indxr
[j
]] = a
[k
][indxc
[j
]];
174 a
[k
][indxc
[j
]] = save
;