Example #1
0
        public timefreq(float[] x, int windowSamp)
        {
            int workerThreadCount;
            int ioThreadCount;

            Console.WriteLine("Determining threadcount");
            ThreadPool.GetMinThreads(out workerThreadCount, out ioThreadCount);
            Console.WriteLine(workerThreadCount);
            ThreadPool.SetMinThreads(1, ioThreadCount);

            ThreadPool.GetMinThreads(out workerThreadCount, out ioThreadCount);
            Console.WriteLine(workerThreadCount);

            int workerThreads, completionPortThreads;

            ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
            workerThreads = 4;
            ThreadPool.SetMaxThreads(1, completionPortThreads);

            ThreadPool.GetMaxThreads(out workerThreads, out completionPortThreads);
            Console.WriteLine(workerThreadCount);


            // int ii;
            double  pi = 3.14159265;
            Complex i  = Complex.ImaginaryOne;

            this.wSamp = windowSamp;
            twiddles   = new Complex[wSamp];


            //Parallel.For(0, wSamp, ii =>
            //{
            //    double a = 2 * pi * ii / (double)wSamp;
            //    twiddles[ii] = Complex.Pow(Complex.Exp(-i), (float)a);
            //});
            for (int ii = 0; ii < wSamp; ii++)
            {
                double a = 2 * pi * ii / (double)wSamp;
                twiddles[ii] = Complex.Pow(Complex.Exp(-i), (float)a);
            }

            timeFreqData = new float[wSamp / 2][];


            int nearest = (int)Math.Ceiling((double)x.Length / (double)wSamp);

            nearest = nearest * wSamp;

            Complex[] compX = new Complex[nearest];

            //Parallel.For(0, nearest, kk =>
            //{
            //    if (kk < x.Length)
            //    {
            //        compX[kk] = x[kk];
            //    }
            //    else
            //    {
            //        compX[kk] = Complex.Zero;
            //    }
            //});

            for (int kk = 0; kk < nearest; kk++)
            {
                if (kk < x.Length)
                {
                    compX[kk] = x[kk];
                }
                else
                {
                    compX[kk] = Complex.Zero;
                }
            }


            int cols = 2 * nearest / wSamp;

            Parallel.For(0, wSamp / 2, jj =>
            {
                timeFreqData[jj] = new float[cols];
            });


            //for (int jj = 0; jj < wSamp / 2; jj++)
            //{
            //    timeFreqData[jj] = new float[cols];
            //}

            compXG       = compX;
            timeFreqData = stft(compX, wSamp);
        }
