/// <summary> /// Создать источник по основным характеристикам /// </summary> /// <param name="center"></param> /// <param name="normals"></param> /// <param name="filter"></param> /// <param name="fmas"></param> /// <param name="type"></param> /// <param name="radius"></param> public Source(Point center, Normal2D[] normals, Func <Point, bool> filter, Complex[] fmas, Type type, double radius) { Center = center.dup; Norms = normals; //new Normal2D[normals.Length]; //for (int i = 0; i < normals.Length; i++) // Norms[i] = new Normal2D(normals[i]); Filter = new Func <Point, bool>(filter); Fmas = fmas.Dup(); this.radius = radius; MeType = type; }
private void button1_Click(object sender, EventArgs e) { Read(); double res = 0; if (radioButton21.Checked) { MonteKarloEnum KK = MonteKarloEnum.Usual; if (radioButton23.Checked) { KK = MonteKarloEnum.Geo; } МатКлассы.Point p = new МатКлассы.Point(a, b); MultiFunc F = (double[] t) => f(t[0]); h_Count = count; n = count; EPS = Double.NaN; res = MonteKarlo(F, KK, p); textBox7.Text = Math.Abs(res - DefIntegral(f, a, b, C, Criterion.StepCount, count, eps, seq)).ToString(); h_Count = count; n = count; EPS = Double.NaN; //return; } else { Criterion K = Criterion.StepCount; if (radioButton19.Checked) { K = Criterion.Accuracy; } if (radioButton20.Checked) { K = Criterion.SegmentCount; } if ((int)C < 3) { res = DefIntegral(f, a, b, C, K, count, eps, seq); } else { res = DefIntegral(f, a, b, C, K, nn, eps, seq); } } textBox6.Text = res.ToString(); textBox3.Text = h_Count.ToString(); textBox4.Text = EPS.ToString(); }
/// <summary> /// Двойной интеграл /// </summary> /// <param name="f"></param> /// <param name="Curve"></param> /// <returns></returns> public static double Integral(Functional f, int Curve) { Func <double, double, double> func = (double x, double y) => { Point t = new Point(x, y); if (KursMethods.filters[Curve](t)) { return(f(t)); } return(0); }; double a, b, c, d; switch (Curve) { case 0: a = -KursMethods.MAX_RADIUS; b = KursMethods.MAX_RADIUS; c = a; d = b; break; case 1: a = 0; b = KursMethods.MIN_RADIUS; c = a; d = b * Math.Sqrt(3) / 2; break; case 3: a = 0; b = KursMethods.MIN_RADIUS; c = a; d = b; break; default: a = 0; b = KursMethods.MIN_RADIUS; c = a; d = b * Math.Sqrt(3) / 2; break; } return(MathNet.Numerics.Integration.GaussLegendreRule.Integrate(func, a, b, c, d, n)); }
public static double g8(Point point) { double dx = MIN_RADIUS / 2; double dy = MIN_RADIUS / 2 * Math.Sqrt(3); double argument; //C++ TO C# CONVERTER TODO TASK: The following line was determined to contain a copy constructor call - this should be verified and a copy constructor should be created: //ORIGINAL LINE: Point d = point; Point d = new Point(point); //d.x=-0.25;d.y=-0.25; d.x -= dx; d.y -= dy; //сдвиг к началу координат if (d.x == 0) { argument = pi / 2 * Math.Sign((sbyte)d.y); } else { if (d.y == 0) { argument = pi * Math.Sign((sbyte)-1 + Math.Sign((sbyte)d.x)); } else { argument = Math.Atan(d.y / d.x) + Math.Sign((sbyte)Math.Abs(d.x) - d.x) * Math.Sign((sbyte)d.y) * pi; } } //return argument; //cout+d.x+" "+d.y+" аргумент в доли: "+argument/pi+endl; if ((-pi <= argument) && (argument < -2 * pi / 3)) { return(-1.0 / 2); } if ((-2 * pi / 3 <= argument) && (argument <= -pi / 3)) { return(0); //return 1; //единицы будут } if ((-pi / 3 < argument) && (argument <= pi / 2)) { return(1.0 / 2); //return 1; //уже не будут } /*if ((pi / 2 < argument) && (argument <= pi))*/ return(-1.0 / 2); }
public void DrawCurves() { SequenceFunc t = (double x, int kk) => Math.Log(0.01 + (x + 1 - 0.1 * kk).Sqr());//1.0/(1.0+kk*x*x);//FuncMethods.Monoms; RealFunc[] f = new RealFunc[] { (double x) => Math.Exp(x / (x.Abs() + 1)), (double x) => Math.Sin(x + 2) * Math.Cos(2 * x), (double x) => x.Abs() * Math.Exp(Math.Cos(x)), (double x) => Math.Log(1 + x.Abs()) * Math.Sinh(x / 2), (double x) => Math.Sin(x) - 8.0 / (2 * x + 6), (double x) => x.Abs() + Math.Log(0.01 + x * x) }; Point[] b = new Point[] { new Point(0, 5), new Point(-4, 4), new Point(-2, 4), new Point(-2, 2), new Point(-1, 1), new Point(-1, 1) }; int k = 64; int[] mas = new int[k]; for (int i = 0; i < k; i++) { mas[i] = i + 1; } Parallel.For(0, f.Length, (int i) => { var c = FuncMethods.UltraVsNormal(f[i], t, SequenceFuncKind.Other, k, b[i].x, b[i].y); StreamWriter fs = new StreamWriter($"Monoms {i + 1}.txt"); fs.WriteLine($"count normal ultra"); for (int j = 0; j < k; j++) { fs.WriteLine($"{mas[j]} {c.Item1[j]} {c.Item2[j]}"); } fs.Close(); }); //k = 75; //mas = new int[k]; //for (int i = 0; i < k; i++) // mas[i] = i + 1; //Parallel.For(0, f.Length, (int i) => //{ // t = FuncMethods.TrigSystem(b[i].x, b[i].y); // var c = FuncMethods.UltraVsNormal(f[i], t, SequenceFuncKind.Orthogonal, k, b[i].x, b[i].y); // StreamWriter fs = new StreamWriter($"Trig {i + 1}.txt"); // fs.WriteLine($"count normal ultra"); // for (int j = 0; j < k; j++) // fs.WriteLine($"{mas[j]} {c.Item1[j]} {c.Item2[j]}"); // fs.Close(); //}); }
private void MakeArrow(Point beg, Point Normal, Color col, DCircle circle) { chart1.Series.Add(counter++.ToString()); chart1.Series.Last().IsVisibleInLegend = false; chart1.Series.Last().ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.FastLine; chart1.Series.Last().BorderWidth = 2; chart1.Series.Last().Color = col; double r = Normal.Abs, s = r / 4; double cor = Math.Acos((Normal.x) / r) * Math.Sign(Normal.y); Point p1 = new Point(s * Math.Cos(-Math.PI - corner), s * Math.Sin(-Math.PI - corner)).Turn(Point.Zero, cor); Point p2 = new Point(s * Math.Cos(-Math.PI + corner), s * Math.Sin(-Math.PI + corner)).Turn(Point.Zero, cor); chart1.Series.Last().Points.AddXY(beg.x, beg.y); chart1.Series.Last().Points.AddXY(beg.x + Normal.x, beg.y + Normal.y); chart1.Series.Last().Points.AddXY(beg.x + Normal.x + p1.x, beg.y + Normal.y + p1.y); chart1.Series.Last().Points.AddXY(beg.x + Normal.x, beg.y + Normal.y); chart1.Series.Last().Points.AddXY(beg.x + Normal.x + p2.x, beg.y + Normal.y + p2.y); }
public void Test() { Read(); double res = 0; Criterion K = Criterion.StepCount; if (radioButton19.Checked) { K = Criterion.Accuracy; } if (radioButton20.Checked) { K = Criterion.SegmentCount; } for (C = 0; (int)C <= 2; C++) { res = DefIntegral(f, a, b, C, K, count, eps, seq); Program.PER.listView1.Items[(int)C].SubItems[1].Text = res.ToString(); } C += 2; res = DefIntegral(f, a, b, (Method)3, K, nn, eps, seq); Program.PER.listView1.Items[(int)C].SubItems[1].Text = res.ToString(); C++; res = DefIntegral(f, a, b, (Method)4, K, nn, eps, seq); Program.PER.listView1.Items[(int)C].SubItems[1].Text = res.ToString(); C++; res = DefIntegral(f, a, b, (Method)5, K, nn, eps, seq); Program.PER.listView1.Items[(int)C].SubItems[1].Text = res.ToString(); for (MonteKarloEnum KK = 0; (int)KK < 2; KK++) { МатКлассы.Point p = new МатКлассы.Point(a, b); MultiFunc F = (double[] t) => f(t[0]); h_Count = count; n = count; EPS = Double.NaN; res = MonteKarlo(F, KK, p); Program.PER.listView1.Items[(int)KK + 3].SubItems[1].Text = res.ToString(); } }
public MostSimpleGrafic(Func <double, double> f, Point[] mas, string name, bool parallel = true) { InitializeComponent(); chart1.Series[0].IsVisibleInLegend = false; chart1.Series.Add(name); chart1.Series[1].BorderWidth = 3; chart1.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; Point[] p = new Point[mas.Length]; Parallel.For(0, p.Length, (int i) => p[i] = new Point(mas[i].x, f(mas[i].x))); for (int i = 0; i < p.Length; i++) { chart1.Series[0].Points.AddXY(mas[i].x, mas[i].y); chart1.Series[1].Points.AddXY(p[i].x, p[i].y); } Библиотека_графики.ForChart.SetToolTips(ref chart1); }
public void DrawCurves2() { SequenceFunc t = (double x, int k) => Math.Exp(k * x);//FuncMethods.Monoms; int[] count = new int[] { 9, 16, 34 }; RealFunc[] f = new RealFunc[count.Length]; Point[] b = new Point[] { new Point(-1, 5), new Point(-4, 4), new Point(-2, 4), new Point(-2, 2), new Point(-1, 1), new Point(-1, 1) }; RealFunc f1 = (double x) => Math.Cos(2 * x) * (Math.Exp((x / 3).Abs()) - 4 * Math.Log(1 + x.Abs()));//Math.Sin(5 * x) / Math.Exp(x.Abs() / 3); RealFunc fl; Parallel.For(0, f.Length, (int i) => { f[i] = FuncMethods.Approx(f1, t, SequenceFuncKind.Other, count[i], b[0].x, b[0].y, true); }); fl = FuncMethods.Approx(f1, t, SequenceFuncKind.Other, count[count.Length - 1], b[0].x, b[0].y); int c = 280; double h = (b[0].y - b[0].x) / (c - 1); StreamWriter fs = new StreamWriter($"Monoms vs.txt"); //fs.WriteLine($"count normal ultra"); for (int j = 0; j < c; j++) { double arg = b[0].x + j * h; fs.Write($"{arg} {f1(arg)} {fl(arg)}"); for (int i = 0; i < count.Length; i++) { fs.Write($" {f[i](arg)}"); } fs.WriteLine(); } fs.Close(); }
private void RandArrows(DCircle circle, int count = 100) { if (count == 0) { return; } chart1.Series.Add(counter++.ToString()); chart1.Series.Last().IsVisibleInLegend = false; chart1.Series.Last().ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point; chart1.Series.Last().MarkerStyle = System.Windows.Forms.DataVisualization.Charting.MarkerStyle.Star5; chart1.Series.Last().MarkerSize = 8; chart1.Series.Last().BorderWidth = 8; chart1.Series.Last().Color = Color.Green; int n = chart1.Series.Count - 1; double cof = GetWindowsCoef(); int c = 0; Random r = new Random(); double x, y, q = circle.Radius * cof; Point f, p; while (c < count) { x = -q + r.NextDouble() * q * 2 + circle.Center.x; y = -q + r.NextDouble() * q * 2 + circle.Center.y; p = new Point(x, y); if (!circle.ContainPoint(p, 1.05)) { chart1.Series[n].Points.AddXY(x, y); f = circle.GetNormal(p, 0.1 * q); MakeArrow(new Point(p.x - f.x, p.y - f.y), f, Color.Blue, circle); c++; } } }
public static double g5(Point point) => masPoints[0].PotentialF(point);
public static double g4(Point point) => CONSTANT;
public static double g3(Point point) => 3 * point.x + 6 * point.y + Math.Sqrt(point.x.Sqr() + point.y.Sqr()) + 0.5 * point.y.Sqr();
public static double g10(Point p) => Math.Exp(p.x) * (Math.Cos(p.y) + 3 * Math.Sin(p.y));
private void button1_Click(object sender, EventArgs e) { for (int i = 0; i < 9; i++) { Program.FORM.chart1.Series[i].Points.Clear(); } for (int i = 0; i < chart1.Series.Count; i++) { chart1.Series[i].IsVisibleInLegend = false; } for (int i = 9; i < Program.FORM.chart1.Series.Count; i++) { Program.FORM.chart1.Series.RemoveAt(i); i--; } Func <double, double> f = Math.Sin; FuncMethods.NetFunc net = new FuncMethods.NetFunc(); Func <double, double> g1, g2, g3, g4, g5, g6, g7; //SequenceFunc Monom, Leg, Cheb, Lager, Her, Trig, Har; g1 = g2 = g3 = g4 = g5 = g6 = g7 = null; //определить действительную функцию if (radioButton5.Checked) { f = (double x) => (Math.Cos(x) - 1); } if (radioButton6.Checked) { f = (double x) => (Math.Abs(x - 1)); } if (radioButton7.Checked) { f = (double x) => (Math.Exp(x - x * x)); } if (radioButton8.Checked) { f = (double x) => (Math.Exp(x) / (Math.Abs(x) + 1)); } if (radioButton9.Checked) { f = (double x) => (x * Math.Sin(x) / (Math.Abs(x) + 2)); } if (radioButton10.Checked) { f = (double x) => (x / (1 + x * x)); } if (radioButton11.Checked) { f = (double x) => (x * Math.Cos(x)); } if (radioButton12.Checked) { f = (double x) => (Math.Log(1 + Math.Abs(x))); } if (radioButton13.Checked) { f = (double x) => (x * x * x + x - 4); } if (radioButton14.Checked) { f = (double x) => (3); } if (radioButton15.Checked) { f = (double x) => (2 * x - Math.Exp(-x)); } if (radioButton16.Checked) { string s = textBox7.Text; try { f = Parser.GetDelegate(s); textBox7.Text = Parser.FORMULA; } catch { f = (double x) => 0; } } chart1.Series[0].IsVisibleInLegend = true; FileStream fs = new FileStream("Данные об аппроксимации.txt", FileMode.Create); TextWriter tmp = Console.Out; StreamWriter sw = new StreamWriter(fs); Console.SetOut(sw); const string message = "Все доступные поля должны быть заполнены действительными числами. Число шагов и число отрезков - натуральными числами. При записи действительных чисел используются запятые, а не точки. Количество заверенных точек должно быть не больше количества действительно заданных точек."; const string caption = "Неверные входные данные!"; try { int n1 = Convert.ToInt32(numericUpDown1.Value), n2 = Convert.ToInt32(numericUpDown2.Value); double[,] MAS = new double[chart1.Series.Count, n2 + 1]; //определить сеточную функцию if (!radioButton1.Checked) { double a = Convert.ToDouble(textBox1.Text), b = Convert.ToDouble(textBox2.Text); int n = Convert.ToInt16(textBox6.Text), ccount = Convert.ToInt32(numericUpDown3.Value); double h = (b - a) / (ccount - 1); Point[] mas1, mas2, mas3 = new Point[ccount]; for (int i = 0; i < ccount; i++) { mas3[i] = new Point(a + i * h, f(a + i * h)); } //чтение набора узлов int m = Convert.ToInt32(textBox4.Text); mas2 = new МатКлассы.Point[m]; string s; string[] st; for (int k = 0; k < m; k++) { s = textBox5.Lines[k]; st = s.Split(' ');//в аргументах указывается массив символов, которым разделяются числа mas2[k] = new МатКлассы.Point(Convert.ToDouble(st[0]), Convert.ToDouble(st[1])); } //чтение массива абцисс s = textBox3.Lines[0]; st = s.Split(' ');//в аргументах указывается массив символов, которым разделяются числа; m = st.Length; mas1 = new МатКлассы.Point[m]; for (int k = 0; k < m; k++) { double v = Convert.ToDouble(st[k]); mas1[k] = new МатКлассы.Point(v, f(v)); } if (radioButton2.Checked) { net = new FuncMethods.NetFunc(mas1); } else { net = new FuncMethods.NetFunc(mas2); } if (checkBox10.Checked) { net = new FuncMethods.NetFunc(mas3); } a = net.MinArg; b = net.MaxArg; if (checkBox9.Checked) { for (n = n1; n <= n2; n++) { Matrix O = new Matrix(MAS); O.PrintMatrix(); "".Show(); if (checkBox1.Checked) { SequenceFunc t = FuncMethods.Monoms; Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Other, n); if (radioButton2.Checked) { MAS[1, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); } else { MAS[1, n] = FuncMethods.NetFunc.Distance(net, g); } chart1.Series[1].Points.AddXY(n, Math.Log10(MAS[1, n])); chart1.Series[1].IsVisibleInLegend = true; } if (checkBox2.Checked) { SequenceFunc t = FuncMethods.Lezhandrs(a, b); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Orthogonal, n); if (radioButton2.Checked) { MAS[2, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); } else { MAS[2, n] = FuncMethods.NetFunc.Distance(net, g); } chart1.Series[2].Points.AddXY(n, Math.Log10(MAS[2, n])); chart1.Series[2].IsVisibleInLegend = true; } if (checkBox6.Checked) { SequenceFunc t = FuncMethods.TrigSystem(a, b); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Orthonormal, n); if (radioButton2.Checked) { MAS[6, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); } else { MAS[6, n] = FuncMethods.NetFunc.Distance(net, g); } chart1.Series[6].Points.AddXY(n, Math.Log10(MAS[6, n])); chart1.Series[6].IsVisibleInLegend = true; } if (checkBox7.Checked) { SequenceFunc t = FuncMethods.HaarSystem(a, b); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Orthogonal, n); if (radioButton2.Checked) { MAS[7, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); } else { MAS[7, n] = FuncMethods.NetFunc.Distance(net, g); } chart1.Series[7].Points.AddXY(n, Math.Log10(MAS[7, n])); chart1.Series[7].IsVisibleInLegend = true; } if (checkBox8.Checked) { SequenceFunc t = (double x, int k) => Math.Exp(k * x); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Other, n); if (radioButton2.Checked) { MAS[8, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); } else { MAS[8, n] = FuncMethods.NetFunc.Distance(net, g); } chart1.Series[8].Points.AddXY(n, Math.Log10(MAS[8, n])); chart1.Series[8].IsVisibleInLegend = true; } } } else//если рисуется не график зависимости от числа функций { if (radioButton2.Checked) { net = new FuncMethods.NetFunc(mas1); Draw_mas(mas1, Color.Blue); } else { net = new FuncMethods.NetFunc(mas2); Draw_mas(mas2, Color.Blue); } if (checkBox10.Checked) { net = new FuncMethods.NetFunc(mas3); Draw_mas(mas3, Color.Blue); } a = net.MinArg; b = net.MaxArg; //ShowPoints(net);//показать точки на графике if (checkBox1.Checked) { SequenceFunc t = FuncMethods.Monoms; //SequencePol t = FuncMethods.Monom; Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Other, n); chart1.Series[1].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[1].IsVisibleInLegend = true; Console.WriteLine("--------Для системы мономов---------"); if (radioButton2.Checked) { FuncMethods.ShowApprox(f, net.Arguments, t, SequenceFuncKind.Other, n); } else { FuncMethods.ShowApprox(net, t, SequenceFuncKind.Other, n); } } //Наименьшие перпендикуляры if (n == 2) { double a0 = 0, a1 = 0; double dist = 0, distold = 0;; SLAU S = new SLAU(2); for (int i = 0; i < net.CountKnots; i++) { S.A[0, 0] += net.Arg(i); S.A[1, 0] += net.Arg(i) * net[i]; S.A[1, 1] += net[i]; S.b[1] -= net[i] * net[i]; } S.A[0, 1] = net.CountKnots; S.b[0] = -S.A[1, 1]; //S.Show(); S.GaussSelection(); a1 = S.x[0]; a0 = S.x[1]; Func <double, double> pol = new Polynom(new double[] { -a0, -a1 }).Value; SLAU T = new SLAU(FuncMethods.Monoms, net, n); T.Gauss();//T.Show(); for (int i = 0; i < net.CountKnots; i++) { dist += Math.Pow(a1 * net.Arg(i) + net[i] + a0, 2); distold += Math.Pow(T.x[1] * net.Arg(i) + net[i] + T.x[0], 2); } dist /= net.CountKnots; distold /= net.CountKnots; dist = Math.Sqrt(dist); distold = Math.Sqrt(distold); Console.WriteLine("\t(в среднеквадратичной норме перпендикуляров) равна {0}", distold); Program.FORM.chart1.Series.Add("Прямая с наилучшими перпендикулярами"); int count = Program.FORM.chart1.Series.Count - 1; Program.FORM.chart1.Series[count].Color = Color.Black; Program.FORM.chart1.Series[count].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line; //Program.FORM.chart1.Series[count].IsVisibleInLegend = false; Program.FORM.chart1.Series[count].BorderWidth = 2; chart1.Series[count].Points.DataBindXY(МатКлассы.Point.PointsX(pol, 100, a, b), МатКлассы.Point.PointsY(pol, 100, a, b)); Console.WriteLine("--------Для наименьших перпендикуляров---------"); Console.WriteLine("Аппроксимация сеточной функции полученной функцией"); Console.WriteLine("\t(в дискретной среднеквадратичной норме) равна {0}", FuncMethods.NetFunc.Distance(net, pol)); Console.WriteLine("\t(в среднеквадратичной норме перпендикуляров) равна {0}", dist); } if (checkBox2.Checked) { SequenceFunc t = FuncMethods.Lezhandrs(a, b); //SequencePol t = FuncMethods.Lezhandr(a, b); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Orthogonal, n); chart1.Series[2].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[2].IsVisibleInLegend = true; Console.WriteLine("--------Для системы полиномов Лежандра---------"); if (radioButton2.Checked) { FuncMethods.ShowApprox(f, net.Arguments, t, SequenceFuncKind.Orthogonal, n); } else { FuncMethods.ShowApprox(net, t, SequenceFuncKind.Orthogonal, n); } } if (checkBox6.Checked) { SequenceFunc t = FuncMethods.TrigSystem(a, b); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Orthonormal, n); chart1.Series[6].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[6].IsVisibleInLegend = true; Console.WriteLine("--------Для ортонормированной системы тригонометрических полиномов---------"); if (radioButton2.Checked) { FuncMethods.ShowApprox(f, net.Arguments, t, SequenceFuncKind.Orthonormal, n); } else { FuncMethods.ShowApprox(net, t, SequenceFuncKind.Orthonormal, n); } } if (checkBox7.Checked) { SequenceFunc t = FuncMethods.HaarSystem(a, b); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Orthogonal, n); chart1.Series[7].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[7].IsVisibleInLegend = true; Console.WriteLine("--------Для системы Хаара---------"); if (radioButton2.Checked) { FuncMethods.ShowApprox(f, net.Arguments, t, SequenceFuncKind.Orthogonal, n); } else { FuncMethods.ShowApprox(net, t, SequenceFuncKind.Orthogonal, n); } } if (checkBox8.Checked) { SequenceFunc t = (double x, int k) => Math.Exp(k * x); Func <double, double> g = FuncMethods.Approx(net, t, SequenceFuncKind.Other, n); chart1.Series[8].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[8].IsVisibleInLegend = true; Console.WriteLine("--------Для системы экспонент---------"); if (radioButton2.Checked) { FuncMethods.ShowApprox(f, net.Arguments, t, SequenceFuncKind.Other, n); } else { FuncMethods.ShowApprox(net, t, SequenceFuncKind.Other, n); } } } } else { double a = Convert.ToDouble(textBox1.Text), b = Convert.ToDouble(textBox2.Text); int n = Convert.ToInt16(textBox6.Text); if (checkBox9.Checked) { chart1.Series[0].Name = "Функция по системе Хаара, выраженная без учёта ортогональности этой системы"; chart1.Series[0].IsVisibleInLegend = true; for (n = n1; n <= n2; n++) { if (checkBox1.Checked) { //SequenceFunc t = FuncMethods.Monoms; SequencePol t = FuncMethods.Monom; Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); MAS[1, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); chart1.Series[1].Points.AddXY(n, Math.Log10(MAS[1, n])); chart1.Series[1].IsVisibleInLegend = true; chart1.Series[1].Name = "Мономы с применением ультра-гибрида"; //g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b, false); //MAS[0, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); //chart1.Series[0].Points.AddXY(n, Math.Log10(MAS[0, n])); //chart1.Series[0].IsVisibleInLegend = true; } if (checkBox2.Checked) { //SequenceFunc t = FuncMethods.Lezhandrs(a,b); SequencePol t = FuncMethods.Lezhandr(a, b); Polynom s = new Polynom(new double[] { -2 * a / (b - a) - 1, 2.0 / (b - a) }); Func <double, double>[] MyMas = new Func <double, double> [n]; for (int i = 0; i < n; i++) { MyMas[i] = /*Polynom.Lezh(i).Value;*/ Polynom.Lezh(i).Value(s).Value; } //Func<double,double> g = FuncMethods.ApproxForLezhandr(f, MyMas, a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Orthogonal, n, a, b); MAS[2, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); chart1.Series[2].Points.AddXY(n, Math.Log10(MAS[2, n])); chart1.Series[2].IsVisibleInLegend = true; } if (checkBox6.Checked) { SequenceFunc t = FuncMethods.TrigSystem(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Orthonormal, n, a, b); MAS[6, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); chart1.Series[6].Points.AddXY(n, Math.Log10(MAS[6, n])); chart1.Series[6].IsVisibleInLegend = true; chart1.Series[6].Name = "Тригонометрическая система с применением ультра-гибрида"; //g = FuncMethods.Approx(f, t, SequenceFuncKind.Orthonormal, n, a, b, false); //MAS[0, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); //chart1.Series[0].Points.AddXY(n, Math.Log10(MAS[0, n])); //chart1.Series[0].IsVisibleInLegend = true; } if (checkBox7.Checked) { SequenceFunc t = FuncMethods.HaarSystem(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Orthogonal, n, a, b); MAS[7, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); chart1.Series[7].Points.AddXY(n, Math.Log10(MAS[7, n])); chart1.Series[7].IsVisibleInLegend = true; chart1.Series[7].Name = "Система Хаара как ортогональная система"; //g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b, false); //MAS[0, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); //chart1.Series[0].Points.AddXY(n, Math.Log10(MAS[0, n])); //chart1.Series[0].IsVisibleInLegend = true; } if (checkBox8.Checked) { SequenceFunc t = (double x, int k) => Math.Exp(k * x); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); MAS[8, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); chart1.Series[8].Points.AddXY(n, Math.Log10(MAS[8, n])); chart1.Series[8].IsVisibleInLegend = true; chart1.Series[8].Name = "Экспоненты с применением ультра-гибрида"; //g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b, false); //MAS[0, n] = FuncMethods.RealFuncMethods.NormDistance(f, g, a, b); //chart1.Series[0].Points.AddXY(n, Math.Log10(MAS[0, n])); //chart1.Series[0].IsVisibleInLegend = true; } } Analys(MAS, n1, n2); } else { chart1.Series[0].Points.DataBindXY(МатКлассы.Point.PointsX(f, 100, a, b), МатКлассы.Point.PointsY(f, 100, a, b)); if (checkBox1.Checked) { //SequenceFunc t = FuncMethods.Monoms; SequencePol t = FuncMethods.Monom; Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); chart1.Series[1].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[1].IsVisibleInLegend = true; Console.WriteLine("--------Для системы мономов---------"); FuncMethods.ShowApprox(f, t, SequenceFuncKind.Other, n, a, b); } if (checkBox2.Checked) { //SequenceFunc t = FuncMethods.Lezhandrs(a,b); SequencePol t = FuncMethods.Lezhandr(a, b); Polynom s = new Polynom(new double[] { -2 * a / (b - a) - 1, 2.0 / (b - a) }); Func <double, double>[] MyMas = new Func <double, double> [n]; for (int i = 0; i < n; i++) { MyMas[i] = /*Polynom.Lezh(i).Value;*/ Polynom.Lezh(i).Value(s).Value; } Func <double, double> g = FuncMethods.ApproxForLezhandr(f, MyMas, a, b); chart1.Series[2].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[2].IsVisibleInLegend = true; Console.WriteLine("--------Для системы полиномов Лежандра---------"); FuncMethods.ShowApprox(f, t, SequenceFuncKind.Orthogonal, n, a, b); } if (checkBox3.Checked) { //SequencePol t = FuncMethods.Cheb(a,b); SequenceFunc t = FuncMethods.Chebs(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); chart1.Series[3].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[3].IsVisibleInLegend = true; } if (checkBox4.Checked) { SequenceFunc t = FuncMethods.Lagerrs(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); chart1.Series[4].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[4].IsVisibleInLegend = true; } if (checkBox5.Checked) { SequenceFunc t = FuncMethods.Hermits(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); chart1.Series[5].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[5].IsVisibleInLegend = true; } if (checkBox6.Checked) { SequenceFunc t = FuncMethods.TrigSystem(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Orthonormal, n, a, b); chart1.Series[6].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[6].IsVisibleInLegend = true; Console.WriteLine("--------Для ортонормированной системы тригонометрических полиномов---------"); FuncMethods.ShowApprox(f, t, SequenceFuncKind.Orthonormal, n, a, b); } if (checkBox7.Checked) { SequenceFunc t = FuncMethods.HaarSystem(a, b); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Orthogonal, n, a, b); chart1.Series[7].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[7].IsVisibleInLegend = true; Console.WriteLine("--------Для системы Хаара---------"); FuncMethods.ShowApprox(f, t, SequenceFuncKind.Orthogonal, n, a, b); } if (checkBox8.Checked) { SequenceFunc t = (double x, int k) => Math.Exp(k * x); Func <double, double> g = FuncMethods.Approx(f, t, SequenceFuncKind.Other, n, a, b); chart1.Series[8].Points.DataBindXY(МатКлассы.Point.PointsX(g, 100, a, b), МатКлассы.Point.PointsY(g, 100, a, b)); chart1.Series[8].IsVisibleInLegend = true; Console.WriteLine("--------Для системы экспонент---------"); FuncMethods.ShowApprox(f, t, SequenceFuncKind.Other, n, a, b); } } } } catch { var MBSave = MessageBox.Show(message, caption, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } finally { sw.Close(); Console.SetOut(tmp); Console.WriteLine("Запись завершена!"); Program.DATA.textBox1.Text = ""; StreamReader sr = new StreamReader("Данные об аппроксимации.txt"); string ss = ""; while (ss != null) { Program.DATA.textBox1.Text += ss + Environment.NewLine; ss = sr.ReadLine(); } sr.Close(); } }
public static double g6(Point point) => point.x * point.x - point.y * point.y;
public static double g7(Point point) => g1(point) * Math.Exp(point.x - point.y);
public void UpVal() { double rr = 1; Curve c = new Curve(0, 2 * Math.PI, (double t, double r) => r * Math.Cos(t), (double t, double r) => r * Math.Sin(t), rr); c.S = (double tx, double ty, double r) => tx * ty * r; c.End = (double r) => 2 * Math.PI; //Functional mp = (Point g) => 1; //DoubleIntegral(mp, c, c.S, parallel: true, cy: 300, M: Method.GaussKronrod61).Show(); Func <Point, int, double> ro = (Point p, int k) => { var cc = new Complex(p.x, p.y); return(Math.Pow(cc.Abs, k) * Math.Cos(k * cc.Arg)); }; Func <Point, Point, double> E = (Point x, Point y) => Math.Log(Point.Eudistance(x, y)); int xc = 100, yc = 100; double x0 = -8, X = 8, y0 = -8, Y = 8; double hx = (X - x0) / (xc - 1), hy = (Y - y0) / (yc - 1); double[] xa = new double[xc], ya = new double[yc]; for (int i = 0; i < xc; i++) { xa[i] = x0 + hx * i; } for (int i = 0; i < yc; i++) { ya[i] = y0 + hy * i; } int[] kk = new int[] { 3, 5, 25, 50, 200, 500 }; double[][,] val = new double[kk.Length][, ]; for (int i = 0; i < kk.Length; i++) { val[i] = new double[xc, yc]; Functional fl = (Point x) => { Functional tmp = (Point y) => ro(y, kk[i]) * E(x, y); return(DoubleIntegral(tmp, c, c.S, parallel: true, cy: 200, M: Method.GaussKronrod61)); }; Functional fl2 = (Point x) => { Complex z = new Complex(x.x, x.y); Functional tmp = (Point y) => { Complex w = new Complex(y.x, y.y); return(Math.Pow(w.Abs, kk[i]) * Math.Cos(kk[i] * (w.Arg)) * Math.Log(z.Abs.Sqr() + w.Abs.Sqr() - 2 * z.Abs * w.Abs * Math.Cos(w.Arg))); }; return(DoubleIntegral(tmp, c, c.S, parallel: true, cy: 200, M: Method.GaussKronrod61) / 2 * Math.Cos(kk[i] * z.Arg)); }; Functional fr = (Point x) => { Complex z = new Complex(x.x, x.y); return(Math.PI * Math.Cos(kk[i] * z.Arg) / (kk[i] + 2) * Math.Max(Math.Log((z.Abs - 1).Sqr()).Abs(), Math.Log((z.Abs + 1).Sqr()).Abs())); }; for (int ix = 0; ix < xc; ix++) { for (int iy = 0; iy < yc; iy++) { Point t = new Point(xa[ix], ya[iy]), o = new Point(0); double rad = Point.Eudistance(t, o); // $"t = {t} fr = {fr(t)} fl = {fl(t)}".Show(); //$"{fl(t)} {fl2(t)}".Show(); //Assert.IsTrue((fl(t) - fl2(t)).Abs() < 1e-7); if (rad > 1.0) { val[i][ix, iy] = fr(t).Abs() - fl(t).Abs(); } else { val[i][ix, iy] = Double.NaN; } } } } StreamWriter args = new StreamWriter("arg.txt"); StreamWriter vals = new StreamWriter("vals.txt"); for (int i = 0; i < xc; i++) { args.WriteLine($"{xa[i]} {ya[i]}"); } for (int i = 0; i < xc; i++) { for (int j = 0; j < yc; j++) { string st = ""; for (int s = 0; s < kk.Length; s++) { st += (val[s][i, j] + " "); } vals.WriteLine(st.Replace("NaN", "NA")); } } args.Close(); vals.Close(); }
public static double g9(Point point) => g8(point) + g3(point);
private async void button2_Click(object sender, EventArgs e) { DateTime time = DateTime.Now; //Func<double,double> f = t => Math.Sin(t*9) / Math.Exp(t * t / 3) * Math.Sign(Math.Max(0, (2*Math.PI- t.Abs()))); Func <double, double> f = t => Math.Cos(t * 9) * t / Math.Exp(t * t / 3) * Math.Sign(Math.Max(0, (Math.PI / 2 - t.Abs()))); //Func<double,double> f = t => Math.Sin(20*Math.PI*t)* Math.Sign(Math.Max(0, (1 - t.Abs()))); Func <double, double, Complex>[] f1 = new Func <double, double, Complex> [7]; Func <double, double>[] f2 = new Func <double, double> [7]; Wavelet[] w = new Wavelet[7]; //await Task.Run(() => //{ // for (int i = 0; i < 7; i++) // { // w[i] = new Wavelet((Wavelet.Wavelets)i); // f1[i] = w[i].GetAnalys(f); // f2[i] = w[i].GetSyntesis(f1[i]); // } //} //); w[3] = new Wavelet((Wavelet.Wavelets) 3); f1[3] = w[3].GetAnalys(f); f2[3] = w[3].GetSyntesis(/*f1[3]*/); //Wavelet w = new Wavelet(); //var f1 = w.GetAnalys(f); //var f2 = w.GetSyntesis(f1); //ИнтеграцияСДругимиПрограммами.CreatTableInExcel((double a, double b) => f1[3](a, b).Re, 0.01, 5, 100, 0.01, 7, 100); var p = OptimizationDCompFunc.GetMaxOnRectangle((double a, double b) => f1[3](a, b).Abs, 0.01, 5, 0.01, 10, eps: 1e-14, ogr: 5, nodescount: 15); new nzy3d_winformsDemo.Form1("", 0.01, 5, 70, 0.01, 10, 70, (double a, double b) => f1[3](a, b).Abs).Show(); // ИнтеграцияСДругимиПрограммами.CreatTableInExcel(f1[3], 0.01, 3, 100, 0.01, 3, 100); //ИнтеграцияСДругимиПрограммами.CreatTableInExcel(w[3].Dic,"Test Page",Number.Complex.ComplMode.Abs); //c1Chart3D1.ChartGroups.Group0.ChartType = Chart3DTypeEnum.Surface; //double[,] z = new double[100, 100]; //for (int s = 0; s < 31; s++) // for (int n = 0; n < 21; n++) // { // z[s, n] = f1[3](0.01 + 0.01 * s, 0.01 + 0.01 * n).Re; // } // create dataset and put it to the chart //Chart3DDataSetGrid gridset = new Chart3DDataSetGrid(0, 0, 1, 1, z); //c1Chart3D1.ChartGroups[0].ChartData.Set = gridset; //var o = w[3].Dic; //МатКлассы.Point[] u = o.Keys.ToArray(); //var c = o.Values.ToArray(); //Chart3DPoint[] points1 = new Chart3DPoint[o.Count]; //for (int i = 0; i < o.Count; i++) // points1[i] = new Chart3DPoint(u[i].x, u[i].y, 7/*(double)c[i].Value*/); //Chart3DDataSetPoint pointset = new Chart3DDataSetPoint(); //pointset.AddSeries(points1); //c1Chart3D1.ChartGroups[0].ChartData.Set = pointset; List <double> tm = new List <double>(), m = new List <double>(); for (double i = beg; i < end; i += step) { double tmp0 = f(i);//,tmp2=f2(i);$"f = {tmp0} \tWf-1 = {tmp2} \teps = {(tmp2-tmp0)} \t f/f0 = {tmp0/tmp2}".Show(); double[] mas = new double[7]; await Task.Run(() => { //for (int j = 0; j < 7; j++) // mas[j] = f2[j](i); mas[3] = f2[3](i); }); (new Vectors(mas) - tmp0).Show(); chart1.Series[0].Points.AddXY(i, tmp0); for (int j = 0; j < 7; j++) { chart1.Series[j + 1].Points.AddXY(i, mas[j]); } progressBar1.Value = (int)((i - beg) / (end - beg) * 100); m.Add(mas[3]); tm.Add(tmp0); } label1.Text = "Время работы (минуты полторы ушло на Excel): " + (DateTime.Now - time).ToString(); label2.Text = "Точность в евклидовой норме: " + (new Vectors(m.ToArray()) - new Vectors(tm.ToArray())).Sort.EuqlidNorm.ToString(); var s = new МатКлассы.Point(p.Item1, p.Item2); label3.Text = "Точка максимума: " + s.ToString(); label4.Text = "Максимальное по модулю значение: " + f1[3](p.Item1, p.Item2).ToString(); }
public static double g11(Point p) => g1(p) + g2(p) + g3(p) + g4(p) + g4(p);
public static double g1(Point point) => point.x + point.y;
private Tuple <Point, Point> GetSourceRect() => Point.GetBigRect(sourcesArray.Select(s => s.Center).ToArray());
public static double g2(Point point) => Math.Sin(point.y) * (Math.Exp(point.x) + Math.Exp(-point.x));