GetNumColumns() public method

public GetNumColumns ( ) : int
return int
Beispiel #1
0
        public bool CalculateAssessment()
        {
            dgAssessment.Refresh();
            try
            {
                int Rows, Columns;//��¼����Ԫ�ص�����������
                Rows = dgAssessment.Rows.Count - 1;
                Columns = dgAssessment.Columns.Count - 1;

                lbState.Visible = true;
                pgBar.Visible = true;

                double[,] X = new double[Rows, Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        if (isNumberic(dgAssessment.Rows[i + 1].Cells[j + 1].Value.ToString(), out X[i, j]))
                           ;
                        else
                            return false;
                    }
                }
                //��һ��
                double[,] S = new double[Rows, Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        //object a=dgChooseSmallIndex.Rows[j].Cells[0].Value;
                        if (dgChooseSmallIndex.Rows[j].Cells[0].Value.ToString().Equals("True"))
                        {
                            S[i, j] = 1 / X[i, j];
                        }
                        else
                            S[i, j] = X[i, j];
                    }
                }
                lbState.Text = "���ڶ�ԭʼ���ݽ��й淶��";
                pgBar.Value = 10;
                //�ڶ���
                double[,] R = new double[Rows, Columns];
                double[] M = new double[Columns];
                double[] m = new double[Columns];
                for (int j = 0; j < Columns; j++)
                {
                    M[j] = S[0, j];
                    m[j] = S[0, j];
                    for (int i = 0; i < Rows; i++)
                    {
                        //object a=dgChooseSmallIndex.Rows[j].Cells[0].Value;
                        if (S[i, j] > M[j])
                        {
                            M[j] = S[i, j];
                        }
                        if (S[i, j] < m[j])
                        {
                            m[j] = S[i, j];
                        }
                    }
                }

                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        //object a=dgChooseSmallIndex.Rows[j].Cells[0].Value;
                        R[i, j] = S[i, j] / m[j];
                    }
                }
                lbState.Text = "���ڼ����ۺ�����ֵ��ȡֵ��Χ";
                pgBar.Value = 25;
                //������
                double ��1 = dbInputFactor��1.Value;
                double[,] T = new double[Rows, Columns];
                double[] wu = new double[Columns];
                T = (double [,])R.Clone();
                for (int j = 0; j < Rows; j++)
                {
                    for (int i = 0; i < Columns; i++)
                    {
                        for (int k = i + 1; k < Columns; k++)
                        {
                            if (T[j, i] < T[j, k])
                            {
                                double temp = T[j, k];
                                T[j, k] = T[j, i];
                                T[j, i] = temp;
                            }
                        }
                    }
                }
                if (radioButton1.Checked)
                { //���ڡ�ǿȨ���Ƕ�������������
                    double temp = 0;
                    for (int i = 0; i < Columns - 2; i++)
                    {
                        wu[i] = Math.Pow(0.5, i + 1);
                        temp += wu[i];
                    }
                    wu[Columns - 2] = wu[Columns - 1] = 0.5 - 0.5 * temp;
                }
                else
                {//���ڡ���Ȩ���Ƕ�������������
                    wu[0] = 0.5;
                    wu[1] = 0.5 - (Columns - 2) * Math.Pow(0.5, Columns - 1);
                    for (int i = 2; i < Columns; i++)
                    {
                        wu[i] = Math.Pow(0.5, Columns - 1);
                    }
                }
                double[,] y = new double[Rows, 2];
                for (int i = 0; i < Rows; i++)
                {
                    double temp0 = 0, temp1 = 0, temp2 = 0, temp3 = 0, temp4 = 1, temp5= 1;
                    for (int j = 0; j < Columns; j++)
                    {
                        temp2 += wu[j] * T[i, Columns - j - 1];
                        temp3 += wu[j] * T[i, j];
                        //temp4 *= Math.Pow();
                        temp4 *= Math.Pow(T[i, Columns - j - 1], 1 / Columns);
                        temp5 *= Math.Pow(T[i, j], 1 / Columns);

                    }
                    temp0 = (��1 * temp2 + (1-��1) * temp4);
                    temp1 = (��1 * temp3 + (1-��1) * temp5);

                    y[i, 0] = temp0;
                    y[i, 1] = temp1;
                }
                lbState.Text = "���ڼ�������̷����ľ�����Ұ";
                pgBar.Value = 45;
                //���IJ�
                double[,] C_L = new double[Rows, Rows];
                double[,] C_U = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = i; j < Rows; j++)
                    {
                        intersection(y[i, 0], y[i, 1], y[j, 0], y[j, 1], out C_L[i, j], out C_U[i, j]);
                    }
                }

                double[,] d = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = i; j < Rows; j++)
                    {
                        if (i == j)
                        {
                            d[i, j] = 0;//���ﲻ֪��������ʲô��˼�����Ұ���0������
                        }
                        else
                        {
                            d[i, j] = d[j, i] = (C_U[i, j] - C_L[i, j]) / (Math.Max(y[i, 1], y[j, 1]) - Math.Min(y[i, 0], y[j, 0]));
                        }
                    }
                }
                lbState.Text = "���ڼ�������̷����ľ���ǿ��";
                pgBar.Value = 70;
                //���岽
                double[,] u = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Rows; j++)
                    {
                        if (i == j)
                        {
                            u[i, j] = 0;
                        }
                        else
                        {
                            double temp = 0;
                            for (int k = 0; k < Rows; k++)
                            {
                                temp += d[i, k];
                            }
                            u[i, j] = d[i, j] / temp;
                        }
                    }
                }
                lbState.Text = "���ڼ��㾺������עϵ������";
                pgBar.Value = 80;
                //������
                double �� = dbInputFactor��.Value;
                double[,] w = new double[Rows, Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {
                        double temp = 0;
                        for (int k = 0; k < Rows; k++)
                        {
                            if (k != i)
                            {
                                temp += R[k, j] * u[i, k];
                            }

                        }
                        w[i, j] = �� * R[i, j] - (1 - ��) * temp;
                    }
                }
                //���߲�
                lbState.Text = "���ڹ���滮���Ⲣ���";
                pgBar.Value = 90;
                double[,] wx = new double[Rows, Columns];//wx��ʾw*:xΪ�ǵ���˼
                //���ڡ�ǿȨ���Ƕ������������͡�ǿȨ���Ƕ�����������������һ���ģ�
                //��Ϊ��wx����wu��õģ���wu�Ѿ�ͨ������������á�
                ToBeOrdered[] orderNumber = new ToBeOrdered[Columns];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Columns; j++)
                    {//�ȸ�ֵ
                        orderNumber[j].Index = j;
                        orderNumber[j].Value = w[i, j];
                    }
                    for (int j = 0; j < Columns; j++)
                    {//������
                        for (int k = j + 1; k < Columns; k++)
                        {
                            if (orderNumber[j].Value < orderNumber[k].Value)
                            {
                                ToBeOrdered temp = orderNumber[k];
                                orderNumber[k] = orderNumber[j];
                                orderNumber[j] = temp;
                            }
                        }

                    }
                    for (int j = 0; j < Columns; j++)
                    {//������
                        wx[i, orderNumber[j].Index] = wu[j];
                    }
                }
                //�ڰ˲�
                double[,] Y = new double[Rows, Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Rows; j++)
                    {
                        double  temp = 0, temp6 = 0, temp7 = 1;
                        for (int k = 0; k < Columns; k++)
                        {
                            //temp += wx[j, k] * R[i, k];

                            temp6 += wx[j, k] * R[i, k];
                            temp7 *= Math.Pow(R[i, k], 1 / Columns);

                        }
                        //Y[i, j] = temp;
                        temp = (��1 * temp6 + (1-��1) * temp7);
                        Y[i, j] = temp;

                    }
                }
                //�ھŲ�
                //������������������
                double[,] Y1 = new double[Rows, Rows];//���
                double[,] Y2 = new double[Rows, Rows];//�Ҳ�
                double[,] Y3 = new double[Rows, Rows];//���
                Y1 =(double [,]) Y.Clone();
                for (int i = 0; i < Rows; i++)
                {//����ת�þ���
                    for (int j = 0; j < Rows; j++)
                    {
                        Y2[i, j] = Y1[j, i];
                    }
                }
                for (int i = 0; i < Rows; i++)
                {//����Գƾ���
                    for (int j = 0; j < Rows; j++)
                    {
                        double temp = 0;
                        for (int k = 0; k < Rows; k++)
                        {
                            temp += Y1[i, k] * Y2[k, j];
                        }
                        Y3[i, j] = temp;
                    }
                }
                double[] Y4 = new double[Rows*Rows];//���ڼ������
                for (int i = 0; i < Rows; i++)
                {//���Գƾ���ת��Ϊһά����
                    for (int j = 0; j < Rows; j++)
                    {
                        Y4[i*Rows+j] = Y3[i, j];
                    }
                }
                //////////////////////////////////////////
                            // ʵ�Գ����Խ����ȫ������ֵ�����������ļ���
                Matrix mtx16 = new Matrix(Rows, Rows, Y4);

                Matrix mtxQ2 = new Matrix();//���غ�˹�ɶ��±任�ij˻�����Q
                Matrix mtxT2 = new Matrix();//������õĶԳ����Խ���
                double[] bArray2 = new double[mtx16.GetNumColumns()];//���ضԳ����Խ�������Խ���Ԫ��
                double[] cArray2 = new double[mtx16.GetNumColumns()];//ǰn-1��Ԫ�ط��ضԳ����Խ���ĴζԽ���Ԫ��
                double[] resultArray = new double[mtx16.GetNumColumns()];//��Ŧ˵Ľ��ֵ
                // 1: Լ���Գƾ���Ϊ�Գ����Խ���: ��˹�ɶ��±任��
                if (mtx16.MakeSymTri(mtxQ2, mtxT2, bArray2, cArray2))
                {
                    // 2: ����ȫ������ֵ����������
                    //bArray2:����Գ����Խ�������Խ���Ԫ��,����ʱ���ȫ������ֵ��
                    //cArray2:ǰn-1��Ԫ�ش���Գ����Խ���ĴζԽ���Ԫ��
                    //mtxQ2:���ؾ���A������ֵ�����������е�i��Ϊ������dblB�е�i������ֵ��Ӧ������������
                    //60:��������
                    //0.0001:���㾫��
                    if (mtx16.ComputeEvSymTri(bArray2, cArray2, mtxQ2, 60, 0.0001))
                    {
                        int tempi = 0;
                        double tempNum = bArray2[0];
                        for (int i = 0; i < mtxQ2.GetNumColumns(); ++i)
                        {//��������ֵ�������Ǹ�
                            if (tempNum < bArray2[i])
                            {
                                tempi = i;
                                tempNum = bArray2[i];
                            }
                        }
                        for (int i = 0; i < mtxQ2.GetNumRows(); ++i)
                        {
                            if(mtxQ2.GetElement(i,tempi)<0)
                            {//ȡ��ֵ
                                resultArray[i]=-mtxQ2.GetElement(i,tempi);
                            }
                            else
                            {
                                resultArray[i]=mtxQ2.GetElement(i,tempi);
                            }
                        }
                    }
                    else
                    {
                        return false;
                    }
                }
                else
                {
                    return false;
                }

                //////////////////////////////////////////

                //��ʮ��
                double[,] x = new double[Rows, Rows];

                ToBeOrdered[] orderNumber2 = new ToBeOrdered[Rows];
                for (int i = 0; i < Rows; i++)
                {
                    for (int j = 0; j < Rows; j++)
                    {//�ȸ�ֵ
                        orderNumber2[j].Index = j;
                        orderNumber2[j].Value = Y[j, i];//ע���Ƕ��н��в���
                    }
                    for (int j = 0; j < Rows; j++)
                    {//������
                        for (int k = j + 1; k < Rows; k++)
                        {
                            if (orderNumber2[j].Value < orderNumber2[k].Value)
                            {
                                ToBeOrdered temp = orderNumber2[k];
                                orderNumber2[k] = orderNumber2[j];
                                orderNumber2[j] = temp;
                            }
                        }
                    }
                    for (int j = 0; j < Rows; j++)
                    {//������
                        x[orderNumber2[j].Index, i] = j + 1;//ע��ֵԽ�����ԽС
                    }
                }
                //
                //��ʮһ��
                int[] orderResult = new int[Rows];//��Ŧ˵�����ֵ
                ToBeOrdered[] orderNumber3 = new ToBeOrdered[Rows];

                for (int j = 0; j < Rows; j++)
                {//�ȸ�ֵ
                    orderNumber3[j].Index = j;
                    orderNumber3[j].Value = resultArray[j];
                }
                for (int j = 0; j < Rows; j++)
                {//������
                    for (int k = j + 1; k < Rows; k++)
                    {
                        if (orderNumber3[j].Value < orderNumber3[k].Value)
                        {
                            ToBeOrdered temp = orderNumber3[k];
                            orderNumber3[k] = orderNumber3[j];
                            orderNumber3[j] = temp;
                        }
                    }
                }
                for (int j = 0; j < Rows; j++)
                {//������
                    orderResult[orderNumber3[j].Index] = j + 1;//ע��ֵԽ�����ԽС
                }

                //
                lbState.Text = "������ɣ�";
                pgBar.Value = 100;
                lbState.Visible = false;
                pgBar.Visible = false;

                FrmAssessResultshow result = new FrmAssessResultshow(x,orderResult);
                result.ShowDialog();
            }
            catch
            {
                return false;
            }

                return true;
        }
