1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
9 * This file incorporates work covered by the following license notice:
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
24 double** mgcLinearSystemD::NewMatrix (int N
)
26 double** A
= new double*[N
];
30 for (int row
= 0; row
< N
; row
++)
32 A
[row
] = new double[N
];
35 for (int i
= 0; i
< row
; i
++)
40 for (int col
= 0; col
< N
; col
++)
46 void mgcLinearSystemD::DeleteMatrix (int N
, double** A
)
48 for (int row
= 0; row
< N
; row
++)
53 double* mgcLinearSystemD::NewVector (int N
)
55 double* B
= new double[N
];
59 for (int row
= 0; row
< N
; row
++)
64 int mgcLinearSystemD::Solve (int n
, double** a
, double* b
)
66 int* indxc
= new int[n
];
69 int* indxr
= new int[n
];
74 int* ipiv
= new int[n
];
86 for (j
= 0; j
< n
; j
++)
89 for (i
= 0; i
< n
; i
++)
92 for (j
= 0; j
< n
; j
++)
96 for (k
= 0; k
< n
; k
++)
100 if ( fabs(a
[j
][k
]) >= big
)
107 else if ( ipiv
[k
] > 1 )
121 double* rowptr
= a
[irow
];
132 if ( a
[icol
][icol
] == 0 )
140 double pivinv
= 1/a
[icol
][icol
];
142 for (k
= 0; k
< n
; k
++)
143 a
[icol
][k
] *= pivinv
;
146 for (j
= 0; j
< n
; j
++)
152 for (k
= 0; k
< n
; k
++)
153 a
[j
][k
] -= a
[icol
][k
]*save
;
154 b
[j
] -= b
[icol
]*save
;
159 for (j
= n
-1; j
>= 0; j
--)
161 if ( indxr
[j
] != indxc
[j
] )
163 for (k
= 0; k
< n
; k
++)
165 save
= a
[k
][indxr
[j
]];
166 a
[k
][indxr
[j
]] = a
[k
][indxc
[j
]];
167 a
[k
][indxc
[j
]] = save
;
178 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */