Esempio n. 1
0
        private void buttonGauss_Click(object sender, EventArgs e)
        {
            // organizing difference table
            dataGridViewDifferenceTable.Columns.Clear();
            string[] nums = new string[] { "¹", "²", "³", "⁴", "⁵", "⁶", "⁷", "⁸", "⁹" };
            for (int i = 0; i < dataGridViewGaussNodes.Rows.Count - 1; ++i)
            {
                dataGridViewDifferenceTable.Columns.Add(i.ToString(), "Δ" + (i == 0 ? "" : nums[i]) + "y");
            }
            dataGridViewDifferenceTable.Rows.Add(dataGridViewGaussNodes.Rows.Count - 1);

            nodes.Clear();
            values.Clear();

            try
            {
                foreach (DataGridViewRow row in dataGridViewGaussNodes.Rows)
                {
                    nodes.Add(double.Parse(row.Cells[0].Value.ToString()));
                    values.Add(double.Parse(row.Cells[1].Value.ToString()));
                }

                GaussForwardInterpolation f = new GaussForwardInterpolation(nodes.ToArray(), values.ToArray());

                label2.Text = "Result: " + Math.Round(f.GaussInterpolation(double.Parse(textBox1.Text)), 3);
                for (int i = 1; i < f.Diff_table.GetLength(0); i++)
                {
                    for (int j = 0; j < f.Diff_table[i].Length; j++)
                    {
                        dataGridViewDifferenceTable.Rows[j].Cells[i - 1].Value = Math.Round(f.Diff_table[i][j], 4);
                    }
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
Esempio n. 2
0
        private void buttonGauss_Click(object sender, EventArgs e)
        {
            // organizing difference table
            dataGridViewDifferenceTable.Columns.Clear();
            string[] nums = new string[] { "¹","²","³","⁴","⁵","⁶","⁷","⁸","⁹" };
            for(int i = 0; i < dataGridViewGaussNodes.Rows.Count - 1; ++i)
            {
                dataGridViewDifferenceTable.Columns.Add(i.ToString(), "Δ" + (i == 0 ? "" : nums[i]) + "y");
            }
            dataGridViewDifferenceTable.Rows.Add(dataGridViewGaussNodes.Rows.Count - 1);

            nodes.Clear();
            values.Clear();

            try
            {
                foreach (DataGridViewRow row in dataGridViewGaussNodes.Rows)
                {
                    nodes.Add(double.Parse(row.Cells[0].Value.ToString()));
                    values.Add(double.Parse(row.Cells[1].Value.ToString()));
                }

                GaussForwardInterpolation f = new GaussForwardInterpolation(nodes.ToArray(),values.ToArray());

                label2.Text = "Result: " + Math.Round(f.GaussInterpolation( double.Parse(textBox1.Text) ),3);
                for (int i = 1; i < f.Diff_table.GetLength(0); i++)
                {
                    for (int j = 0; j < f.Diff_table[i].Length; j++)
                    {
                        dataGridViewDifferenceTable.Rows[j].Cells[i - 1].Value = Math.Round(f.Diff_table[i][j], 4);
                    }
                }

                
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
      }