Beispiel #2
0
        /**
         * ���Գ������������ƽ������
         *
         * @param mtxResult - CMatrix���ö��󣬷��ط���������
         * @return bool �ͣ�����������Ƿ�ɹ�
         */
        public bool GetRootsetCholesky(Matrix mtxResult)
        {
            int i,j,k,u,v;

            // ���������ԣ����������󸳸������
            Matrix mtxCoef = new Matrix(mtxLECoef);
            mtxResult.SetValue(mtxLEConst);
            int n = mtxCoef.GetNumColumns();
            int m = mtxResult.GetNumColumns();
            double[] pDataCoef = mtxCoef.GetData();
            double[] pDataConst = mtxResult.GetData();

            // �ǶԳ�����ϵ�����󣬲����ñ��������
            if (pDataCoef[0] <= 0.0)
                return false;

            pDataCoef[0]=Math.Sqrt(pDataCoef[0]);
            for (j=1; j<=n-1; j++)
                pDataCoef[j]=pDataCoef[j]/pDataCoef[0];

            for (i=1; i<=n-1; i++)
            {
                u=i*n+i;
                for (j=1; j<=i; j++)
                {
                    v=(j-1)*n+i;
                    pDataCoef[u]=pDataCoef[u]-pDataCoef[v]*pDataCoef[v];
                }

                if (pDataCoef[u] <= 0.0)
                    return false;

                pDataCoef[u]=Math.Sqrt(pDataCoef[u]);
                if (i!=(n-1))
                {
                    for (j=i+1; j<=n-1; j++)
                    {
                        v=i*n+j;
                        for (k=1; k<=i; k++)
                            pDataCoef[v]=pDataCoef[v]-pDataCoef[(k-1)*n+i]*pDataCoef[(k-1)*n+j];
                        pDataCoef[v]=pDataCoef[v]/pDataCoef[u];
                    }
                }
            }

            for (j=0; j<=m-1; j++)
            {
                pDataConst[j]=pDataConst[j]/pDataCoef[0];
                for (i=1; i<=n-1; i++)
                {
                    u=i*n+i;
                    v=i*m+j;
                    for (k=1; k<=i; k++)
                        pDataConst[v]=pDataConst[v]-pDataCoef[(k-1)*n+i]*pDataConst[(k-1)*m+j];
                    pDataConst[v]=pDataConst[v]/pDataCoef[u];
                }
            }

            for (j=0; j<=m-1; j++)
            {
                u=(n-1)*m+j;
                pDataConst[u]=pDataConst[u]/pDataCoef[n*n-1];
                for (k=n-1; k>=1; k--)
                {
                    u=(k-1)*m+j;
                    for (i=k; i<=n-1; i++)
                    {
                        v=(k-1)*n+i;
                        pDataConst[u]=pDataConst[u]-pDataCoef[v]*pDataConst[i*m+j];
                    }

                    v=(k-1)*n+k-1;
                    pDataConst[u]=pDataConst[u]/pDataCoef[v];
                }
            }

            return true;
        }
