示例#1
0
        private void button1_Click(object sender, EventArgs e)
        {
            double t0, tmax, tau;

            t0   = Convert.ToDouble(tbT0.Text);
            tmax = Convert.ToDouble(tbTmax.Text);
            tau  = Convert.ToDouble(tbTau.Text);
            double[] mass = {};
            double   t    = t0;
            int      n    = 3;

            double[] ynach = new double[n];
            ynach[0] = 1.0;
            ynach[1] = 1.0;
            ynach[2] = 0.0;

            MathFuncsDiffEquations myfunc = new MathFuncsDiffEquations();

            if (rbEiler.Checked)
            {
                richTextBox1.Clear();
                mass = myfunc.Eiler(t0, tmax, tau, n, ynach, diffEqu);


                for (int i = 1; i < (int)((tmax - t0) / tau); i++)
                {
                    t += tau;
                    richTextBox1.Text += String.Format("time={0} y1={1:f6} y2={2:f6} y3={3:f6}", t, mass[i * 3],
                                                       mass[1 + i * 3],
                                                       mass[2 + i * 3]) + Environment.NewLine;
                }
            }

            if (rbRK2.Checked)
            {
                richTextBox1.Clear();
                mass = myfunc.RK2(t0, tmax, tau, n, ynach, diffEqu);
                for (int i = 1; i < (int)((tmax - t0) / tau); i++)
                {
                    t += tau;
                    richTextBox1.Text += String.Format("time={0} y1={1:f6} y2={2:f6} y3={3:f6}", t, mass[i * 3],
                                                       mass[1 + i * 3],
                                                       mass[2 + i * 3]) + Environment.NewLine;
                }
            }

            if (rbRK4.Checked)
            {
                richTextBox1.Clear();

                mass = myfunc.RK4(t0, tmax, tau, n, ynach, diffEqu);
                for (int i = 1; i < (int)((tmax - t0) / tau); i++)
                {
                    t += tau;
                    richTextBox1.Text += String.Format("time={0} y1={1:f6} y2={2:f6} y3={3:f6}", t, mass[i * 3],
                                                       mass[1 + i * 3],
                                                       mass[2 + i * 3]) + Environment.NewLine;
                }
            }
        }
示例#2
0
        public void DiffEiler()
        {
            double[] mass = { };
            double   t0 = 0.0, tmax = 0.1, tau = 0.01;

            int n = 3;

            double[] ynach = new double[n];
            ynach[0] = 1.0;
            ynach[1] = 1.0;
            ynach[2] = 0.0;
            mass     = mydiff.Eiler(t0, tmax, tau, n, ynach, diffEqu);
            int nn = (int)((tmax - t0) / tau) - 1;

            Assert.AreEqual(Math.Round(mass[nn * n], 6), 1.182412);
            Assert.AreEqual(Math.Round(mass[nn * n + 1], 6), 1.001024);
            Assert.AreEqual(Math.Round(mass[nn * n + 2], 6), 0.010308);
        }