예제 #1
0
        static void NewtonRapson(double startvalue, int limit, F_x XPolynome, F_x XDerivate, int degP, List <double> listP, int degD, List <double> listD)
        {
            const int MaxIterations = 1000;
            double    limited       = (1 / Math.Pow(10, limit));

            Console.SetWindowSize(80, 30);

            double Xh = 0.0, Xh1 = 0.0;
            string linestr = string.Empty;

            linestr = linestr.PadRight(72, '-');
            Console.WriteLine(linestr);
            Console.WriteLine("| {0,-15}| {1,-15} | {2,-15} | {3,-15} |       ", "Iteration", "x", "f(x)", "f'(x)");
            Console.WriteLine(linestr);
            Console.WriteLine("|     {0,-10} | {1,15:0.00000} | {2,15:0.00000} | {3,15:0.00000} |       ", 0, startvalue, XPolynome(startvalue, degP, listP), XDerivate(startvalue, degD, listD));

            Xh = startvalue;
            for (int i = 1; i < MaxIterations; ++i)
            {
                Xh1 = Xh - (XPolynome(Xh, degP, listP) / XDerivate(Xh, degD, listD));

                if (Math.Abs(Xh1 - Xh) <= limited)
                {
                    Console.WriteLine(linestr);
                    Console.WriteLine("Root = {0,15:0.00000}".PadRight(Console.WindowWidth), Xh);
                    break;
                }
                else
                {
                    Console.WriteLine("|     {0,-10} | {1,15:0.00000} | {2,15:0.00000} | {3,15:0.00000} |       ", i, Xh1, XPolynome(Xh1, degP, listP), XDerivate(Xh1, degD, listD));
                    Xh = Xh1;
                }
            }
        }
예제 #2
0
        public BodyRotation(double x, double y, double z, double a, double b, double h, F_x f, Color c, bool fill, bool filled = true, int m = 50)
        {
            this.filled = filled;

            int n = (int)Math.Ceiling((b - a) / h);

            s = new Vector[n][];

            for (int i = 0; i < n; i++)
            {
                s[i] = new Vector[m];

                double r     = f(a + i * h);
                double angle = Math.PI / m * 2;

                for (int j = 0; j < m; j++)
                {
                    double x0 = x + r * Math.Sin(j * angle);
                    double y0 = y + i * h;
                    double z0 = z + r * Math.Cos(j * angle);

                    s[i][j] = new Vector(x0, y0, z0);
                }
            }

            for (int j = 0; j < s[0].Length; j++)
            {
                lines.Add(new Line(s[0][j], s[0][(j + 1) % s[0].Length], c));

                if (fill)
                {
                    triangles.Add(new Triangle(s[0][j], s[0][(j + 1) % s[0].Length], new Vector(x, y, z), c));
                    triangles.Add(new Triangle(s[n - 1][j], new Vector(x, y + h * (n - 1), z), s[n - 1][(j + 1) % s[n - 1].Length], c));
                }
            }

            for (int i = 1; i < s.Length; i++)
            {
                for (int j = 0; j < s[i].Length; j++)
                {
                    triangles.Add(new Triangle(s[i - 1][j], s[i][j], s[i - 1][(j + 1) % s[i].Length], c));
                    triangles.Add(new Triangle(s[i][j], s[i][(j + 1) % s[i].Length], s[i - 1][(j + 1) % s[i].Length], c));

                    lines.Add(new Line(s[i - 1][j], s[i][j], c));
                    lines.Add(new Line(s[i][j], s[i][(j + 1) % s[i].Length], c));
                }
            }
        }