Ejemplo n.º 1
0
        public static PoissonSolvers1D operator +(PoissonSolvers1D a1, PoissonSolvers1D a2)
        {
            double           temp1, temp2, sum;
            PoissonSolvers1D temp = new PoissonSolvers1D(a1.nDim);

            for (int i = 0; i < a1.nDim; i++)
            {
                for (int j = 0; j < a1.nDim; j++)
                {
                    temp1 = a1.getElement(i, j);
                    temp2 = a2.getElement(i, j);
                    sum   = temp1 + temp2;
                    temp.setElement(sum, i, j);
                }
            }

            return(temp);
        }
        private void btn_Click(object sender, RoutedEventArgs e)
        {
//            p.Set(-2.0, 4.0);
            //p.Set(-4.0, 14.0);
//            p.Set(13.0, -14.0);


            //p.Set(1.0, 2.0);

            string txt1 = nPnt.Text;
            string txt2 = point0.Text;
            string txt3 = point1.Text;
            string txt4 = func0.Text;
            string txt5 = func1.Text;


            if ((String.IsNullOrEmpty(txt1.Trim())) || (String.IsNullOrEmpty(txt2.Trim())) || (String.IsNullOrEmpty(txt3.Trim())) || (String.IsNullOrEmpty(txt4.Trim())) || (String.IsNullOrEmpty(txt5.Trim())))

            {
                MessageBox.Show("Error. Please input all required parameters");
                return;
            }

            ndim = int.Parse(nPnt.Text);


            x0 = double.Parse(point0.Text);
            x1 = double.Parse(point1.Text);

            x  = new double[ndim];
            dh = (x1 - x0) / (ndim - 1);

            f0 = double.Parse(func0.Text);
            f1 = double.Parse(func1.Text);



            double tempVal;

            double[] rhs = new double[ndim];



            p1D = new PoissonSolvers1D(ndim);



            p1D.initPoint = f0;
            p1D.endPoint  = f1;
            p1D.dh        = dh;

            tempVal = 0;

            if (comboBox1.SelectedIndex == -1)
            {
                MessageBox.Show("No Item is Selected, Choosing Default Value");
                comboBox1.SelectedIndex = 0;
            }

            for (int i = 0; i < ndim; i++)
            {
                x[i] = x0 + i * dh;

                if (comboBox1.SelectedIndex == 0)
                {
                    tempVal = 30.0 * Math.Sin(Math.Sqrt(30.0) * x[i]);
                }
                else if (comboBox1.SelectedIndex == 1)
                {
                    tempVal = 1.0 + 2.0 * x[i] * x[i] - 12 * x[i] * x[i] * x[i] * x[i];
                }

                else if (comboBox1.SelectedIndex == 2)
                {
                    tempVal = x[i];
                }

                else if (comboBox1.SelectedIndex == 3)
                {
                    tempVal = Math.Exp(-x[i] * x[i]) * Math.Cos(10.0 * x[i]);
                }
                else if (comboBox1.SelectedIndex == 4)
                {
                    tempVal = 1.0 - 2.0 * x[i] * x[i];
                }
                else if (comboBox1.SelectedIndex == 5)
                {
                    tempVal = 2.0 * (1.0 / (Math.Exp(x[i]) + Math.Exp(-x[i]))) * Math.Tanh(x[i]);
                }


                p1D.setRHS(i, tempVal);
            }

            p1D.augB();



            double[] xx = new double[ndim];

            xx = p1D.Solve();



            for (int i = 0; i < ndim; i++)
            {
                p1.Set(x[i], -xx[i]);
            }


            DataContext = p1;


            x   = null;
            p1D = null;
            rhs = null;
            xx  = null;
        }