Beispiel #3
0
        /**
         * ���ԳƷ�����ķֽⷨ
         *
         * @param mtxResult - CMatrix���ö��󣬷��ط���������
         * @return bool �ͣ�����������Ƿ�ɹ�
         */
        public bool GetRootsetDjn(Matrix mtxResult)
        {
            int i,j,l,k,u,v,w,k1,k2,k3;
            double p;

            // ���������ԣ����������󸳸������
            Matrix mtxCoef = new Matrix(mtxLECoef);
            mtxResult.SetValue(mtxLEConst);
            int n = mtxCoef.GetNumColumns();
            int m = mtxResult.GetNumColumns();
            double[] pDataCoef = mtxCoef.GetData();
            double[] pDataConst = mtxResult.GetData();

            // �ǶԳ�ϵ�����󣬲����ñ��������
            if (pDataCoef[0] == 0.0)
                return false;

            for (i=1; i<=n-1; i++)
            {
                u=i*n;
                pDataCoef[u]=pDataCoef[u]/pDataCoef[0];
            }

            for (i=1; i<=n-2; i++)
            {
                u=i*n+i;
                for (j=1; j<=i; j++)
                {
                    v=i*n+j-1;
                    l=(j-1)*n+j-1;
                    pDataCoef[u]=pDataCoef[u]-pDataCoef[v]*pDataCoef[v]*pDataCoef[l];
                }

                p=pDataCoef[u];
                if (p == 0.0)
                    return false;

                for (k=i+1; k<=n-1; k++)
                {
                    u=k*n+i;
                    for (j=1; j<=i; j++)
                    {
                        v=k*n+j-1;
                        l=i*n+j-1;
                        w=(j-1)*n+j-1;
                        pDataCoef[u]=pDataCoef[u]-pDataCoef[v]*pDataCoef[l]*pDataCoef[w];
                    }

                    pDataCoef[u]=pDataCoef[u]/p;
                }
            }

            u=n*n-1;
            for (j=1; j<=n-1; j++)
            {
                v=(n-1)*n+j-1;
                w=(j-1)*n+j-1;
                pDataCoef[u]=pDataCoef[u]-pDataCoef[v]*pDataCoef[v]*pDataCoef[w];
            }

            p=pDataCoef[u];
            if (p == 0.0)
                return false;

            for (j=0; j<=m-1; j++)
            {
                for (i=1; i<=n-1; i++)
                {
                    u=i*m+j;
                    for (k=1; k<=i; k++)
                    {
                        v=i*n+k-1;
                        w=(k-1)*m+j;
                        pDataConst[u]=pDataConst[u]-pDataCoef[v]*pDataConst[w];
                    }
                }
            }

            for (i=1; i<=n-1; i++)
            {
                u=(i-1)*n+i-1;
                for (j=i; j<=n-1; j++)
                {
                    v=(i-1)*n+j;
                    w=j*n+i-1;
                    pDataCoef[v]=pDataCoef[u]*pDataCoef[w];
                }
            }

            for (j=0; j<=m-1; j++)
            {
                u=(n-1)*m+j;
                pDataConst[u]=pDataConst[u]/p;
                for (k=1; k<=n-1; k++)
                {
                    k1=n-k;
                    k3=k1-1;
                    u=k3*m+j;
                    for (k2=k1; k2<=n-1; k2++)
                    {
                        v=k3*n+k2;
                        w=k2*m+j;
                        pDataConst[u]=pDataConst[u]-pDataCoef[v]*pDataConst[w];
                    }

                    pDataConst[u]=pDataConst[u]/pDataCoef[k3*n+k3];
                }
            }

            return true;
        }