Example #2
0
        // Onset Detection function - Determines Start and Finish times of a note and the frequency of the note over each duration.

        private void onsetDetection()
        {
            float[] HFC;
            int     starts = 0;
            int     stops  = 0;

            Complex[]     Y;
            double[]      absY;
            List <int>    lengths;
            List <int>    noteStarts;
            List <int>    noteStops;
            List <double> pitches;


            double  pi = 3.14159265;
            Complex i  = Complex.ImaginaryOne;

            noteStarts = new List <int>(100);
            noteStops  = new List <int>(100);
            lengths    = new List <int>(100);
            pitches    = new List <double>(100);

            SolidColorBrush sheetBrush = new SolidColorBrush(Colors.Black);
            SolidColorBrush ErrorBrush = new SolidColorBrush(Colors.Red);
            SolidColorBrush whiteBrush = new SolidColorBrush(Colors.White);

            HFC = new float[stftRep.timeFreqData[0].Length];

            Parallel.For(0, stftRep.timeFreqData[0].Length, jj =>
            {
                for (int ii = 0; ii < stftRep.wSamp / 2; ii++)
                {
                    HFC[jj] = HFC[jj] + (float)Math.Pow((double)stftRep.timeFreqData[ii][jj] * ii, 2);
                }
            });

            float maxi = HFC.Max();

            for (int jj = 0; jj < stftRep.timeFreqData[0].Length; jj++)
            {
                HFC[jj] = (float)Math.Pow((HFC[jj] / maxi), 2);
            }

            for (int jj = 0; jj < stftRep.timeFreqData[0].Length; jj++)
            {
                if (starts > stops)
                {
                    if (HFC[jj] < 0.001)
                    {
                        noteStops.Add(jj * ((stftRep.wSamp - 1) / 2));
                        stops = stops + 1;
                    }
                }
                else if (starts - stops == 0)
                {
                    if (HFC[jj] > 0.001)
                    {
                        noteStarts.Add(jj * ((stftRep.wSamp - 1) / 2));
                        starts = starts + 1;
                    }
                }
            }

            if (starts > stops)
            {
                noteStops.Add(waveIn.data.Length);
            }


            // DETERMINES START AND FINISH TIME OF NOTES BASED ON ONSET DETECTION

            ///*

            for (int ii = 0; ii < noteStops.Count; ii++)
            {
                lengths.Add(noteStops[ii] - noteStarts[ii]);
            }

            for (int mm = 0; mm < lengths.Count; mm++)
            {
                int nearest = (int)Math.Pow(2, Math.Ceiling(Math.Log(lengths[mm], 2)));
                twiddles = new Complex[nearest];
                Parallel.For(0, nearest, ll =>
                {
                    double a     = 2 * pi * ll / (double)nearest;
                    twiddles[ll] = Complex.Pow(Complex.Exp(-i), (float)a);
                });

                compX = new Complex[nearest];
                for (int kk = 0; kk < nearest; kk++)
                {
                    if (kk < lengths[mm] && (noteStarts[mm] + kk) < waveIn.wave.Length)
                    {
                        compX[kk] = waveIn.wave[noteStarts[mm] + kk];
                    }
                    else
                    {
                        compX[kk] = Complex.Zero;
                    }
                }

                Y = new Complex[nearest];

                Y = fft(compX, nearest);

                absY = new double[nearest];

                double maximum = 0;
                int    maxInd  = 0;

                for (int jj = 0; jj < Y.Length; jj++)
                {
                    absY[jj] = Y[jj].Magnitude;
                    if (absY[jj] > maximum)
                    {
                        maximum = absY[jj];
                        maxInd  = jj;
                    }
                }

                for (int div = 6; div > 1; div--)
                {
                    if (maxInd > nearest / 2)
                    {
                        if (absY[(int)Math.Floor((double)(nearest - maxInd) / div)] / absY[(maxInd)] > 0.10)
                        {
                            maxInd = (nearest - maxInd) / div;
                        }
                    }
                    else
                    {
                        if (absY[(int)Math.Floor((double)maxInd / div)] / absY[(maxInd)] > 0.10)
                        {
                            maxInd = maxInd / div;
                        }
                    }
                }

                if (maxInd > nearest / 2)
                {
                    pitches.Add((nearest - maxInd) * waveIn.SampleRate / nearest);
                }
                else
                {
                    pitches.Add(maxInd * waveIn.SampleRate / nearest);
                }
            }

            musicNote[] noteArray;
            noteArray = new musicNote[noteStarts.Count()];

            for (int ii = 0; ii < noteStarts.Count(); ii++)
            {
                noteArray[ii] = new musicNote(pitches[ii], lengths[ii]);
            }

            int[] sheetPitchArray = new int[sheetmusic.Length];
            int[] notePitchArray  = new int[noteArray.Length];

            for (int ii = 0; ii < sheetmusic.Length; ii++)
            {
                sheetPitchArray[ii] = sheetmusic[ii].pitch % 12;
            }

            for (int jj = 0; jj < noteArray.Length; jj++)
            {
                notePitchArray[jj] = noteArray[jj].pitch % 12;
            }

            string[] alignedStrings = new string[2];

            alignedStrings = stringMatch(sheetPitchArray, notePitchArray);

            musicNote[] alignedStaffArray = new musicNote[alignedStrings[0].Length / 2];
            musicNote[] alignedNoteArray  = new musicNote[alignedStrings[1].Length / 2];
            int         staffCount        = 0;
            int         noteCount         = 0;

            for (int ii = 0; ii < alignedStrings[0].Length / 2; ii++)
            {
                if (alignedStrings[0][2 * ii] == ' ')
                {
                    alignedStaffArray[ii] = new musicNote(0, 0);
                }
                else
                {
                    alignedStaffArray[ii] = sheetmusic[staffCount];
                    staffCount++;
                }

                if (alignedStrings[1][2 * ii] == ' ')
                {
                    alignedNoteArray[ii] = new musicNote(0, 0);
                }
                else
                {
                    alignedNoteArray[ii] = noteArray[noteCount];
                    noteCount++;
                }
            }

            // STAFF TAB DISPLAY

            Ellipse[] notes;
            Line[]    stems;
            notes = new Ellipse[alignedNoteArray.Length];
            stems = new Line[alignedNoteArray.Length];
            SolidColorBrush myBrush = new SolidColorBrush(Colors.Green);

            RotateTransform rotate = new RotateTransform(45);

            for (int ii = 0; ii < alignedNoteArray.Length; ii++)
            {
                //noteArray[ii] = new musicNote(pitches[ii], lengths[ii]);
                //System.Console.Out.Write("Note " + (ii + 1) + ": \nDuration: " + noteArray[ii].duration / waveIn.SampleRate + " seconds \nPitch: " + Enum.GetName(typeof(musicNote.notePitch), (noteArray[ii].pitch) % 12) + " / " + pitches[ii] + "\nError: " + noteArray[ii].error * 100 + "%\n");
                notes[ii]                 = new Ellipse();
                notes[ii].Tag             = alignedNoteArray[ii];
                notes[ii].Height          = 20;
                notes[ii].Width           = 15;
                notes[ii].Margin          = new Thickness(ii * 30, 0, 0, 0);
                notes[ii].LayoutTransform = rotate;
                notes[ii].MouseEnter     += DisplayStats;
                notes[ii].MouseLeave     += ClearStats;
                stems[ii]                 = new Line();
                stems[ii].StrokeThickness = 1;
                stems[ii].X1              = ii * 30 + 20;
                stems[ii].X2              = ii * 30 + 20;
                stems[ii].Y1              = 250 - 10 * alignedNoteArray[ii].staffPos;
                stems[ii].Y2              = 250 - 10 * alignedNoteArray[ii].staffPos - 40;
                notes[ii].Fill            = ErrorBrush;
                notes[ii].StrokeThickness = 1;
                stems[ii].Stroke          = ErrorBrush;


                Canvas.SetTop(notes[ii], (240 - 10 * alignedNoteArray[ii].staffPos));
                if (alignedNoteArray[ii].flat)
                {
                    System.Windows.Controls.Label flat = new System.Windows.Controls.Label();
                    flat.Content    = "b";
                    flat.FontFamily = new FontFamily("Mistral");
                    flat.Margin     = new Thickness(ii * 30 + 15, 0, 0, 0);
                    Canvas.SetTop(flat, (240 - 10 * alignedNoteArray[ii].staffPos));
                    noteStaff.Children.Insert(ii, flat);
                }

                noteStaff.Children.Insert(ii, notes[ii]);
                noteStaff.Children.Insert(ii, stems[ii]);
            }

            Ellipse[]   sheetNotes;
            Rectangle[] timeRect;
            Line[]      sheetStems;
            sheetNotes = new Ellipse[alignedStaffArray.Length];
            sheetStems = new Line[alignedStaffArray.Length];
            timeRect   = new Rectangle[2 * alignedStaffArray.Length];

            Fline.Width     = alignedStaffArray.Length * 30;
            Dline.Width     = alignedStaffArray.Length * 30;
            Bline.Width     = alignedStaffArray.Length * 30;
            Gline.Width     = alignedStaffArray.Length * 30;
            Eline.Width     = alignedStaffArray.Length * 30;
            noteStaff.Width = alignedStaffArray.Length * 30;


            for (int ii = 0; ii < alignedStaffArray.Length; ii++)
            {
                sheetNotes[ii]                 = new Ellipse();
                sheetNotes[ii].Tag             = alignedStaffArray[ii];
                sheetNotes[ii].Height          = 20;
                sheetNotes[ii].Width           = 15;
                sheetNotes[ii].Margin          = new Thickness(ii * 30, 0, 0, 0);
                sheetNotes[ii].LayoutTransform = rotate;
                sheetNotes[ii].MouseEnter     += DisplayStats;
                sheetNotes[ii].MouseLeave     += ClearStats;
                sheetStems[ii]                 = new Line();
                sheetStems[ii].StrokeThickness = 1;
                sheetStems[ii].X1              = ii * 30 + 20;
                sheetStems[ii].X2              = ii * 30 + 20;
                sheetStems[ii].Y1              = 250 - 10 * alignedStaffArray[ii].staffPos;
                sheetStems[ii].Y2              = 250 - 10 * alignedStaffArray[ii].staffPos - 40;

                sheetNotes[ii].Fill            = sheetBrush;
                sheetNotes[ii].StrokeThickness = 1;
                sheetStems[ii].Stroke          = sheetBrush;


                Canvas.SetTop(sheetNotes[ii], (240 - 10 * alignedStaffArray[ii].staffPos));
                if (alignedStaffArray[ii].flat)
                {
                    System.Windows.Controls.Label flat = new System.Windows.Controls.Label();
                    flat.Content    = "b";
                    flat.FontFamily = new FontFamily("Mistral");
                    flat.Margin     = new Thickness(ii * 30 + 15, 0, 0, 0);
                    Canvas.SetTop(flat, (240 - 10 * alignedStaffArray[ii].staffPos));
                    noteStaff.Children.Insert(ii, flat);
                }
                noteStaff.Children.Insert(ii, sheetNotes[ii]);
                noteStaff.Children.Insert(ii, sheetStems[ii]);
            }

            // FOR TIMING ERROR RECTANGLES

            for (int ii = 0; ii < alignedStaffArray.Length; ii++)
            {
                timeRect[ii]        = new Rectangle();
                timeRect[ii].Fill   = sheetBrush;
                timeRect[ii].Height = 10 * alignedStaffArray[ii].duration * 4 * bpm / (60 * waveIn.SampleRate);
                timeRect[ii].Width  = 15;
                timeRect[ii].Margin = new Thickness(ii * 30 + 5, 0, 0, 0);

                Canvas.SetTop(timeRect[ii], 200);

                noteStaff.Children.Insert(ii, timeRect[ii]);
            }

            for (int ii = alignedStaffArray.Length; ii < alignedStaffArray.Length + alignedNoteArray.Length; ii++)
            {
                timeRect[ii]        = new Rectangle();
                timeRect[ii].Fill   = ErrorBrush;
                timeRect[ii].Height = 10 * alignedNoteArray[ii - alignedStaffArray.Length].duration * 4 * bpm / (60 * waveIn.SampleRate);
                timeRect[ii].Width  = 10;
                timeRect[ii].Margin = new Thickness((ii - alignedStaffArray.Length) * 30 + 5, 0, 0, 0);

                Canvas.SetTop(timeRect[ii], 200);
                noteStaff.Children.Insert(ii, timeRect[ii]);
            }
        }
        public PointD Power(PointD p)
        {
            Complex c = Complex.Pow(ToComplex(), p.ToComplex());

            return(new PointD(c));
        }
 public override Complex Compute(Complex z) => Complex.Pow(Arguments[0].Compute(z), Arguments[1].Compute(z));
 public Complex SysIncode() => Complex.Sin(Complex.Pow(3, 2)) + Complex.Cos(Complex.Pow(3, 2)) + Complex.Pow(3, 2) + Complex.Sin(Complex.Pow(3, 2));
