Ejemplo n.º 1
0
        private static int FindSolutionRootNumber(List <ComplexNumber> roots, ref int maxId, ComplexNumber complexNumber)
        {
            bool known = false;
            int  id    = 0;

            for (int i = 0; i < roots.Count; i++)
            {
                if (Math.Pow(complexNumber.RealPart - roots[i].RealPart, 2)
                    + Math.Pow(complexNumber.ImaginaryPart - roots[i].ImaginaryPart, 2) <= 0.01)
                {
                    known = true;
                    id    = i;
                }
            }
            if (!known)
            {
                roots.Add(complexNumber);
                id    = roots.Count;
                maxId = id + 1;
            }

            return(id);
        }
Ejemplo n.º 2
0
        static void Main(string[] args)
        {
            if (args.Length == 2)
            {
                if (!Int32.TryParse(args[0], out width))
                {
                    Console.WriteLine("Error occured while parsing arg[0] to Width value");
                    return;
                }
                if (!Int32.TryParse(args[1], out height))
                {
                    Console.WriteLine("Error occured while parsing arg[1] to Height value");
                    return;
                }
            }
            else
            {
                Console.WriteLine("Please enter the width and height of the canvas");
                Console.WriteLine("Width = ");
                if (!Int32.TryParse(Console.ReadLine(), out width))
                {
                    Console.WriteLine("Error occured while parsing input to Width value");
                    return;
                }
                Console.WriteLine("Height = ");
                if (!Int32.TryParse(Console.ReadLine(), out height))
                {
                    Console.WriteLine("Error occured while parsing input to Height value");
                    return;
                }
            }
            if (width > 0 && height > 0)
            {
                Initialize();
                for (int xCoordinate = 0; xCoordinate < width; xCoordinate++)
                {
                    for (int yCoordinate = 0; yCoordinate < height; yCoordinate++)
                    {
                        chosenComplex = new ComplexNumber()
                        {
                            RealPart      = xmin + yCoordinate * xstep,
                            ImaginaryPart = ymin + xCoordinate * ystep
                        };
                        if (chosenComplex.isComplexZero())
                        {
                            chosenComplex.RealPart      = 0.0001;
                            chosenComplex.ImaginaryPart = 0.0001f;
                        }
                        FindSolutionByNewton();

                        FindIdOfRoot();

                        ColorizePixel(idOfRoot, iteration, yCoordinate, xCoordinate);
                    }
                }
                bmpCanvas.Save("../../../INPTPZ1_output.png");
            }
            else
            {
                Console.WriteLine("Invalid input for Width and/or Height!");
                return;
            }
            Console.ReadKey();
            return;
        }
Ejemplo n.º 3
0
        private static float FindSolution(Polynome polynome, Polynome polynomeDerivated, ref ComplexNumber complexNumber)
        {
            // find solution of equation using newton's iteration
            float it = 0;

            for (int q = 0; q < 30; q++)
            {
                ComplexNumber diff = polynome.Evaluate(complexNumber).Divide(polynomeDerivated.Evaluate(complexNumber));
                complexNumber = complexNumber.Subtract(diff);

                if (Math.Pow(diff.RealPart, 2) + Math.Pow(diff.ImaginaryPart, 2) >= 0.5)
                {
                    q--;
                }
                it++;
            }

            return(it);
        }