Exemple #1
0
        private void CountBtn_Click(object sender, EventArgs e)
        {
            ResultView.Clear();

            string[] vectors = MatrixView.Text.Split(new[] { Environment.NewLine }, StringSplitOptions.None);
            double[,] matrixA = new double[vectors.Count(), vectors[0].Split(' ').Count()];
            int numberOfVariables = vectors.Count() - 1;

            for (int i = 0; i < numberOfVariables; i++)
            {
                string[] cells = vectors[i].Split(' ');
                for (int j = 0; j < cells.Count(); j++)
                {
                    matrixA[i, j] = double.Parse(cells[j]);
                }
            }

            for (int i = 0; i < numberOfVariables - 1; i++)
            {
                for (int j = i + 1; j < numberOfVariables; j++)
                {
                    double m = 0;
                    if (matrixA[i, i] != 0)
                    {
                        m = (-1) * (matrixA[j, i] / matrixA[i, i]);
                    }
                    for (int k = i; k < numberOfVariables + 1; k++)
                    {
                        matrixA[j, k] = matrixA[j, k] + m * matrixA[i, k];
                    }
                }
            }

            double[] matrixResult = new double[numberOfVariables];
            for (int i = 0; i < numberOfVariables; i++)
            {
                matrixResult[i] = 1;
            }

            for (int i = numberOfVariables - 1; i > -1; i--)
            {
                double s = matrixA[i, numberOfVariables];
                for (int j = numberOfVariables - 1; j > i; j--)
                {
                    s = s - matrixA[i, j] * matrixResult[j];
                }
                matrixResult[i] = s / matrixA[i, i];
            }

            String result = "";

            for (int i = 0; i < matrixResult.Count(); i++)
            {
                result += "x" + (i + 1).ToString() + " = " + matrixResult[i].ToString() + Environment.NewLine;
            }
            ResultView.Text += result;
        }
Exemple #2
0
 private void BindToken()
 {
     ResultView.GridLines = true;
     ResultView.View      = View.Details;
     ResultView.Clear();
     ResultView.Columns.Add("ID", 40);
     ResultView.Columns.Add("类型", 100);
     ResultView.Columns.Add("内容", 120);
     ResultView.Columns.Add("行", 40);
     ResultView.Columns.Add("列", 40);
     foreach (Token log in Analyse.Token)
     {
         List <String> a = new List <string>();
         a.Add(log.Id.ToString());
         a.Add(log.Type.ToString());
         a.Add(log.Content);
         a.Add(log.Row.ToString());
         a.Add(log.Column.ToString());
         ListViewItem listViewItem = new ListViewItem(a.ToArray());
         ResultView.Items.Add(listViewItem);
     }
 }
Exemple #3
0
 private void ClearBtn_Click(object sender, EventArgs e)
 {
     ResultView.Clear();
 }