Example #6
0
 public static Complex Pow(Complex num, double exp)
 {
     return(Complex.Pow(num, exp));
 }
Example #7
0
 /// <summary>
 /// Raises a number to a power. The function is made radially symmetrical. Also known as "pwr".
 /// </summary>
 /// <param name="left">The left argument.</param>
 /// <param name="right">The right argument.</param>
 /// <returns>The result.</returns>
 public static Complex Power(Complex left, Complex right) => Complex.Pow(left.Magnitude, right);
Example #8
0
 public static Complex Root(this Complex complex, Complex rootExponent) => Complex.Pow(complex, 1 / rootExponent);
Example #9
0
        static void Main(string[] args)
        {
            if (File.Exists(Path.Combine(Environment.CurrentDirectory, "ComplexNumber.dll")))
            {
                // Загрузка сборки
                Assembly asm = Assembly.Load("ComplexNumber");

                // Получаем тип Complex
                Type complexType = asm.GetType("ComplexNumber.Complex");

                Console.WriteLine("Не используем dynamic");
                Console.WriteLine("------------------------------------");

                // Динамическое создание объекта
                object x = Activator.CreateInstance(complexType, 2, 3);

                // Объект "y" создадим с помощью статического метода
                MethodInfo createComplexByModAndArgMethod = complexType.GetMethod("CreateComplexByModAndArg");
                object     y = createComplexByModAndArgMethod.Invoke(null, new object[] { 14, Math.PI / 4 });

                // Вывод в тригонометрическом виде
                PropertyInfo modProperty = complexType.GetProperty("Mod");
                PropertyInfo argProperty = complexType.GetProperty("Arg");

                Console.WriteLine($"x = {x}");
                Console.WriteLine($"y = {modProperty.GetValue(y)}(cos({argProperty.GetValue(y)}) + i*sin({argProperty.GetValue(y)})");

                Console.WriteLine("Вычислим z = ((x+y)^2)/27");

                MethodInfo operatorAdd      = complexType.GetMethod("op_Addition");
                MethodInfo operatorMultiply = complexType.GetMethod("op_Multiply");
                MethodInfo operatorDivision = complexType.GetMethod("op_Division");

                object z = operatorAdd.Invoke(null, new[] { x, y });
                z = operatorMultiply.Invoke(null, new[] { z, z });
                z = operatorDivision.Invoke(null, new[] { z, Activator.CreateInstance(complexType, 27, 0) });

                Console.WriteLine("Обычный вид:");
                Console.WriteLine($"z = {z}");
                Console.WriteLine("Тригонометрический вид:");
                Console.WriteLine($"z = {modProperty.GetValue(z)}(cos({argProperty.GetValue(z)}) + i*sin({argProperty.GetValue(z)})");


                Console.WriteLine("\nИспользуем dynamic");
                Console.WriteLine("------------------------------------");

                dynamic a = Activator.CreateInstance(complexType, 4, 1);
                dynamic b = createComplexByModAndArgMethod.Invoke(null, new object[] { 2, Math.PI / 3 });

                Console.WriteLine($"a = {a}");
                Console.WriteLine($"b = {b.Mod}(cos({b.Arg}) + i*sin({b.Arg})");

                Console.WriteLine("Вычислим z = ((a^2+b^2)^2)/3*b");

                dynamic int3 = Activator.CreateInstance(complexType, 3, 0);
                dynamic c    = ((a * a + b * b) * (a * a + b * b)) / (int3 * b);

                Console.WriteLine("Обычный вид:");
                Console.WriteLine($"c = {c}");
                Console.WriteLine("Тригонометрический вид:");
                Console.WriteLine($"c = {c.Mod}(cos({c.Arg}) + i*sin({c.Arg})");
            }
            else
            {
                Console.WriteLine("ComplexNumber.dll не найдена!");
                Console.WriteLine("Используем System.Numerics");

                Complex e = new Complex(1, 2);
                Complex f = Complex.FromPolarCoordinates(3, Math.PI / 8);

                Console.WriteLine($"e = {e}");
                Console.WriteLine($"f = {f.Magnitude}(cos({f.Phase}) + i*sin({f.Phase})");

                Console.WriteLine("Вычислим d = 34 + e^f");

                Complex d = 34 + Complex.Pow(e, f);

                Console.WriteLine("Обычный вид:");
                Console.WriteLine($"d = {d}");
                Console.WriteLine("Тригонометрический вид:");
                Console.WriteLine($"d = {d.Magnitude}(cos({d.Phase}) + i*sin({d.Phase})");
            }

            Console.WriteLine("\nНажмите Enter...");
            Console.Read();
        }
        // which root reached after how many steps
        protected void PartialRenderRootReached(object P)
        {
            object[] o      = (object[])P;
            int      offset = (int)o[0];
            int      lines  = (int)o[1];

            int[] dst = (int[])o[2];
            RenderResult.RenderStatus status_clbk = (RenderResult.RenderStatus)o[3];
            AutoResetEvent            completed   = (AutoResetEvent)o[4];

            int width      = (int)pars.GetValue("WIDTH");
            int heigth     = (int)pars.GetValue("HEIGHT");
            int iterations = (int)pars.GetValue("ITERATIONS") - 1;

            Int32[] Palette = (Int32[])pars.GetValue("PALETTE");

            double W = (double)pars.GetValue("W");
            double H = (double)pars.GetValue("H");
            double X = (double)pars.GetValue("X");
            double Y = (double)pars.GetValue("Y");

            int    iter = 0;
            int    idx  = 0;
            double xs   = (X - W / 2.0);
            double ys   = (Y - H / 2.0);
            double xd   = W / (double)width;
            double yd   = H / (double)heigth;
            double y1   = ys + yd * offset;
            double a    = 1.0;

            Complex Att1 = new Complex(1.25992, 0);
            Complex Att2 = new Complex(-0.629961, -1.09112);
            Complex Att3 = new Complex(-0.629961, 1.09112);

            for (int y = offset; y < offset + lines; y++)
            {
                idx = y * width;
                double x1 = xs;

                for (int x = 0; x < width; x++)
                {
                    iter = 0;

                    // newton fractal formula:
                    // zn+1 = zn - a* p(zn)/p'(zn)
                    // were p(z):
                    //              z^3-1   a: 1,0 ..... 0,5

                    Complex zn  = new Complex(x1, y1);
                    Complex pz  = new Complex(1, 0);
                    Complex pzd = new Complex(1, 0);

                    if (x1 == 0 && y1 == 0)
                    {
                        iter = 0;
                    }
                    else
                    {
                        while ((iter < iterations) && pz.GetModulusSquared() > 0.00000001)
                        {
                            pz  = Complex.Pow(zn, 3) - 2;
                            pzd = 3 * Complex.Pow(zn, 2);
                            zn  = (zn - a * pz / pzd);
                            iter++;
                        }
                    }

                    Att1 = Att1 - zn;
                    Att2 = Att2 - zn;
                    Att3 = Att3 - zn;
                    int palidx = iter;

                    if (Att1.GetModulusSquared() < 0.0001)
                    {
                        palidx = iter;
                    }
                    else if (Att2.GetModulusSquared() < 0.0001)
                    {
                        palidx = iter + 32;
                    }
                    else if (Att3.GetModulusSquared() < 0.0001)
                    {
                        palidx = iter + 64;
                    }

                    palidx     = palidx % Palette.Length;
                    dst[idx++] = Palette[palidx];
                    x1        += xd;
                }
                y1 += yd;
                lines_rendered++;
                if (lines_rendered % 40 == 0)
                {
                    status_clbk(100.0f * ((float)lines_rendered) / heigth);
                }
            }
            completed.Set();
        }
 // Two-argument functions
 private static Complex Pow(Complex[] args)
 {
     args.Check(2); return(Complex.Pow(args[0], args[1]));
 }
        // Integrands for Heston Greeks
        public double HestonGreeksProb(double phi, HParam param, OpSet settings, int Pnum, string Greek)
        {
            Complex i = new Complex(0.0, 1.0);                 // Imaginary unit
            Complex S = new Complex(settings.S, 0.0);          // Spot Price
            Complex K = new Complex(settings.K, 0.0);          // Strike Price
            Complex T = new Complex(settings.T, 0.0);          // Maturity in years
            Complex r = new Complex(settings.r, 0.0);          // Interest rate
            Complex q = new Complex(settings.q, 0.0);          // Dividend yield
            Complex rho = new Complex(param.rho, 0.0);         // Heston parameter: correlation
            Complex kappa = new Complex(param.kappa, 0.0);     // Heston parameter: mean reversion speed
            Complex theta = new Complex(param.theta, 0.0);     // Heston parameter: mean reversion speed
            Complex lambda = new Complex(param.lambda, 0.0);   // Heston parameter: price of volatility risk
            Complex sigma = new Complex(param.sigma, 0.0);     // Heston parameter: volatility of variance
            Complex v0 = new Complex(param.v0, 0.0);           // Heston parameter: initial variance
            Complex x = Complex.Log(S);
            Complex a = kappa * theta;
            int     Trap = settings.trap;
            Complex b, u, d, g, c, D, G, C, f = new Complex();

            // Parameters "u" and "b" are different for P1 and P2
            if (Pnum == 1)
            {
                u = 0.5;
                b = kappa + lambda - rho * sigma;
            }
            else
            {
                u = -0.5;
                b = kappa + lambda;
            }
            d = Complex.Sqrt(Complex.Pow(rho * sigma * i * phi - b, 2) - sigma * sigma * (2.0 * u * i * phi - phi * phi));
            g = (b - rho * sigma * i * phi + d) / (b - rho * sigma * i * phi - d);
            if (Trap == 1)
            {
                // "Little Heston Trap" formulation
                c = 1.0 / g;
                D = (b - rho * sigma * i * phi - d) / sigma / sigma * ((1.0 - Complex.Exp(-d * T)) / (1.0 - c * Complex.Exp(-d * T)));
                G = (1.0 - c * Complex.Exp(-d * T)) / (1 - c);
                C = (r - q) * i * phi * T + a / sigma / sigma * ((b - rho * sigma * i * phi - d) * T - 2.0 * Complex.Log(G));
            }
            else
            {
                // Original Heston formulation.
                G = (1.0 - g * Complex.Exp(d * T)) / (1.0 - g);
                C = (r - q) * i * phi * T + a / sigma / sigma * ((b - rho * sigma * i * phi + d) * T - 2.0 * Complex.Log(G));
                D = (b - rho * sigma * i * phi + d) / sigma / sigma * ((1.0 - Complex.Exp(d * T)) / (1.0 - g * Complex.Exp(d * T)));
            }

            // The characteristic function.
            f = Complex.Exp(C + D * v0 + i * phi * x);

            // Calculate the integrands for the various Greeks
            Complex y  = new Complex(0.0, 0.0);
            Complex dD = new Complex(0.0, 0.0);
            Complex dC = new Complex(0.0, 0.0);
            Complex df = new Complex(0.0, 0.0);

            if ((Greek == "Delta") | (Greek == "Rho"))
            {
                y = Complex.Exp(-i * phi * Complex.Log(K)) * f / i / phi;
            }
            else if (Greek == "Gamma")
            {
                // der(P1^2)/der(S^2)
                y = Complex.Exp(-i * phi * Complex.Log(K)) * f;
            }
            else if (Greek == "Theta")
            {
                // dP/dtau
                dD = d * Complex.Exp(d * T) * (b - rho * sigma * phi * i + d) * (g - 1.0) / sigma / sigma / Complex.Pow(1.0 - g * Complex.Exp(d * T), 2);
                dC = (r - q) * phi * i + kappa * theta / sigma / sigma * ((b - rho * sigma * phi * i + d) + 2.0 * g * d * Complex.Exp(d * T) / (1.0 - g * Complex.Exp(d * T)));
                df = f * (dC + dD * v0);
                y  = Complex.Exp(-i * phi * Complex.Log(K)) * df / i / phi;
            }
            else if (Greek == "Vega1")
            {
                // dP/dv0
                y = Complex.Exp(-i * phi * Complex.Log(K)) * f * D / i / phi;
            }
            else if (Greek == "Vega2")
            {
                if (Trap == 1)
                {
                    dC = (r - q) * i * phi * T + kappa / sigma / sigma * ((b - rho * sigma * i * phi - d) * T - 2.0 * Complex.Log(G));
                }
                else if (Trap == 0)
                {
                    dC = (r - q) * i * phi * T + kappa / sigma / sigma * ((b - rho * sigma * i * phi + d) * T - 2.0 * Complex.Log(G));
                }
                df = f * dC;
                y  = Complex.Exp(-i * phi * Complex.Log(K)) * df / i / phi;
            }
            else if (Greek == "Volga")
            {
                // dP2/dv02
                y = Complex.Exp(-i * phi * Complex.Log(K)) * f * D * D / i / phi;
            }
            return(y.Real);
        }
