Beispiel #1
0
        private void BuildInterpFunc()
        {
            List <PointD> NearPoints = new List <PointD>(GenPoints);

            NearPoints.Sort((A, B) => Math.Abs(A.X - X0).CompareTo(Math.Abs(B.X - X0)));
            NearPoints.RemoveRange((int)tbPower.Value + 1, NearPoints.Count - (int)tbPower.Value - 1);
            NearPoints.Sort((A, B) => A.X.CompareTo(B.X));

            Graphic.Points = NearPoints;

            List <PointD> InvPoints = NearPoints.ConvertAll <PointD>(A => new PointD(A.Y, A.X));

            if (rbNewton.Checked)
            {
                Polynom    = new NewtonPolynom(NearPoints);
                InvPolynom = new NewtonPolynom(InvPoints);
            }
            else
            {
                Polynom = new Spline(NearPoints);
                InvPoints.Sort((A, B) => A.X.CompareTo(B.X));
                InvPolynom = new Spline(InvPoints);
            }
            Graphic.Funcs[1].Func = Polynom.GetValueAt;
            InvInterpFunc         = InvPolynom.GetValueAt;
        }
Beispiel #2
0
        private void button1_Click(object sender, EventArgs e)
        {
            Eps  = Convert.ToDouble(tbEps.Text);
            Eps1 = Convert.ToDouble(tbEps1.Text);

            p0  = Convert.ToDouble(tbP.Text);
            T_0 = Convert.ToDouble(tbT_0.Text);
            T0  = Convert.ToDouble(tbT0.Text);
            Tw  = Convert.ToDouble(tbTw.Text);
            n   = Convert.ToInt32(tbN.Text);

            //c = p0 * 7242 / T_0;
            c = p0 * 3621 / T_0;

            N              = (int)UpDownNTrapez.Value;
            Integral       = Trapez;
            lblAnswer.Text = "Trapezium: p = " + Dihotomy(0, 50).ToString();

            N               = (int)UpDownNSimpson.Value;
            Integral        = Simpson;
            lblAnswer3.Text = "Simpson: p = " + Dihotomy(0, 50).ToString();

            N = (int)UpDownNGauss.Value;
            LegendrePolynom = new LegendrePolynom((int)UpDownNGauss.Value, Eps);

            Integral = Gauss;
            LegendreCoeffs2(N, out LegendreCoefs);
            lblAnswer2.Text = "Gauss: p = " + Dihotomy(0, 50).ToString();
        }
Beispiel #3
0
        public static void PlotFunction(Graphics g, Pen p, double x1, double x2, DoubleFunc function)
        {
            double lx = x1;
            double ly = (double)function(lx);

            double step = (x2 - x1) / (width / 2);

            for (double x = x1; x < x2; x += step)
            {
                double y = function(x);

                g.DrawLine(p, (float)lx, (float)ly, (float)x, (float)y);
                lx = x;
                ly = y;
            }
        }
Beispiel #4
0
        static double Simpson(DoubleFunc Func)
        {
            double Result = 0;
            double dx     = 1 / (double)N;
            double dx2    = 2 * dx;
            double x      = dx2;

            while (x < 1)
            {
                Result += Func(x) + 2 * Func(x + dx);
                x      += dx2;
            }
            Result += (Func(0) + Func(1)) * 0.5 + 2 * Func(dx);
            Result *= dx2 / 3;
            return(Result);
        }
Beispiel #5
0
        static double Trapez(DoubleFunc Func)
        {
            double Result = 0;
            double dx     = 1 / (double)N;
            double x      = dx;

            //for (int i = 1; i < N; i++)
            while (x < 1)
            {
                Result += Func(x);
                x      += dx;
            }
            Result += (Func(0) + Func(1)) * 0.5;
            Result *= dx;
            return(Result);
        }
Beispiel #6
0
        static double Trapec(double A, double B, int N, DoubleFunc Func)
        {
            double Result = 0;
            double t      = Func(A);
            double dx     = (B - A) / N;
            double t1     = Func(A + dx);
            double x      = A;

            while (x < B)
            {
                Result += (t + t1) * 0.5;
                x      += dx;
                t       = t1;
                t1      = Func(x);
            }
            return(Result);
        }
Beispiel #7
0
 public static object Plot(DoubleFunc f1, DoubleFunc f2, DoubleFunc f3, DoubleFunc f4)
 {
     return(PlotFunctions(new DoubleFunc [] { f1, f2, f3, f4 }));
 }
Beispiel #8
0
 public static object Plot(DoubleFunc f1, DoubleFunc f2)
 {
     return(PlotFunctions(new DoubleFunc [] { f1, f2 }));
 }
Beispiel #9
0
 public static object Plot(DoubleFunc function)
 {
     return(PlotFunctions(new DoubleFunc [] { function }));
 }
Beispiel #10
0
 public GraphFunc(DoubleFunc Func, Pen Pen)
 {
     this.Func    = Func;
     this.Pen     = Pen;
     this.Visible = true;
 }
        static object PlotFunctions(DoubleFunc [] funcs)
        {
            Bitmap b = new Bitmap (width, height);

            Matrix t = new Matrix (), invert;
            t.Translate (width/2, height/2);
            t.Scale (2f, -2f);

            invert = t.Clone ();
            invert.Invert ();

            Point [] bounds = new Point [] {
                new Point (0, 0),
                new Point (width, height)
            };
            invert.TransformPoints (bounds);

            Pen black = new Pen (Color.Black);
            black.Transform = invert;

            float x1 = bounds [0].X;
            float x2 = bounds [1].X;

            using (Graphics g = System.Drawing.Graphics.FromImage (b)){
                g.Transform = t;
                DrawAxes (g, black, x1, bounds [1].Y, x2, bounds [0].Y);

                int i = 0;
                g.SmoothingMode = SmoothingMode.AntiAlias;
                foreach (var func in funcs){
                    Pen p = GetPen (i++);
                    p.Transform = invert;

                    PlotFunction (g, p, x1, x2, func);
                }

                g.Transform = new Matrix ();

                g.DrawRectangle (black, 0, 0, width-1, height-1);
            }

            return b;
        }
        public static void PlotFunction(Graphics g, Pen p, double x1, double x2, DoubleFunc function)
        {
            double lx = x1;
            double ly = (double) function (lx);

            double step = (x2-x1)/(width/2);

            for (double x = x1; x < x2; x += step){
                double y = function (x);

                g.DrawLine (p, (float) lx, (float) ly, (float) x, (float) y);
                lx = x;
                ly = y;
            }
        }
 public static object Plot(DoubleFunc f1, DoubleFunc f2, DoubleFunc f3, DoubleFunc f4)
 {
     return PlotFunctions (new DoubleFunc [] { f1, f2, f3, f4 });
 }
 public static object Plot(DoubleFunc f1, DoubleFunc f2)
 {
     return PlotFunctions (new DoubleFunc [] { f1, f2 });
 }
 public static object Plot(DoubleFunc function)
 {
     return PlotFunctions (new DoubleFunc [] { function });
 }
Beispiel #16
0
        public static double GCFDouble(double n1, double n2)
        {
            n1 = Equation.ExNumber.EpsilonCorrect(n1);
            n2 = Equation.ExNumber.EpsilonCorrect(n2);
            if (n1 == 0.0 || n2 == 0.0)
            {
                return(0.0);
            }

            if (double.IsNaN(n1) || double.IsNaN(n2))
            {
                return(double.NaN);
            }

            if (DoubleFunc.IsInfinity(n1) || DoubleFunc.IsInfinity(n2))
            {
                return(double.PositiveInfinity);
            }

            double an1 = Math.Abs(n1);
            double an2 = Math.Abs(n2);

            double multiple = 1;

            // Check if either of the numbers are not whole numbers.
            if (an1 % 1 != 0 || an2 % 1 != 0)
            {
                // Either the top or the bottom is not whole.
                int    distanceFromZero1 = 0, distanceFromZero2 = 0;
                int    index;
                string afterPointStr;
                if (an1 % 1 != 0)
                {
                    string an1Str = an1.ToString();
                    // Check how far the string goes out after the decimal point.
                    index             = an1Str.IndexOf('.');
                    afterPointStr     = an1Str.Substring(index);
                    distanceFromZero1 = afterPointStr.Length - 1;
                }

                if (an2 % 1 != 0)
                {
                    string an2Str = an2.ToString();
                    // Check how far the string goes out after the decimal point.
                    index             = an2Str.IndexOf('.');
                    afterPointStr     = an2Str.Substring(index);
                    distanceFromZero2 = afterPointStr.Length - 1;
                }

                int maxDistanceFromZero = Math.Max(distanceFromZero1, distanceFromZero2);
                //if (maxDistanceFromZero > MAX_GCF_ZERO_DIST)
                //    return n1 * n2;

                multiple *= Math.Pow(10, maxDistanceFromZero);
                an1      *= multiple;
                an2      *= multiple;
            }

            while (an1 != 0)
            {
                double tmp = an1;
                an1 = an2 % an1;
                an2 = tmp;
            }

            if (n1 < 0)
            {
                return(-an2 / multiple);
            }

            return(an2 / multiple);
        }