1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*************************************************************************
4 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
6 * Copyright 2000, 2010 Oracle and/or its affiliates.
8 * OpenOffice.org - a multi-platform office productivity suite
10 * This file is part of OpenOffice.org.
12 * OpenOffice.org is free software: you can redistribute it and/or modify
13 * it under the terms of the GNU Lesser General Public License version 3
14 * only, as published by the Free Software Foundation.
16 * OpenOffice.org is distributed in the hope that it will be useful,
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 * GNU Lesser General Public License version 3 for more details
20 * (a copy is included in the LICENSE file that accompanied this code).
22 * You should have received a copy of the GNU Lesser General Public License
23 * version 3 along with OpenOffice.org. If not, see
24 * <http://www.openoffice.org/license.html>
25 * for a copy of the LGPLv3 License.
27 ************************************************************************/
32 //---------------------------------------------------------------------------
33 double** mgcLinearSystemD::NewMatrix (int N
)
35 double** A
= new double*[N
];
39 for (int row
= 0; row
< N
; row
++)
41 A
[row
] = new double[N
];
44 for (int i
= 0; i
< row
; i
++)
49 for (int col
= 0; col
< N
; col
++)
54 //---------------------------------------------------------------------------
55 void mgcLinearSystemD::DeleteMatrix (int N
, double** A
)
57 for (int row
= 0; row
< N
; row
++)
61 //---------------------------------------------------------------------------
62 double* mgcLinearSystemD::NewVector (int N
)
64 double* B
= new double[N
];
68 for (int row
= 0; row
< N
; row
++)
72 //---------------------------------------------------------------------------
73 int mgcLinearSystemD::Solve (int n
, double** a
, double* b
)
75 int* indxc
= new int[n
];
78 int* indxr
= new int[n
];
83 int* ipiv
= new int[n
];
93 double big
, pivinv
, save
;
95 for (j
= 0; j
< n
; j
++)
98 for (i
= 0; i
< n
; i
++)
101 for (j
= 0; j
< n
; j
++)
105 for (k
= 0; k
< n
; k
++)
109 if ( fabs(a
[j
][k
]) >= big
)
116 else if ( ipiv
[k
] > 1 )
130 double* rowptr
= a
[irow
];
141 if ( a
[icol
][icol
] == 0 )
149 pivinv
= 1/a
[icol
][icol
];
151 for (k
= 0; k
< n
; k
++)
152 a
[icol
][k
] *= pivinv
;
155 for (j
= 0; j
< n
; j
++)
161 for (k
= 0; k
< n
; k
++)
162 a
[j
][k
] -= a
[icol
][k
]*save
;
163 b
[j
] -= b
[icol
]*save
;
168 for (j
= n
-1; j
>= 0; j
--)
170 if ( indxr
[j
] != indxc
[j
] )
172 for (k
= 0; k
< n
; k
++)
174 save
= a
[k
][indxr
[j
]];
175 a
[k
][indxr
[j
]] = a
[k
][indxc
[j
]];
176 a
[k
][indxc
[j
]] = save
;
187 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */