public static vector integrate(MultiFunc f, double a, double b, double e, int min_step) { t <vector> t = new t <vector>(); int n, k, i, m; double h, p; vector g; h = (b - a) / 2; t[0, 0] = h * (f(a) + f(b)); k = 1; n = 1; do { g = null; for (i = 1; i <= n; i++) { g += f(a + (2 * i - 1) * h); } t[k, 0] = t[k - 1, 0] / 2 + h * g; for (m = 1; m <= k; m++) { p = System.Math.Pow(4, m); t[k - m, m] = (p * t[k - m + 1, m - 1] - t[k - m, m - 1]) / (p - 1); } m -= 1; h /= 2; n *= 2; k += 1; } while (k < min_step || (t[0, m] - t[0, m - 1]).abs().Max() > e); return(t[0, m]); }
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(); }
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 static double Max(MultiFunc F) { MultiFunc e = (double[] x) => - F(x); return(-Min(e)); }
public static double Min(MultiFunc F) { return(-1); }