一些简单算法

 #region 小算法方法
        //从一组数距中找到最大的数返回结果
        private double GetMaxVaue(double[] dArry)
        {
            double max = dArry[0];

            for (int i = 0; i < dArry.Length; i++)
            {
                //如果想得到最小值。
                //直接返回max 或者设条件为dList[i]<max 返回max=dList[i]
                if (dArry[i] > max)
                {
                    max = dArry[i];
                }
            }
            return max;
        }

        //计算平均值
        private double GetAvg(double[] dArry)
        {
            double avg = 0;
            double sum = 0;
            for (int i = 0; i < dArry.Length; i++)
            {
                sum += dArry[i];
            }
            avg = sum / dArry.Length;
            return avg;
        }

        //从一个数组Copy到另一个新的数组中
        private double[] CopyArryToNewArry(double[] oldArry)
        {
            double[] newArray = new double[oldArry.Length];
            for (int i = 0; i < oldArry.Length; i++)
            {
                newArray[i] = oldArry[i];
            }
            return newArray;
        }

        //颠倒数组的排序
        private double[] DescArray(double[] dArray)
        {

            int len = dArray.Length;
            for (int i = 0; i < len / 2; i++)
            {
                double temp = dArray[i];
                dArray[i] = dArray[len - 1 - i];
                dArray[len - 1 - i] = temp;
            }
            return dArray;
        }

        //矩阵相乘
        private double[][] JuZhenCheng(double[][] A, double[][] B)
        {
            int len = A.Length;
            //在java 中的申明方式和C# 中的有点区别 在java 中申明double[][] C =new double[len][len];
            double[][] C = new double[len][];
            for (int i = 0; i < len; i++)
            {
                for (int j = 0; j < len; j++)
                {
                    //计算行i,和列j的点乘
                    for (int k = 0; k < len; k++)
                    {
                        C[i][j] += A[i][k] * B[k][j];
                    }
                }
            }
            return C;
        }

        #endregion

http://user.qzone.qq.com/1273704678/infocenter#!app=2&via=QZ.HashRefresh&pos=1362739438

你可能感兴趣的:(算方法矩阵算法)