Пример #1
0
        private void button1_Click(object sender, EventArgs e)
        {
            double xmax = 1;
            double xmin = -1;

            double a = Convert.ToDouble(textBox4.Text);
            N = Convert.ToInt32(textBox5.Text);
            n = N / 10;
            double h = (xmax - xmin) / N;

            Input(a, h, xmin, xmax);
            p = new double[N];

            if (flag == 1)
                InputP_1();
            else
                InputP_2();

            InputP_2();

            Vector.p = p;
            Vector x = new Vector(N - 1);
            Vector y = new Vector(N - 1);

            for (int i = 0; i < N - 1; i++)
            {
                x[i] = Convert.ToDouble(this.dataGridView1.Rows[i].Cells[0].Value);
                y[i] = Convert.ToDouble(this.dataGridView1.Rows[i].Cells[1].Value);
            }

            Vector[] phi = new Vector[n];
            for (int i = 0; i < n; i++)
                phi[i] = new Vector(N - 1);
            for (int i = 0; i < N - 1; i++)
                phi[0][i] = 1;

            double norm = Vector.Norm(phi[0]);
            for (int i = 0; i < N - 1; i++)
                phi[0][i] /= norm;

            for (int j = 1; j < n; j++)
            {
                phi[j] = x * phi[j - 1];
                for (int i = j - 1; i >= 0 ; i--)
                {
                    phi[j] = phi[j] + ( -Vector.DotProduct(x * phi[j - 1], phi[i])) * phi[i];
                }
                phi[j] /= Vector.Norm(phi[j]);
            }

            Vector ystar = new Vector(N - 1);

            Cet_Output_Tabble();

            for (int j = 0; j < n; j++)
            {
                ystar = ystar + Vector.DotProduct(y, phi[j]) * phi[j];
                Output(ystar, j);
            }

            radioButton1.Enabled = false;
            radioButton2.Enabled = false;
            button3.Enabled = true;
            button1.Enabled = false;
             //   Output(ystar, 0);
             //       Console.WriteLine();
        }
Пример #2
0
 public static double DotProduct(Vector a, Vector b)
 {
     int n;
     if (a.n == b.n)
         n = a.n;
     else
         throw new ArgumentException();
     double sum = 0;
     for (int i = 0; i < n; i++)
         sum += a[i] * b[i] * p[i];
     return sum;
 }
Пример #3
0
 public static double Norm(Vector a)
 {
     return Math.Sqrt(DotProduct(a, a));
 }
Пример #4
0
 public static Vector operator /(Vector v, double k)
 {
     Vector result = new Vector(v.n);
     for (int i = 0; i < v.n; i++)
         result[i] = v[i] / k;
     return result;
 }
Пример #5
0
 public static Vector operator +(Vector v1, Vector v2)
 {
     int n;
     if (v1.n == v2.n)
         n = v1.n;
     else
         throw new ArgumentException();
     Vector sum = new Vector(n);
     for (int i = 0; i < n; i++)
     {
         sum[i] = v1[i] + v2[i];
     }
     return sum;
 }
Пример #6
0
 public static Vector operator *(Vector v1, Vector v2)
 {
     int n;
     if (v1.n == v2.n)
         n = v1.n;
     else
         throw new ArgumentException();
     Vector result = new Vector(n);
     for (int i = 0; i < n; i++)
         result[i] = v1[i] * v2[i];
     return result;
 }
Пример #7
0
 public static Vector operator *(double k, Vector v)
 {
     Vector result = new Vector(v.n);
     for (int i = 0; i < v.n; i++)
         result[i] = k * v[i];
     return result;
 }
Пример #8
0
        private void Output(Vector ystar, int j)
        {
            Vector y = new Vector(N - 1);

            for (int i = 0; i < N - 1; i++)
                y[i] = Convert.ToDouble(this.dataGridView1.Rows[i].Cells[1].Value);

            for (int i = 0; i < ystar.data.Length; i++)
                this.dataGridView2.Rows[i].Cells[j].Value = Convert.ToDouble(Math.Abs((ystar[i]) - y[i]));
        }