Example #13
0
 /// <summary>
 /// Returns the arcosecant of the specified complex number.
 /// </summary>
 /// <param name="number">Complex number.</param>
 /// <returns>Arcosecant of complex number.</returns>
 public static Complex Acsc(Complex number)
 {
     return(-Complex.ImaginaryOne * Complex.Log(Complex.Sqrt(1 - 1 / Complex.Pow(number, 2)) + Complex.ImaginaryOne / number));
 }
Example #14
0
 /// <summary>
 /// Returns the arcosecant of the specified complex number.
 /// </summary>
 /// <param name="number">Complex number.</param>
 /// <returns>Arcosecant of complex number.</returns>
 public static Complex Asec(Complex number)
 {
     return(Complex.ImaginaryOne * Complex.Log(Complex.Sqrt(1 / Complex.Pow(number, 2) - 1) + 1 / number));
 }
        private Complex Bandalog(Complex s)  // The analog Bandstop tf
        {
            Complex BA  = (0.357663 * Complex.Pow(s, 6) + 3.322227 * Complex.Pow(s, 4) + 10.241961 * Complex.Pow(s, 2) + 10.483156) / (0.035766 * Complex.Pow(s, 6) + 0.374406 * Complex.Pow(s, 5) + 0.464755 * Complex.Pow(s, 4) + 2.371567 * Complex.Pow(s, 3) + 1.432948 * Complex.Pow(s, 2) + 3.559225 * (s) + 1.048316);
            Complex BAl = (0.357696 * Complex.Pow(s, 6) + 3.322 * Complex.Pow(s, 4) + 10.242 * Complex.Pow(s, 2) + 10.4832) / (0.0358 * Complex.Pow(s, 6) + 0.376 * Complex.Pow(s, 5) + 0.4648 * Complex.Pow(s, 4) + 2.3716 * Complex.Pow(s, 3) + 1.4329 * Complex.Pow(s, 2) + 3.5592 * (s) + 1.0483);
            Complex BAj = ((0.600513 * Complex.Pow(s, 6) + 0.72942024 * Complex.Pow(s, 5) + 2.072374 * Complex.Pow(s, 4) + 1.4887096 * Complex.Pow(s, 3) + 2.072374 * Complex.Pow(s, 2) + 0.72942024 * (s) + 0.600513)) / ((1 * Complex.Pow(s, 6) + 1.0213728 * Complex.Pow(s, 5) + 2.3609725 * Complex.Pow(s, 4) + 1.445696 * Complex.Pow(s, 3) + 1.67829284 * Complex.Pow(s, 2) + 0.48048121 * (s) + 0.3065088));
            Complex BA1 = ((1 * Complex.Pow(s, 6) + 2420000000 * Complex.Pow(s, 4) + 0.0109 * Complex.Pow(s, 3) + 1771000000000000000 * Complex.Pow(s, 2) + 505200 * (s) + 392100000000000000000000000.0)) / ((1 * Complex.Pow(s, 6) + 80670 * Complex.Pow(s, 5) + 4275000000 * Complex.Pow(s, 4) + 195000000000000 * Complex.Pow(s, 3) + 3129000000000000000 * Complex.Pow(s, 2) + 43220000000000000000000.0 * (s) + 392100000000000000000000000.0));
            Complex BAt = ((1 * Complex.Pow(s, 6) + 2420287562 * Complex.Pow(s, 4) + 0.0108962853 * Complex.Pow(s, 3) + 1771435291390217728 * Complex.Pow(s, 2) + 5051847 * (s) + 392080254164488158493802496.0)) / ((1 * Complex.Pow(s, 6) + 80672.7 * Complex.Pow(s, 5) + 4274809525 * Complex.Pow(s, 4) + 195019504507183 * Complex.Pow(s, 3) + 3128780470436911616 * Complex.Pow(s, 2) + 43215876438098196824064.0 * (s) + 392080254164488983127523328.0));

            return(BA1);
        }
Example #16
0
 public static Complex Pow(Complex a, Complex b)
 => Complex.Pow(a, b);
        private Complex Bandigital(Complex z)  // The digital bandstop tf
        {
            Complex BD1  = (3.517132 * Complex.Pow(z, 6) + 10.749901 * Complex.Pow(z, 5) + 21.48009 * Complex.Pow(z, 4) + 25.195791 * Complex.Pow(z, 3) + 21.480095 * Complex.Pow(z, 2) + 10.749902 * Complex.Pow(z, 1) + 3.51712) / (1.338395 * Complex.Pow(z, 6) + 2.990529 * Complex.Pow(z, 5) + 3.879146 * Complex.Pow(z, 4) + 2.360351 * Complex.Pow(z, 3) + 0.260859 * Complex.Pow(z, 2) - 0.681318 * Complex.Pow(z, 1) - 0.478954);
            Complex BDii = (0.2985 * Complex.Pow(z, 6) + 0.3485 * Complex.Pow(z, 5) + 0.9526 * Complex.Pow(z, 4) + 0.6826 * Complex.Pow(z, 3) + 0.9526 * Complex.Pow(z, 2) + 0.3485 * Complex.Pow(z, 1) + 0.2985) / (1 * Complex.Pow(z, 6) + 0.7484 * Complex.Pow(z, 5) + 0.877 * Complex.Pow(z, 4) + 0.5449 * Complex.Pow(z, 3) + 0.6905 * Complex.Pow(z, 2) + 0.08634 * Complex.Pow(z, 1) - 0.06526);
            Complex BDl  = (0.2985 + 0.3485 * Complex.Pow(z, -1) + 0.9526 * Complex.Pow(z, -2) + 0.6826 * Complex.Pow(z, -3) + 0.9526 * Complex.Pow(z, -4) + 0.3485 * Complex.Pow(z, -5) + 0.2985 * Complex.Pow(z, -6)) / (1 + 0.7484 * Complex.Pow(z, -1) + 0.877 * Complex.Pow(z, -2) + 0.5449 * Complex.Pow(z, -3) + 0.6905 * Complex.Pow(z, -4) + 0.08634 * Complex.Pow(z, -5) - 0.06526 * Complex.Pow(z, -6));
            Complex BDi  = (3.517132 + 10.749901 * Complex.Pow(z, -1) + 21.48009 * Complex.Pow(z, -2) + 25.195791 * Complex.Pow(z, -3) + 21.480095 * Complex.Pow(z, -4) + 10.749902 * Complex.Pow(z, -5) + 3.51712 * Complex.Pow(z, -6)) / (1.338395 + 2.990529 * Complex.Pow(z, -1) + 3.879146 * Complex.Pow(z, -2) + 2.360351 * Complex.Pow(z, -3) + 0.260859 * Complex.Pow(z, -4) - 0.681318 * Complex.Pow(z, -5) - 0.478954 * Complex.Pow(z, -6));

            return(BDl);
        }
        public CacheCompiledFuncTest()
        {
            notCompiled = MathS.Sin(MathS.Sqr(x)) + MathS.Cos(MathS.Sqr(x)) + MathS.Sqr(x) + MathS.Sin(MathS.Sqr(x));
            complexFunc = notCompiled.Compile(x);

            Expression <Func <Complex, Complex> > linqExpr = x => Complex.Sin(Complex.Pow(x, 2)) + Complex.Cos(Complex.Pow(x, 2)) + Complex.Pow(x, 2) + Complex.Sin(Complex.Pow(x, 2));

            linqComp = linqExpr.Compile();
        }