Beispiel #4
0
        /**
         * ʵ�Գ����Խ����ȫ������ֵ�����������ļ���
         *
         * @param dblB - һά���飬����Ϊ����Ľ���������Գ����Խ�������Խ���Ԫ�أ�
         *			     ����ʱ���ȫ������ֵ��
         * @param dblC - һά���飬����Ϊ����Ľ�����ǰn-1��Ԫ�ش���Գ����Խ����
         *               �ζԽ���Ԫ��
         * @param mtxQ - ������뵥λ�����򷵻�ʵ�Գ����Խ��������ֵ��������
         *			     �������MakeSymTri������õľ���A�ĺ�˹�ɶ��±任�ij˻�
         *               ����Q���򷵻ؾ���A������ֵ�����������е�i��Ϊ������dblB
         *               �е�j������ֵ��Ӧ������������
         * @param nMaxIt - ��������
         * @param eps - ���㾫��
         * @return bool�ͣ�����Ƿ�ɹ�
         */
        public bool ComputeEvSymTri(double[] dblB, double[] dblC, Matrix mtxQ, int nMaxIt, double eps)
        {
            int i,j,k,m,it,u,v;
            double d,f,h,g,p,r,e,s;

            // ��ֵ
            int n = mtxQ.GetNumColumns();
            dblC[n-1]=0.0;
            d=0.0;
            f=0.0;

            // ��������

            for (j=0; j<=n-1; j++)
            {
                it=0;
                h=eps*(Math.Abs(dblB[j])+Math.Abs(dblC[j]));
                if (h>d)
                    d=h;

                m=j;
                while ((m<=n-1) && (Math.Abs(dblC[m])>d))
                    m=m+1;

                if (m!=j)
                {
                    do
                    {
                        if (it==nMaxIt)
                            return false;

                        it=it+1;
                        g=dblB[j];
                        p=(dblB[j+1]-g)/(2.0*dblC[j]);
                        r=Math.Sqrt(p*p+1.0);
                        if (p>=0.0)
                            dblB[j]=dblC[j]/(p+r);
                        else
                            dblB[j]=dblC[j]/(p-r);

                        h=g-dblB[j];
                        for (i=j+1; i<=n-1; i++)
                            dblB[i]=dblB[i]-h;

                        f=f+h;
                        p=dblB[m];
                        e=1.0;
                        s=0.0;
                        for (i=m-1; i>=j; i--)
                        {
                            g=e*dblC[i];
                            h=e*p;
                            if (Math.Abs(p)>=Math.Abs(dblC[i]))
                            {
                                e=dblC[i]/p;
                                r=Math.Sqrt(e*e+1.0);
                                dblC[i+1]=s*p*r;
                                s=e/r;
                                e=1.0/r;
                            }
                            else
                            {
                                e=p/dblC[i];
                                r=Math.Sqrt(e*e+1.0);
                                dblC[i+1]=s*dblC[i]*r;
                                s=1.0/r;
                                e=e/r;
                            }

                            p=e*dblB[i]-s*g;
                            dblB[i+1]=h+s*(e*g+s*dblB[i]);
                            for (k=0; k<=n-1; k++)
                            {
                                u=k*n+i+1;
                                v=u-1;
                                h=mtxQ.elements[u];
                                mtxQ.elements[u]=s*mtxQ.elements[v]+e*h;
                                mtxQ.elements[v]=e*mtxQ.elements[v]-s*h;
                            }
                        }

                        dblC[j]=s*p;
                        dblB[j]=e*p;

                    } while (Math.Abs(dblC[j])>d);
                }

                dblB[j]=dblB[j]+f;
            }

            for (i=0; i<=n-1; i++)
            {
                k=i;
                p=dblB[i];
                if (i+1<=n-1)
                {
                    j=i+1;
                    while ((j<=n-1) && (dblB[j]<=p))
                    {
                        k=j;
                        p=dblB[j];
                        j=j+1;
                    }
                }

                if (k!=i)
                {
                    dblB[k]=dblB[i];
                    dblB[i]=p;
                    for (j=0; j<=n-1; j++)
                    {
                        u=j*n+i;
                        v=j*n+k;
                        p=mtxQ.elements[u];
                        mtxQ.elements[u]=mtxQ.elements[v];
                        mtxQ.elements[v]=p;
                    }
                }
            }

            return true;
        }
