Esempio n. 1
0
        protected override Matrix <Complex> Multiply(Matrix <Complex> B)
        {
            MatrixComplex result = new MatrixComplex(this.Col, B.Row);

            if (this.Row == B.Col)
            {
                for (int i = 0; i < this.Col; i++)
                {
                    for (int j = 0; j < B.Row; j++)
                    {
                        Complex sum = 0.0;
                        for (int k = 0; k < this.Row; k++)
                        {
                            sum += this.Arr[i, k] * B.Arr[k, j];
                        }
                        result.Arr[i, j] = sum;
                    }
                }
                return(result);
            }
            else
            {
                throw new Exception("These matrices cannot be multiplied");
            }
        }
Esempio n. 2
0
        public override Matrix <Complex> Inverse()
        {
            Matrix <Complex> X = new MatrixComplex(Col, Row);
            var matBuild       = MathNet.Numerics.LinearAlgebra.Matrix <Complex> .Build;
            var matrix         = matBuild.DenseOfArray(Arr).Inverse();

            X.Arr = matrix.ToArray();
            return(X);
        }
Esempio n. 3
0
        public override Matrix <Complex> Unity()
        {
            var unity = new MatrixComplex(this.Col, this.Row);

            for (int i = 0; i < Col; i++)
            {
                unity.Arr[i, i] = new Complex(1.0, 0.0);
            }
            return(unity);
        }
Esempio n. 4
0
        public Matrix <Complex> InverseOld()
        {
            Matrix <Complex> X = new MatrixComplex(Col, Row);
            Matrix <Complex> E = new MatrixComplex(Col, Row);

            E = E.Unity();
            Complex kf   = new Complex();
            int     RANG = Row;
            var     Temp = new MatrixComplex(Col, Row);

            Temp.Arr = Arr;

            for (int p = 0; p < RANG; p++)
            {
                for (int i = p + 1; i < RANG; i++)
                {
                    if (Temp.Arr[p, p] == 0.0)
                    {
                        kf = 0;
                    }
                    else
                    {
                        kf = -Temp.Arr[i, p] / Temp.Arr[p, p];
                    }

                    for (int j = 0; j < RANG; j++)
                    {
                        E.Arr[i, j] = E.Arr[i, j] + kf * E.Arr[p, j];
                        if (j >= p)
                        {
                            Temp.Arr[i, j] = Temp.Arr[i, j] + kf * Temp.Arr[p, j];
                        }
                    }
                }
            }

            for (int k = 0; k < RANG; k++)
            {
                X.Arr[RANG - 1, k] = E.Arr[RANG - 1, k] / Temp.Arr[RANG - 1, RANG - 1];

                for (int i = RANG - 2; i >= 0; i--)
                {
                    Complex sum = 0.0;
                    for (int j = i + 1; j < RANG; j++)
                    {
                        sum = sum + X.Arr[j, k] * Temp.Arr[i, j];
                    }

                    X.Arr[i, k] = (E.Arr[i, k] - sum) / Temp.Arr[i, i];
                }
            }
            return(X);
        }
Esempio n. 5
0
        protected override Matrix <Complex> Devide(Complex k)
        {
            MatrixComplex result = new MatrixComplex(Col, Row);

            for (int i = 0; i < Col; i++)
            {
                for (int j = 0; j < Row; j++)
                {
                    result.Arr[i, j] = Arr[i, j] / k;
                }
            }
            return(result);
        }
Esempio n. 6
0
        public override Matrix <Complex> Clone()
        {
            Matrix <Complex> result = new MatrixComplex(Col, Row);

            for (int i = 0; i < Col; i++)
            {
                for (int j = 0; j < Row; j++)
                {
                    result.Arr[i, j] = Arr[i, j];
                }
            }
            return(result);
        }
Esempio n. 7
0
        protected override Matrix <Complex> Add(Matrix <Complex> A)
        {
            MatrixComplex result = new MatrixComplex(A.Col, A.Row);

            if (A.Col != this.Col || A.Row != this.Row)
            {
                throw new Exception("These matrices is not equal");
            }
            else
            {
                for (int i = 0; i < A.Col; i++)
                {
                    for (int j = 0; j < A.Row; j++)
                    {
                        result.Arr[i, j] = this.Arr[i, j] + A.Arr[i, j];
                    }
                }
                return(result);
            }
        }
Esempio n. 8
0
        protected override Matrix <Complex> Substract(Matrix <Complex> B)
        {
            MatrixComplex result = new MatrixComplex(B.Col, B.Row);

            if (B.Col != this.Col || B.Row != this.Row)
            {
                throw new Exception("These matrices is not equal");
            }
            else
            {
                for (int i = 0; i < B.Col; i++)
                {
                    for (int j = 0; j < B.Row; j++)
                    {
                        result.Arr[i, j] = this.Arr[i, j] - B.Arr[i, j];
                    }
                }
                return(result);
            }
        }
Esempio n. 9
0
        public Matrix <double> Calculate(Matrix <double> a, Matrix <double> n)
        {
            Matrix <Complex> U = new MatrixComplex(a.Col, a.Row);
            Matrix <Complex> N = new MatrixComplex(n.Col, n.Row);
            //Matrix<Complex> N = n * Globals.Alpha[0].Real;
            var aa = a.Cast <Complex>();
            var nn = n.Cast <Complex>();

            U = U.Unity();
            var dx = 100.0 / 7.0;

            for (int i = 1; i <= 7; i++)
            {
                var temp  = aa - (U * Globals.Theta[i]);
                var temp1 = temp.Inverse();
                var _n    = temp1 * nn * Globals.Alpha[i];
                var str   = "";
                N = N + _n;
                ExpStatusChangedEvent?.Invoke((int)(i * dx));
                //if (i == 1)
                //{
                //    for (int k = 0; k < temp1.Col; k++)
                //    {
                //        for (int j = 0; j < temp1.Row; j++)
                //        {
                //            str += temp1.Arr[k, j].Real + "  " + temp1.Arr[k, j].Imaginary + "\t";
                //        }
                //        str += "\n";
                //    }
                //    str += "\n";
                //    File.AppendAllText("F://testmatrix.txt", str);
                //}
            }
            Matrix <double> result = N.Cast <double>();

            result *= 2;
            result += n * Globals.Alpha[0].Real;
            result.RemoveMinuses();
            return(result);
        }
Esempio n. 10
0
        public override Matrix <Complex> Pow(int p)
        {
            Matrix <Complex> result = new MatrixComplex(Col, Row);

            result = result.Unity();

            if (p == 0)
            {
            }
            else if (p == 1)
            {
                result = Clone();
            }
            else
            {
                result = Clone();
                for (int i = 1; i < p; i++)
                {
                    result = result * this;
                }
            }
            return(result);
        }