Example #19
0
        private void calculate()
        {
            List <double> e = new List <double>();

            for (int i = 0; i < vectorLength; i++)
            {
                // abs(s11*conj(s21)+s12*conj(s22))/(sqrt((1-abs(s11)^2-abs(s12)^2)*(1-abs(s21)^2-abs(s22)^2)))

                Complex a = Complex.Abs(Complex.Add(Complex.Multiply(s11[i], Complex.Conjugate(s21[i])), Complex.Multiply(s12[i], Complex.Conjugate(s22[i]))));
                //A works
                Complex b = Complex.Subtract(Complex.Subtract(1, Complex.Pow(Complex.Abs(s11[i]), 2.00)), Complex.Pow(Complex.Abs(s12[i]), 2.00));
                Complex c = Complex.Subtract(Complex.Subtract(1, Complex.Pow(Complex.Abs(s21[i]), 2.00)), Complex.Pow(Complex.Abs(s22[i]), 2.00));
                Complex d = Complex.Divide(a, Complex.Sqrt(Complex.Multiply(b, c)));

                // the simplified code for an reciprocal device works:

                //abs(s11*conj(s21) + s21*conj(s11)) / (1 - abs(s11)^2 - abs(s21)^2)
                //    Complex a = Complex.Abs(Complex.Add(Complex.Multiply(s11[i], Complex.Conjugate(s21[i])),Complex.Multiply(s21[i], Complex.Conjugate(s11[i]))));
                //   Complex b = Complex.Subtract(Complex.Subtract(1.0, Complex.Pow(Complex.Abs(s11[i]),2.0)), Complex.Pow(Complex.Abs(s21[i]),2.0));
                //   Complex d = Complex.Divide(a, b);

                double f = (double)(d.Magnitude);


                e.Add(f);
            }

            dataArray = e.ToArray();

            //abs(s11*conj(s21)+s12*conj(s22))/(sqrt((1-abs(s11)^2-abs(s12)^2)*(1-abs(s21)^2-abs(s22)^2)))

            plotdata();

            label15.Text = Convert.ToString(string.Format("{0:0.00}", (dataArray.Max() * 100) - 100));
            label16.Text = Convert.ToString(string.Format("{0:0.00}", (100 - (dataArray.Min() * 100))));
        }
Example #20
0
 public static Complex Root(Complex num, double basen)
 {
     return(Complex.Pow(num, 1 / basen));
 }
Example #21
0
        static Complex Filter(double hz, double FFTSize)
        {
            var z = Complex.Exp(new Complex(0, 2 * Math.PI / FFTSize * hz));
            var b = 0.669152709119095 + 1.33830541823819 * Complex.Pow(z, -1) + 0.669152709119095 * Complex.Pow(z, -2);
            var a = 1 + 1.40381719814556 * Complex.Pow(z, -1) + 0.599389555365550 * Complex.Pow(z, -2);

            return(b / a);
        }
        /// <summary>
        /// Calls the compiled function (synonim to Call)
        /// </summary>
        /// <param name="values">
        /// List arguments in the same order in which you compiled the function
        /// </param>
        /// <returns></returns>
        // TODO: Optimization
        public Complex Substitute(params Complex[] values)
        {
            if (values.Length != varCount)
            {
                throw new SysException("Wrong amount of parameters");
            }
            Instruction instruction;

            for (int i = 0; i < instructions.Count; i++)
            {
                instruction = instructions[i];
                switch (instruction.Type)
                {
                case Instruction.InstructionType.PUSHVAR:
                    stack.Push(values[instruction.VarNumber]);
                    break;

                case Instruction.InstructionType.PUSHCONST:
                    stack.Push(instruction.Value);
                    break;

                case Instruction.InstructionType.CALL:
                    switch (instruction.FuncNumber)
                    {
                    case 0:
                        stack.Push(stack.Pop() + stack.Pop());
                        break;

                    case 1:
                        stack.Push(stack.Pop() - stack.Pop());
                        break;

                    case 2:
                        stack.Push(stack.Pop() * stack.Pop());
                        break;

                    case 3:
                        stack.Push(stack.Pop() / stack.Pop());
                        break;

                    case 4:
                        stack.Push(Complex.Pow(stack.Pop(), stack.Pop()));
                        break;

                    case 5:
                        stack.Push(Complex.Sin(stack.Pop()));
                        break;

                    case 6:
                        stack.Push(Complex.Cos(stack.Pop()));
                        break;

                    case 7:
                        stack.Push(Complex.Tan(stack.Pop()));
                        break;

                    case 8:
                        stack.Push(1 / Complex.Tan(stack.Pop()));
                        break;

                    case 9:
                        stack.Push(Complex.Log(stack.Pop(), stack.Pop().Real));
                        break;

                    case 10:
                        stack.Push(Complex.Asin(stack.Pop()));
                        break;

                    case 11:
                        stack.Push(Complex.Acos(stack.Pop()));
                        break;

                    case 12:
                        stack.Push(Complex.Atan(stack.Pop()));
                        break;

                    case 13:
                        stack.Push(Complex.Atan(1 / stack.Pop()));
                        break;
                    }
                    break;

                case Instruction.InstructionType.PULLCACHE:
                    stack.Push(Cache[instruction.CacheNumber]);
                    break;

                default:
                    Cache[instruction.CacheNumber] = stack.Peek();
                    break;
                }
            }

            return(stack.Pop());
        }