Beispiel #5
0
        /**
         * ������ϡ�跽�����ȫѡ��Ԫ��˹��Լȥ��ȥ��
         *
         * @param mtxResult - CMatrix���ö��󣬷��ط���������
         * @return bool �ͣ�����������Ƿ�ɹ�
         */
        public bool GetRootsetGgje(Matrix mtxResult)
        {
            int i,j,k,nIs=0,u,v;
            double d,t;

            // ���������ԣ����������󸳸������
            Matrix mtxCoef = new Matrix(mtxLECoef);
            mtxResult.SetValue(mtxLEConst);
            int n = mtxCoef.GetNumColumns();
            double[] pDataCoef = mtxCoef.GetData();
            double[] pDataConst = mtxResult.GetData();

            // ��ʱ����������ű任������
            int[] pnJs = new int[n];

            // ��Ԫ
            for (k=0; k<=n-1; k++)
            {
                d=0.0;
                for (i=k; i<=n-1; i++)
                {
                    for (j=k; j<=n-1; j++)
                    {
                        t=Math.Abs(pDataCoef[i*n+j]);
                        if (t>d)
                        {
                            d=t;
                            pnJs[k]=j;
                            nIs=i;
                        }
                    }
                }

                if (d == 0.0)
                {
                    return false;
                }

                if (nIs!=k)
                {
                    for (j=k; j<=n-1; j++)
                    {
                        u=k*n+j;
                        v=nIs*n+j;
                        t=pDataCoef[u];
                        pDataCoef[u]=pDataCoef[v];
                        pDataCoef[v]=t;
                    }

                    t=pDataConst[k];
                    pDataConst[k]=pDataConst[nIs];
                    pDataConst[nIs]=t;
                }

                if (pnJs[k]!=k)
                {
                    for (i=0; i<=n-1; i++)
                    {
                        u=i*n+k;
                        v=i*n+pnJs[k];
                        t=pDataCoef[u];
                        pDataCoef[u]=pDataCoef[v];
                        pDataCoef[v]=t;
                    }
                }

                t=pDataCoef[k*n+k];
                for (j=k+1; j<=n-1; j++)
                {
                    u=k*n+j;
                    if (pDataCoef[u]!=0.0)
                        pDataCoef[u]=pDataCoef[u]/t;
                }

                pDataConst[k]=pDataConst[k]/t;
                for (j=k+1; j<=n-1; j++)
                {
                    u=k*n+j;
                    if (pDataCoef[u]!=0.0)
                    {
                        for (i=0; i<=n-1; i++)
                        {
                            v=i*n+k;
                            if ((i!=k)&&(pDataCoef[v]!=0.0))
                            {
                                nIs=i*n+j;
                                pDataCoef[nIs]=pDataCoef[nIs]-pDataCoef[v]*pDataCoef[u];
                            }
                        }
                    }
                }

                for (i=0; i<=n-1; i++)
                {
                    u=i*n+k;
                    if ((i!=k)&&(pDataCoef[u]!=0.0))
                        pDataConst[i]=pDataConst[i]-pDataCoef[u]*pDataConst[k];
                }
            }

            // ����
            for (k=n-1; k>=0; k--)
            {
                if (k!=pnJs[k])
                {
                    t=pDataConst[k];
                    pDataConst[k]=pDataConst[pnJs[k]];
                    pDataConst[pnJs[k]]=t;
                }
            }

            return true;
        }
