Free cookie consent management tool by TermsFeed Policy Generator

source: trunk/sources/HeuristicLab.ExtLibs/HeuristicLab.ALGLIB/2.1.2.2591/ALGLIB-2.1.2.2591/cdet.cs @ 3031

Last change on this file since 3031 was 2645, checked in by mkommend, 15 years ago

extracted external libraries and adapted dependent plugins (ticket #837)

File size: 3.9 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            clu.cmatrixlu(ref a, n, n, ref pivots);
87            result = cmatrixludet(ref a, ref pivots, n);
88            return result;
89        }
90
91
92        public static AP.Complex complexdeterminantlu(ref AP.Complex[,] a,
93            ref int[] pivots,
94            int n)
95        {
96            AP.Complex result = 0;
97            int i = 0;
98            int s = 0;
99
100            result = 1;
101            s = 1;
102            for(i=1; i<=n; i++)
103            {
104                result = result*a[i,i];
105                if( pivots[i]!=i )
106                {
107                    s = -s;
108                }
109            }
110            result = result*s;
111            return result;
112        }
113
114
115        public static AP.Complex complexdeterminant(AP.Complex[,] a,
116            int n)
117        {
118            AP.Complex result = 0;
119            int[] pivots = new int[0];
120
121            a = (AP.Complex[,])a.Clone();
122
123            clu.complexludecomposition(ref a, n, n, ref pivots);
124            result = complexdeterminantlu(ref a, ref pivots, n);
125            return result;
126        }
127    }
128}
Note: See TracBrowser for help on using the repository browser.