Example #23
0
        /// <summary>
        /// 強制振動を計算します(オリジナルメソッド)
        /// </summary>
        private void TayunCalcForcedAcc()
        {
            // 外周をのぞく点において計算する
            for (int x = 1; x <= this.DivisionX - 2; x++)
            {
                for (int y = 1; y <= this.DivisionY - 2; y++)
                {
                    var node = this.Items[x, y];

                    // 自分で振動する節点は除外
                    //if (node.Amplitude.W != 0 || node.Amplitude.H != 0) continue;

                    // 隣り合う節点
                    var leftNode  = this.Items[x - 1, y];
                    var rightNode = this.Items[x + 1, y];
                    var upperNode = this.Items[x, y - 1];
                    var lowerNode = this.Items[x, y + 1];

                    // 強制振動
                    var omega = node.Omega;
                    var roe   = node.Roe;
                    var t     = 0; // this.time;

                    var     omegaZero = Double.NaN;
                    Complex ft        = default(Complex);

                    // 加速度
                    var acc = node.Acceleration;
                    if (!node.ConstraintX)
                    {
                        var force = (rightNode.Position.X + leftNode.Position.X) / 2 - node.Position.X;
                        force += (upperNode.Position.X + lowerNode.Position.X) / 2 - node.Position.X;
                        force *= -1;
                        if (force != 0)
                        {
                            var forceZero = force; // / Math.Cos(omega * t); // 実質 1 なので計算不要
                            omegaZero = Math.Sqrt((rightNode.Spring + leftNode.Spring + upperNode.Spring + lowerNode.Spring) /
                                                  (rightNode.Mass + leftNode.Mass + upperNode.Mass + lowerNode.Mass) / 4 / 4);
                            ft = (omegaZero * omegaZero - omega * omega + new Complex(0, roe * omega)) * Complex.Pow(Math.E, new Complex(0, omega * t));

                            var fx = forceZero / ft;
                            acc.X += fx.Real;
                        }
                    }
                    if (!node.ConstraintY)
                    {
                        var force = (rightNode.Position.Y + leftNode.Position.Y) / 2 - node.Position.Y;
                        force += (upperNode.Position.Y + lowerNode.Position.Y) / 2 - node.Position.Y;
                        force *= -1;
                        if (force != 0)
                        {
                            var forceZero = force; // / Math.Cos(omega * t); // 実質 1 なので計算不要
                            if (Double.IsNaN(omegaZero))
                            {
                                omegaZero = Math.Sqrt((rightNode.Spring + leftNode.Spring + upperNode.Spring + lowerNode.Spring) /
                                                      (rightNode.Mass + leftNode.Mass + upperNode.Mass + lowerNode.Mass) / 4 / 4);
                                ft = (omegaZero * omegaZero - omega * omega + new Complex(0, roe * omega)) * Complex.Pow(Math.E, new Complex(0, omega * t));
                            }

                            var fy = forceZero / ft;
                            acc.Y += fy.Real;
                        }
                    }
                    node.Acceleration = acc;
                }
            }
        }
        public PointD Power(double p)
        {
            Complex c = Complex.Pow(ToComplex(), new Complex(p, 0));

            return(new PointD(c));
        }
Example #25
0
        // Returns the damped Carr-Madan integrand for OTM options
        public double CarrMadanDampedIntegrandOTM(double v, double kappa, double theta, double lambda, double rho, double sigma,
                                                  double T, double K, double S, double r, double v0, int Trap, double alpha)
        {
            // Calculate z(v-ia)
            Complex i   = new Complex(0.0, 1.0);
            Complex u   = v - i * alpha;
            Complex phi = HestonCF(u - i, kappa, theta, lambda, rho, sigma, T, K, S, r, v0, Trap);
            Complex z1  = Math.Exp(-r * T) * (Complex.Pow(S, (i * u + 1.0)) / (1.0 + i * u) - Math.Exp(r * T) * Complex.Pow(S, (i * u + 1.0)) / (i * u) - phi / (u * u - i * u));

            // Calculate z(v+ia)
            u   = v + i * alpha;
            phi = HestonCF(u - i, kappa, theta, lambda, rho, sigma, T, K, S, r, v0, Trap);
            Complex z2 = Math.Exp(-r * T) * (Complex.Pow(S, (i * u + 1.0)) / (1.0 + i * u) - Math.Exp(r * T) * Complex.Pow(S, (i * u + 1.0)) / (i * u) - phi / (u * u - i * u));

            // Calculate the Fourier transform of y
            Complex y = Complex.Exp(-i * u * Math.Log(K)) * (z1 - z2) / 2.0;

            // Return the real part only
            return(y.Real);
        }