Beispiel #6
0
        /**
         * ʵ�־���ļ���
         *
         * @param other - ��ָ����������ľ���
         * @return Matrix�ͣ�ָ��������other���֮��
         * @����������/������ƥ�䣬����׳��쳣
         */
        public Matrix Subtract(Matrix other)
        {
            if (numColumns != other.GetNumColumns() ||
                numRows != other.GetNumRows())
                throw new Exception("�������/������ƥ�䡣");

            // ����������
            Matrix	result = new Matrix(this) ;		// ��������

            // ���������
            for (int i = 0 ; i < numRows ; ++i)
            {
                for (int j = 0 ; j <  numColumns; ++j)
                    result.SetElement(i, j, result.GetElement(i, j) - other.GetElement(i, j)) ;
            }

            return result ;
        }
Beispiel #7
0
        /**
         * ������ֵ
         *
         * @param other - ���ڸ�����ֵ��Դ����
         * @return Matrix�ͣ�����other���
         */
        public Matrix SetValue(Matrix other)
        {
            if (other != this)
            {
                Init(other.GetNumRows(), other.GetNumColumns());
                SetData(other.elements);
            }

            // finally return a reference to ourselves
            return this ;
        }
Beispiel #8
0
        /**
         * ������ij˷�
         *
         * @param AR - ��߸������ʵ������
         * @param AI - ��߸�������鲿����
         * @param BR - �ұ߸������ʵ������
         * @param BI - �ұ߸�������鲿����
         * @param CR - �˻��������ʵ������
         * @param CI - �˻���������鲿����
         * @return bool�ͣ�������˷��Ƿ�ɹ�
         */
        public bool Multiply(Matrix AR,  Matrix AI,  Matrix BR,  Matrix BI, Matrix CR, Matrix CI)
        {
            // ���ȼ���������Ƿ����Ҫ��
            if (AR.GetNumColumns() != AI.GetNumColumns() ||
                AR.GetNumRows() != AI.GetNumRows() ||
                BR.GetNumColumns() != BI.GetNumColumns() ||
                BR.GetNumRows() != BI.GetNumRows() ||
                AR.GetNumColumns() != BR.GetNumRows())
                return false;

            // ����˻�����ʵ��������鲿����
            Matrix mtxCR = new Matrix(AR.GetNumRows(), BR.GetNumColumns());
            Matrix mtxCI = new Matrix(AR.GetNumRows(), BR.GetNumColumns());
            // ���������
            for (int i=0; i<AR.GetNumRows(); ++i)
            {
                for (int j=0; j<BR.GetNumColumns(); ++j)
                {
                    double vr = 0;
                    double vi = 0;
                    for (int k =0; k<AR.GetNumColumns(); ++k)
                    {
                        double p = AR.GetElement(i, k) * BR.GetElement(k, j);
                        double q = AI.GetElement(i, k) * BI.GetElement(k, j);
                        double s = (AR.GetElement(i, k) + AI.GetElement(i, k)) * (BR.GetElement(k, j) + BI.GetElement(k, j));
                        vr += p - q;
                        vi += s - p - q;
                    }
                    mtxCR.SetElement(i, j, vr);
                    mtxCI.SetElement(i, j, vi);
                }
            }

            CR = mtxCR;
            CI = mtxCI;

            return true;
        }
