private static void Initialize() { bmpCanvas = new Bitmap(width, height); xmin = ymin = -1.5; xmax = ymax = 1.5; xstep = (xmax - xmin) / width; ystep = (ymax - ymin) / height; colors = new Color[] { Color.Magenta, Color.Aqua, Color.Lime }; roots = new List <ComplexNumber>(); poly = new Polynome(new List <ComplexNumber> { new ComplexNumber { RealPart = 1 }, ComplexNumber.Zero, ComplexNumber.Zero, new ComplexNumber { RealPart = 1 }, }); derivationPoly = poly.Derivate(); Console.WriteLine("f(x) = " + poly); Console.WriteLine("f'(x) = " + derivationPoly); }
static void Main(string[] args) { int rootsCount = Convert.ToInt32(args[0]); Bitmap bmp = new Bitmap(300, 300); double xmin = -1; double xmax = 1; double ymin = -1; double ymax = 1; double xstep = (xmax - xmin) / 300; double ystep = (ymax - ymin) / 300; List <ComplexNumber> koreny = new List <ComplexNumber>(); Polynome polynome = new Polynome(rootsCount > 0 && rootsCount < 10 ? rootsCount : 0); Polynome polynomeDerivated = polynome.Derive(); Color[] colors = new Color[] { Color.Red, Color.Blue, Color.Green, Color.Yellow, Color.Orange, Color.Fuchsia, Color.Gold, Color.Cyan, Color.Magenta }; Process(bmp, xmin, ymin, xstep, ystep, koreny, polynome, polynomeDerivated, colors); bmp.Save("../../../out.png"); }
public Polynome Derivate() { Polynome derivation = new Polynome(); for (int i = 1; i < Coefficient.Count; i++) { derivation.Coefficient.Add(Coefficient[i].Multiply(new ComplexNumber() { RealPart = i })); } return derivation; }
public Polynome Derive() { Polynome p = new Polynome(); for (int i = 1; i < ComplexNumbers.Count; i++) { p.ComplexNumbers.Add(ComplexNumbers[i].Multiply(new ComplexNumber() { RealPart = i })); } return(p); }
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); }
private static void Process(Bitmap bmp, double xmin, double ymin, double xstep, double ystep, List <ComplexNumber> roots, Polynome polynome, Polynome polynomeDerivated, Color[] colors) { int maxid = 0; for (int i = 0; i < 300; i++) { for (int j = 0; j < 300; j++) { ComplexNumber ox = FindCoordinates(xmin, ymin, xstep, ystep, i, j); float it = FindSolution(polynome, polynomeDerivated, ref ox); int id = FindSolutionRootNumber(roots, ref maxid, ox); ColorizePixels(bmp, colors, i, j, it, id); } } }