Esempio n. 1
0
        internal ComplexVector(ComplexMatrix inner)
        {
            if (inner.Columns != 1)
            {
                throw new ArgumentException();
            }

            this.inner = inner;
        }
Esempio n. 2
0
        public ComplexVector(Complex[] entries)
        {
            int n = entries.Length;

            Complex[,] a = new Complex[n, 1];
            for (int i = 0; i < n; i++)
            {
                a[i, 0] = entries[i];
            }

            inner = new ComplexMatrix(a);
        }
Esempio n. 3
0
        public ComplexMatrix SetMatrix(int row, int column, ComplexMatrix a)
        {
            if (row < 0 || row + a.rows > rows || column < 0 || column + a.columns > columns)
            {
                throw new IndexOutOfRangeException();
            }

            ComplexMatrix b = new ComplexMatrix(rows, columns, entries);
            for (int i = 0; i < a.rows; i++)
            {
                for (int j = 0; j < a.columns; j++)
                {
                    b.SetEntryInternal(row + i, column + j, a.GetEntryInternal(i, j));
                }
            }

            return b;
        }
Esempio n. 4
0
        public ComplexMatrix SetEntry(int row, int column, Complex t)
        {
            if (row < 0 || row >= rows || column < 0 || column >= columns)
            {
                throw new IndexOutOfRangeException();
            }

            ComplexMatrix a = new ComplexMatrix(rows, columns, entries);
            a.SetEntryInternal(row, column, t);
            return a;
        }
Esempio n. 5
0
        public ComplexMatrix GetMatrix(int row, int column, int rows, int columns)
        {
            if (row < 0 || row + rows > this.rows || column < 0 || column + columns > this.columns)
            {
                throw new IndexOutOfRangeException();
            }

            int n = rows;
            int m = columns;

            ComplexMatrix a = new ComplexMatrix(n, m);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    a.SetEntryInternal(i, j, GetEntryInternal(row + i, column + j));
                }
            }

            return a;
        }
Esempio n. 6
0
        public static ComplexMatrix Transpose(ComplexMatrix a)
        {
            int n = a.columns;
            int m = a.rows;

            ComplexMatrix b = new ComplexMatrix(n, m);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    b.SetEntryInternal(i, j, a.GetEntryInternal(j, i));
                }
            }

            return b;
        }
Esempio n. 7
0
        public static Complex Trace(ComplexMatrix a)
        {
            int n = Math.Min(a.rows, a.columns);

            Complex s = 0.0;
            for (int i = 0; i < n; i++)
            {
                s += a[i, i];
            }

            return s;
        }
Esempio n. 8
0
        public static ComplexMatrix Identity(int rows, int columns)
        {
            int n = Math.Min(rows, columns);

            ComplexMatrix a = new ComplexMatrix(rows, columns);
            for (int i = 0; i < n; i++)
            {
                a.SetEntryInternal(i, i, 1.0);
            }

            return a;
        }
Esempio n. 9
0
        public static ComplexMatrix Diagonal(Complex[] values)
        {
            int n = values.Length;

            ComplexMatrix a = new ComplexMatrix(n, n);
            for (int i = 0; i < n; i++)
            {
                a.SetEntryInternal(i, i, values[i]);
            }

            return a;
        }
Esempio n. 10
0
        public static ComplexMatrix Basis(int rows, int columns, int row, int column)
        {
            if (row < 0 || row >= rows || column < 0 || column >= columns)
            {
                throw new IndexOutOfRangeException();
            }

            ComplexMatrix a = new ComplexMatrix(rows, columns);
            a.SetEntryInternal(row, column, 1.0);
            return a;
        }
Esempio n. 11
0
        public static ComplexMatrix operator -(Complex t, ComplexMatrix a)
        {
            int n = a.rows;
            int m = a.columns;

            ComplexMatrix b = new ComplexMatrix(n, m);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    b.SetEntryInternal(i, j, t - a.GetEntryInternal(i, j));
                }
            }

            return b;
        }
Esempio n. 12
0
        public static ComplexMatrix operator -(ComplexMatrix a, ComplexMatrix b)
        {
            int n = a.rows;
            int m = a.columns;

            if (b.rows != n || b.columns != m)
            {
                throw new ArgumentException("The matrix dimensions don't match.");
            }

            ComplexMatrix c = new ComplexMatrix(n, m);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    c.SetEntryInternal(i, j, a.GetEntryInternal(i, j) - b.GetEntryInternal(i, j));
                }
            }

            return c;
        }
Esempio n. 13
0
        public static ComplexMatrix operator +(ComplexMatrix a, Complex t)
        {
            int n = a.Rows;
            int m = a.Columns;

            ComplexMatrix c = new ComplexMatrix(n, m);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    c.SetEntryInternal(i, j, a.GetEntryInternal(i, j) + t);
                }
            }

            return c;
        }
Esempio n. 14
0
        public static ComplexMatrix operator *(ComplexMatrix a, ComplexMatrix b)
        {
            int n = a.rows;
            int m = b.columns;
            int l = a.columns;

            if (b.rows != l)
            {
                throw new ArgumentException("The matrix dimensions don't match.");
            }

            ComplexMatrix c = new ComplexMatrix(n, m);
            for (int i = 0; i < n; i++)
            {
                for (int j = 0; j < m; j++)
                {
                    Complex s = 0.0;
                    for (int k = 0; k < l; k++)
                    {
                        s += a.GetEntryInternal(i, k) * b.GetEntryInternal(k, j);
                    }

                    c.SetEntryInternal(i, j, s);
                }
            }

            return c;
        }