Пример #1
0
        /*==========================================================================
         * Function:   ToDiscreteTimeSystem
         * Arguments:  double
         * Returns:    One DTModel
         */

        public DTModel ToDiscreteTimeSystem(double ts)
        {
            // Define local variable
            double[,] newMatrixA = new double[MatrixA.GetLength(1),
                                              MatrixA.GetLength(0)];
            double[,] newMatrixB = new double[MatrixB.GetLength(1),
                                              MatrixB.GetLength(0)];
            double[,] newMatrixC = new double[MatrixC.GetLength(1),
                                              MatrixC.GetLength(0)];
            double[,] newMatrixD = new double[MatrixD.GetLength(1),
                                              MatrixD.GetLength(0)];

            // Calculate matrix exponetial to obtain new matrix
            // Update newMatrixA, newMatrixB, newMatrixC, newMatrixD

            // Create a discrete time system
            DTModel dtSystem =
                new DTModel(newMatrixA, newMatrixB, newMatrixC, newMatrixD, ts);

            Console.WriteLine("CT system is transfered to DT system!!");

            // Return discrete time system
            return(dtSystem);
        }
        public List<double> NonNegLeastSquares(double[,] matrix, List<double> values)
        {
            List<double> normalizedValues = this.NormalizeIntensities(values);

            //to handle < 20 intensiites for isotopes
            //otherwise vector-matrix length mismatch and crash
            List<double> tempValues = new List<double>();
            for (int i = 0; i < 20; i++)
            {
                if (i < normalizedValues.Count)
                {
                    tempValues.Add(normalizedValues[i]);
                }
                else
                {
                    tempValues.Add(0);
                }
            }

            List<double> results = new List<double>();
            double[,] tempMatrix = new double[tempValues.Count, 1];

            //hardcoded to handle only 20 isotope intensities
            for (int i = 0; i < 20; i++)
            {
                if (i < normalizedValues.Count)
                {
                    tempMatrix[i, 0] = normalizedValues[i];
                }
                else
                {
                    tempMatrix[i, 0] = 0;
                }
            }

            MatrixC theoretical = new MatrixC(tempMatrix);

            double[] experimental = new double[values.Count];

            for (int i = 0; i < values.Count; i++)
            {
                experimental[i] = values[i];
            }

            VectorC v = new VectorC(experimental);

            var result = solver.MatchLibraryMatrix(theoretical, v);

            for (int i = 0; i < result.GetSize(); i++)
            {
                results.Add(result[i]);
            }

            //calcualte %of each component
            double sum = 0;
            for (int j = 0; j < result.GetSize(); j++)
            {
                sum += results[j];
            }

            for (int k = 0; k < result.GetSize(); k++)
            {
                results[k] = results[k] / sum;
            }
            return results;
        }