Example #26
0
        /// <summary>
        ///     Deblur bitmap with the Fastest Fourier Transform
        /// </summary>
        private Array Deblur(Array data)
        {
            var handle = GCHandle.Alloc(data, GCHandleType.Pinned);

            var f       = Complex.One;
            var length  = data.Length;
            var n0      = data.GetLength(0);
            var n1      = data.GetLength(1);
            var n2      = data.GetLength(2);
            var doubles = new double[length];

            Marshal.Copy(handle.AddrOfPinnedObject(), doubles, 0, doubles.Length);

            double average;
            double delta;

            AverageAndDelta(out average, out delta, doubles, _keepOption);

            var complex = doubles.Select(x => new Complex(x, 0)).ToArray();

            Fourier(n0, n1, n2, complex, FourierDirection.Forward);

            var array = complex.Select(x => x * Complex.Conjugate(x)).ToArray();

            array = array.Select(x => x / array[0]).ToArray();
            array = array.Select(Complex.Sqrt).ToArray();

            Debug.Assert(array.All(x => x.Magnitude <= 1));

            Fourier(n0, n1, n2, array, FourierDirection.Backward);
            doubles = array.Select(x => x.Magnitude / length).ToArray();

            var filterSize = _filterSize;

            switch (_filterMode)
            {
            case FilterMode.FilterSize:
                break;

            case FilterMode.FilterStep:
                var filterStep = _filterStep;
                filterSize = new Size(MulDiv(n1, filterStep, filterStep + 1),
                                      MulDiv(n0, filterStep, filterStep + 1));
                break;

            default:
                throw new NotImplementedException();
            }
            BlindInner(n0, n1, doubles, filterSize, n2);

            array = doubles.Select(x => new Complex(x, 0)).ToArray();
            Fourier(n0, n1, n2, array, FourierDirection.Forward);

            array = array.Select(x => Complex.Pow(x * Complex.Conjugate(x), _filterPower / 2)).ToArray();
            array = array.Select(x => f + x).ToArray();
            array = array.Select(Complex.Reciprocal).ToArray();

            var level = complex[0];

            complex    = complex.Select(x => f + x).ToArray();
            complex    = complex.Zip(array, (x, y) => (x * y)).ToArray();
            complex[0] = level;

            Fourier(n0, n1, n2, complex, FourierDirection.Backward);
            doubles = complex.Select(x => x.Magnitude / length).ToArray();

            double average2;
            double delta2;

            AverageAndDelta(out average2, out delta2, doubles, _keepOption);

            // a*average2 + b == average
            // a*delta2 == delta
            var a = (_keepOption == KeepOption.AverageAndDelta) ? (delta / delta2) : (average / average2);
            var b = (_keepOption == KeepOption.AverageAndDelta) ? (average - a * average2) : 0;

            Debug.Assert(Math.Abs(a * average2 + b - average) < 0.1);
            doubles = doubles.Select(x => Math.Round(a * x + b)).ToArray();


            Marshal.Copy(doubles, 0, handle.AddrOfPinnedObject(), doubles.Length);
            handle.Free();

            return(data);
        }
 //функція f(z)
 private Complex f(Complex z)
 {
     return(Complex.Pow(z, Power) + Constant);
 }
 public Complex QuarticFunction(double a, double b, double c, double d, double e, Complex root)
 {
     return(a * Complex.Pow(root, 4) + b * Complex.Pow(root, 3) + c * Complex.Pow(root, 2) + d * root + e);
 }
 //похідна функції f(z)
 private Complex df(Complex z)
 {
     return(Power * Complex.Pow(z, Power - 1));
 }
Example #30
0
 public static ComplexValue Power(ComplexValue x, ComplexValue exponent)
 {
     return(new ComplexValue(Complex.Pow(x.value, exponent.value)));
 }
        private void Create_part_of_fractal(_2DFractalHelper fractal_helper,AbcissOrdinateHandler p_aoh)
        {
            ulong iterations;
            int percent_length=fractal_helper.PercentLength, current_percent=percent_length,trio_height;
            ulong[][] iter_matrix = fractal_helper.CommonMatrix;
            double[] abciss_points = fractal_helper.AbcissRealValues, ordinate_points = fractal_helper.OrdinateRealValues;
            double abciss_point,ratio,lratio;
            double[][] Ratio_matrix = fractal_helper.GetRatioMatrix();
            double[][][] trio_matrix = (double[][][])fractal_helper.GetUnique(typeof(double[][][]));
            double  v1, v2, v3, v1total, v2total, v3total, v1min, v1max, v2min, v2max, v3min, v3max;
            Complex value=new Complex(), z=new Complex();
            trio_height=Ratio_matrix[0].Length;
            for(;p_aoh.abciss<p_aoh.end_of_abciss;p_aoh.abciss++)
            {
                abciss_point = abciss_points[p_aoh.abciss];
                trio_matrix[p_aoh.abciss] = new double[trio_height][];
                for(;p_aoh.ordinate<p_aoh.end_of_ordinate;p_aoh.ordinate++)
                {
                    z.Real=abciss_point;
                    z.Imagine = ordinate_points[p_aoh.ordinate];
                    //z0 = z.getclone();
                    v1 = v2 = v3 = v1total = v1max = v1min = v2total = v2max = v2min = v3total = v3max = v3min = 0D;
                    ratio = (z.Real * z.Real + z.Imagine * z.Imagine);
                    lratio = 0;
                    for(iterations=0;iterations<f_iterations_count&&ratio<400D;iterations++)
                    {
                        lratio = ratio;
                        z = Complex.SSin(z);
                        z.Real += _P.Real;
                        z.Imagine += _P.Imagine;
                        value = Complex.Sec(z);
                        ratio = z.Real*z.Real+z.Imagine*z.Imagine;
                        if (double.IsNaN(value.Real) || double.IsNaN(value.Imagine)) {
                            v1 = v2 = v3 = 0;
                        }
                        else{v1 = value.abs;
                        v2 = value.sqr().abs;
                        v3 = value.Pow(3).abs;
                        v1total += v1;
                        v2total += v2;
                        v3total += v3;
                        if (v1 < v1min) v1min = v1;
                        else if (v1 > v1max) v1max = v1;
                        if (v2 < v2min) v2min = v2;
                        else if (v2 > v2max) v2max = v2;
                        if (v3 < v3min) v3min = v3;
                        else if (v3 > v3max) v3max = v3;}
                    }
                    //$r = (($v1total / $count) - $v1min) / ($v1max - $v1min);
                    Ratio_matrix[p_aoh.abciss][p_aoh.ordinate] = lratio;
                    if (iterations > 0)
                    {
                        trio_matrix[p_aoh.abciss][p_aoh.ordinate] = new double[] {((v1total/(double)iterations)-v1min)/(v1max-v1min),
                        ((v2total/(double)iterations)-v2min)/(v2max-v2min),
                        ((v3total/(double)iterations)-v3min)/(v3max-v3min)};
                    }
                    else trio_matrix[p_aoh.abciss][p_aoh.ordinate] = new double[3];
                    iter_matrix[p_aoh.abciss][p_aoh.ordinate] = iterations;
                }
                p_aoh.ordinate = 0;
                if((--current_percent)==0)
                {
                    current_percent = percent_length;
                    f_new_percent_in_parallel_activate();
                }

            }
        }