Beispiel #9
0
        /**
         * ʵ�־���ij˷�
         *
         * @param other - ��ָ��������˵ľ���
         * @return Matrix�ͣ�ָ��������other���֮��
         * @����������/������ƥ�䣬����׳��쳣
         */
        public Matrix Multiply(Matrix other)
        {
            // ���ȼ���������Ƿ����Ҫ��
            if (numColumns != other.GetNumRows())
                throw new Exception("�������/������ƥ�䡣");

            // ruct the object we are going to return
            Matrix	result = new Matrix(numRows, other.GetNumColumns());

            // ����˷�����
            //
            // [A][B][C]   [G][H]     [A*G + B*I + C*K][A*H + B*J + C*L]
            // [D][E][F] * [I][J] =   [D*G + E*I + F*K][D*H + E*J + F*L]
            //             [K][L]
            //
            double	value ;
            for (int i = 0 ; i < result.GetNumRows() ; ++i)
            {
                for (int j = 0 ; j < other.GetNumColumns() ; ++j)
                {
                    value = 0.0 ;
                    for (int k = 0 ; k < numColumns ; ++k)
                    {
                        value += GetElement(i, k) * other.GetElement(k, j) ;
                    }

                    result.SetElement(i, j, value) ;
                }
            }

            return result ;
        }
Beispiel #10
0
 /**
  * �������캯��
  *
  * @param other - Դ����
  */
 public Matrix( Matrix other)
 {
     numColumns = other.GetNumColumns();
     numRows = other.GetNumRows();
     Init(numRows, numColumns);
     SetData(other.elements);
 }