Free cookie consent management tool by TermsFeed Policy Generator

source: branches/3.2/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.3.0/ALGLIB-2.3.0/cdet.cs @ 5955

Last change on this file since 5955 was 2806, checked in by gkronber, 15 years ago

Added plugin for new version of ALGLIB. #875 (Update ALGLIB sources)

File size: 3.0 KB
Line 
1/*************************************************************************
2Copyright (c) 2005-2007, Sergey Bochkanov (ALGLIB project).
3
4>>> SOURCE LICENSE >>>
5This program is free software; you can redistribute it and/or modify
6it under the terms of the GNU General Public License as published by
7the Free Software Foundation (www.fsf.org); either version 2 of the
8License, or (at your option) any later version.
9
10This program is distributed in the hope that it will be useful,
11but WITHOUT ANY WARRANTY; without even the implied warranty of
12MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13GNU General Public License for more details.
14
15A copy of the GNU General Public License is available at
16http://www.fsf.org/licensing/licenses
17
18>>> END OF LICENSE >>>
19*************************************************************************/
20
21using System;
22
23namespace alglib
24{
25    public class cdet
26    {
27        /*************************************************************************
28        Determinant calculation of the matrix given by its LU decomposition.
29
30        Input parameters:
31            A       -   LU decomposition of the matrix (output of
32                        RMatrixLU subroutine).
33            Pivots  -   table of permutations which were made during
34                        the LU decomposition.
35                        Output of RMatrixLU subroutine.
36            N       -   size of matrix A.
37
38        Result: matrix determinant.
39
40          -- ALGLIB --
41             Copyright 2005 by Bochkanov Sergey
42        *************************************************************************/
43        public static AP.Complex cmatrixludet(ref AP.Complex[,] a,
44            ref int[] pivots,
45            int n)
46        {
47            AP.Complex result = 0;
48            int i = 0;
49            int s = 0;
50
51            result = 1;
52            s = 1;
53            for(i=0; i<=n-1; i++)
54            {
55                result = result*a[i,i];
56                if( pivots[i]!=i )
57                {
58                    s = -s;
59                }
60            }
61            result = result*s;
62            return result;
63        }
64
65
66        /*************************************************************************
67        Calculation of the determinant of a general matrix
68
69        Input parameters:
70            A       -   matrix, array[0..N-1, 0..N-1]
71            N       -   size of matrix A.
72
73        Result: determinant of matrix A.
74
75          -- ALGLIB --
76             Copyright 2005 by Bochkanov Sergey
77        *************************************************************************/
78        public static AP.Complex cmatrixdet(AP.Complex[,] a,
79            int n)
80        {
81            AP.Complex result = 0;
82            int[] pivots = new int[0];
83
84            a = (AP.Complex[,])a.Clone();
85
86            trfac.cmatrixlu(ref a, n, n, ref pivots);
87            result = cmatrixludet(ref a, ref pivots, n);
88            return result;
89        }
90    }
91}
Note: See TracBrowser for help on using the repository browser.