|
|||||||
АвтоАвтоматизацияАрхитектураАстрономияАудитБиологияБухгалтерияВоенное делоГенетикаГеографияГеологияГосударствоДомДругоеЖурналистика и СМИИзобретательствоИностранные языкиИнформатикаИскусствоИсторияКомпьютерыКулинарияКультураЛексикологияЛитератураЛогикаМаркетингМатематикаМашиностроениеМедицинаМенеджментМеталлы и СваркаМеханикаМузыкаНаселениеОбразованиеОхрана безопасности жизниОхрана ТрудаПедагогикаПолитикаПравоПриборостроениеПрограммированиеПроизводствоПромышленностьПсихологияРадиоРегилияСвязьСоциологияСпортСтандартизацияСтроительствоТехнологииТорговляТуризмФизикаФизиологияФилософияФинансыХимияХозяйствоЦеннообразованиеЧерчениеЭкологияЭконометрикаЭкономикаЭлектроникаЮриспунденкция |
Численное интегрирование методом Монте-Карло4.1 Теоретический материал: В этом методе несколько раз берётся значение подынтегральной функции от случайной величины, которая лежит между пределами интегрирования. Затем сумма полученных значений делится на объём выборки, который также называется количеством разыгрываемых точек.
4.2 Блок-схема: Рисунок 7 – Метод Монте-Карло. 4.3 Результат работы:
Рисунок 8 – Результат вычисления методом Монте-Карло.
Листинг программы: using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Text; using System.Windows.Forms; using System.Threading;
namespace nelin_ur { public partial class Form1: Form {
public Form1() { InitializeComponent(); }
private double a = 0.0; private double b = 1.0; private double h, x, s; private int n; private double fun(double x) { double f = (double)(Math.Cos(x * x));
return (f); } private double m1(double a, double b, int n) { h = (b - a) / n; x = a + h / 2; s = 0; for (int i = 0; i < n; i++) { s = s + fun(x); x = x + h; } s = s * h; return (s); } private double m1_gr(double a, double b, int n) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage1.Handle); System.Drawing.Brush brush = System.Drawing.Brushes.Red; System.Drawing.Brush brush2 = System.Drawing.Brushes.White; int milSec = hScrollBar1.Maximum + 10 - hScrollBar1.Value; g.FillEllipse(brush, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); Thread.Sleep(milSec); g.FillEllipse(brush2, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.FillRectangle(brush, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.FillRectangle(brush, 201, 81, 99, 39); g.DrawString("h=(b-a)/N\nx:=a;s:=0", this.Font, Brushes.Black, 223, 88); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 81, 99, 39); g.DrawString("h=(b-a)/N\nx:=a;s:=0", this.Font, Brushes.Black, 223, 88); h = (b - a) / n; x = a; s = 0;
for (int i = 1; i < n; i++) { g.FillRectangle(brush, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132);
g.FillRectangle(brush, 201, 161, 99, 29); g.DrawString("s:=s+f(x)\nx:=x+h", this.Font, Brushes.Black, 223, 162); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 161, 99, 29); g.DrawString("s:=s+f(x)\nx:=x+h", this.Font, Brushes.Black, 223, 162); x = x + h; s = s + fun(x);
} g.FillRectangle(brush, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132);
g.FillRectangle(brush, 316, 131, 99, 19); g.DrawString("s:=s*h", this.Font, Brushes.Black, 345, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 316, 131, 99, 19); g.DrawString("s:=s*h", this.Font, Brushes.Black, 345, 132); s = s * h; g.FillRectangle(brush, 316, 161, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 340, 162); Thread.Sleep(milSec); g.FillRectangle(brush2, 316, 161, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 340, 162); g.FillEllipse(brush, 316, 191, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 345, 192); Thread.Sleep(milSec); g.FillEllipse(brush2, 316, 191, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 345, 192); return (s);
} private double m2(double a, double b, int n) { double f; h = (b - a) / n; x = a+h; s = 0; s = (fun(a) + fun(b)) / 2; for (int i = 0; i < n-1; i++) { s = s + fun(x); x = x + h; } s = s * h; return (s); } private double m2_gr(double a, double b, int n) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage2.Handle); System.Drawing.Brush brush = System.Drawing.Brushes.Red; System.Drawing.Brush brush2 = System.Drawing.Brushes.White; int milSec = hScrollBar2.Maximum + 10 - hScrollBar2.Value; g.FillEllipse(brush, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); Thread.Sleep(milSec); g.FillEllipse(brush2, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.FillRectangle(brush, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.FillRectangle(brush, 201, 81, 99, 39); g.DrawString("h=(b-a)/N\nx:=a;s:=0\ns:=(f(a)+f(b))/2", this.Font, Brushes.Black, 217, 82); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 81, 99, 39); g.DrawString("h=(b-a)/N\nx:=a;s:=0\ns:=(f(a)+f(b))/2", this.Font, Brushes.Black, 217, 82);
h = (b - a) / n; x = a; s = 0; s = (fun(a) + fun(b)) / 2; for (int i = 0; i < n; i++) { g.FillRectangle(brush, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132);
g.FillRectangle(brush, 201, 161, 99, 29); g.DrawString("s:=s+f(x)\nx:=x+h", this.Font, Brushes.Black, 223, 162); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 161, 99, 29); g.DrawString("s:=s+f(x)\nx:=x+h", this.Font, Brushes.Black, 223, 162); s = s + fun(x); x = x + h; } g.FillRectangle(brush, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132);
g.FillRectangle(brush, 316, 131, 99, 19); g.DrawString("s:=s*h", this.Font, Brushes.Black, 345, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 316, 131, 99, 19); g.DrawString("s:=s*h", this.Font, Brushes.Black, 345, 132); s = s * h; g.FillRectangle(brush, 316, 161, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 340, 162); Thread.Sleep(milSec); g.FillRectangle(brush2, 316, 161, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 340, 162); g.FillEllipse(brush, 316, 191, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 345, 192); Thread.Sleep(milSec); g.FillEllipse(brush2, 316, 191, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 345, 192); return (s); } private double m3(double a, double b, int n) { double x0; h = (b - a) / n; x = a; s = fun(a); for (int i = 1; i <= n; i = i + 2) { x = x + h; s = s + 4 * fun(x); if ((i + 1) == n) break; x = x + h; s = s + 2 * fun(x); }; x = b; s = s + fun(x); s = s * h / 3; return (s); } private double m3_gr(double a, double b, int n) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage3.Handle); System.Drawing.Brush brush = System.Drawing.Brushes.Red; System.Drawing.Brush brush2 = System.Drawing.Brushes.White; int milSec = hScrollBar3.Maximum + 10 - hScrollBar3.Value; g.FillEllipse(brush, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); Thread.Sleep(milSec); g.FillEllipse(brush2, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.FillRectangle(brush, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.FillRectangle(brush, 201, 81, 99, 39); g.DrawString("h=(b-a)/N\nx:=a;s:=f(a)", this.Font, Brushes.Black, 217, 88); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 81, 99, 39); g.DrawString("h=(b-a)/N\nx:=a;s:=f(a)", this.Font, Brushes.Black, 217, 88); h = (b - a) / n; x = a; s = fun(a); for (int i = 1; i <= n; i = i + 2) { g.FillRectangle(brush, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 131, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); g.FillRectangle(brush, 201, 161, 99, 29); g.DrawString("x:=x+h\ns:=s+4f(x)", this.Font, Brushes.Black, 223, 162); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 161, 99, 29); g.DrawString("x:=x+h\ns:=s+4f(x)", this.Font, Brushes.Black, 223, 162); x = x + h; s = s + 4 * fun(x); g.FillRectangle(brush, 201, 201, 99, 19); g.DrawString("(i+1)==N", this.Font, Brushes.Black, 223, 202); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 201, 99, 19); g.DrawString("(i+1)==N", this.Font, Brushes.Black, 223, 202); if ((i + 1) == n) break; g.FillRectangle(brush, 131, 231, 99, 29); g.DrawString("x:=x+h\ns:=s+2f(x)", this.Font, Brushes.Black, 153, 232); Thread.Sleep(milSec); g.FillRectangle(brush2, 131, 231, 99, 29); g.DrawString("x:=x+h\ns:=s+2f(x)", this.Font, Brushes.Black, 153, 232); x = x + h; s = s + 2 * fun(x); }; g.FillRectangle(brush, 271, 231, 99, 39); g.DrawString("x:=b\ns:=s+f(x)\ns=s*h/3", this.Font, Brushes.Black, 293, 232); Thread.Sleep(milSec); g.FillRectangle(brush2, 271, 231, 99, 39); g.DrawString("x:=b\ns:=s+f(x)\ns=s*h/3", this.Font, Brushes.Black, 293, 232); x = b; s = s + fun(x); s = s * h / 3; g.FillRectangle(brush, 271, 281, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 290, 282); Thread.Sleep(milSec); g.FillRectangle(brush2, 271, 281, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 290, 282); g.FillEllipse(brush, 271, 311, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 305, 312); Thread.Sleep(milSec); g.FillEllipse(brush2, 271, 311, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 305, 312); return (s); }
private Random rand = new Random(); private double m4(double a, double b, int n) { s = 0; for (int i = 1; i <= n; i++) { s = s + fun(rand.NextDouble() * (b - a) + a); }; s = s / n; return (s); } private double m4_gr(double a, double b, int n) { System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage4.Handle); System.Drawing.Brush brush = System.Drawing.Brushes.Red; System.Drawing.Brush brush2 = System.Drawing.Brushes.White; int milSec = hScrollBar4.Maximum + 10 - hScrollBar4.Value; g.FillEllipse(brush, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); Thread.Sleep(milSec); g.FillEllipse(brush2, 201, 21, 99, 18); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.FillRectangle(brush, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 51, 99, 19); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); s = 0; for (int i = 1; i <= n; i++) { g.FillRectangle(brush, 201, 81, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 223, 82); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 81, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 223, 82);
g.FillRectangle(brush, 201, 111, 99, 19); g.DrawString("s:=s+f(random())", this.Font, Brushes.Black, 215, 112); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 111, 99, 19); g.DrawString("s:=s+f(random())", this.Font, Brushes.Black, 215, 112); s = s + fun(rand.NextDouble() * (b - a) + a); }; g.FillRectangle(brush, 201, 81, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 223, 82); Thread.Sleep(milSec); g.FillRectangle(brush2, 201, 81, 99, 19); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 223, 82); s = s / n; g.FillRectangle(brush, 311, 81, 99, 19); g.DrawString("s:=s/N", this.Font, Brushes.Black, 333, 82); Thread.Sleep(milSec); g.FillRectangle(brush2, 311, 81, 99, 19); g.DrawString("s:=s/N", this.Font, Brushes.Black, 333, 82);
g.FillRectangle(brush, 311, 111, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 330, 112); Thread.Sleep(milSec); g.FillRectangle(brush2, 311, 111, 99, 19); g.DrawString("вывод s", this.Font, Brushes.Black, 330, 112);
g.FillEllipse(brush, 311, 141, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 340, 142); Thread.Sleep(milSec); g.FillEllipse(brush2, 311, 141, 99, 18); g.DrawString("конец", this.Font, Brushes.Black, 340, 142); return (s); }
private void Form1_Load(object sender, EventArgs e) {
}
private void button1_Click (object sender, EventArgs e) { System.Drawing.Pen myPen = System.Drawing.Pens.Black; System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage1.Handle); g.DrawEllipse(myPen, 200, 20, 100, 20); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.DrawLine(myPen, 250, 40, 250, 50); g.DrawRectangle(myPen, 200, 50, 100, 20); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.DrawLine(myPen, 250, 70, 250, 80); g.DrawRectangle(myPen, 200, 80, 100, 40); g.DrawString("h=(b-a)/N\nx:=a;s:=0", this.Font, Brushes.Black, 223, 88); g.DrawLine(myPen, 250, 120, 250, 130); g.DrawRectangle(myPen, 200, 130, 100, 20); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); g.DrawLine(myPen, 250, 150, 250, 160); g.DrawRectangle(myPen, 200, 160, 100, 30); g.DrawString("s:=s+f(x)\nx:=x+h", this.Font, Brushes.Black, 223, 162); g.DrawLine(myPen, 200, 175, 185, 175); g.DrawLine(myPen, 185, 175, 185, 140); g.DrawLine(myPen, 200, 140, 185, 140); g.DrawLine(myPen, 300, 140, 315, 140); g.DrawRectangle(myPen, 315, 130, 100, 20); g.DrawString("s:=s*h", this.Font, Brushes.Black, 345, 132); g.DrawLine(myPen, 365, 150, 365, 160); g.DrawRectangle(myPen, 315, 160, 100, 20); g.DrawString("вывод s", this.Font, Brushes.Black, 340, 162); g.DrawLine(myPen, 365, 180, 365, 190); g.DrawEllipse(myPen, 315, 190, 100, 20); g.DrawString("конец", this.Font, Brushes.Black, 345, 192);
label1.Text = ""; n = 4; s = m1_gr(a, b, n); label1.Text = label1.Text + s + ", N=4" + "\n"; n = 10; s = m1(a, b, n); label1.Text = label1.Text + s + ", N=10" + "\n"; n = 50; s = m1(a, b, n); label1.Text = label1.Text + s + ", N=50" + "\n"; n = 500; s = m1(a, b, n); label1.Text = label1.Text + s + ", N=500" + "\n";
}
private void button2_Click (object sender, EventArgs e) { System.Drawing.Pen myPen = System.Drawing.Pens.Black; System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage2.Handle); g.DrawEllipse(myPen, 200, 20, 100, 20); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.DrawLine(myPen, 250, 40, 250, 50); g.DrawRectangle(myPen, 200, 50, 100, 20); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.DrawLine(myPen, 250, 70, 250, 80); g.DrawRectangle(myPen, 200, 80, 100, 40); g.DrawString("h=(b-a)/N\nx:=a;s:=0\ns:=(f(a)+f(b))/2", this.Font, Brushes.Black, 217, 82); g.DrawLine(myPen, 250, 120, 250, 130); g.DrawRectangle(myPen, 200, 130, 100, 20); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 225, 132); g.DrawLine(myPen, 250, 150, 250, 160); g.DrawRectangle(myPen, 200, 160, 100, 30); g.DrawString("s:=s+f(x)\nx:=x+h", this.Font, Brushes.Black, 223, 162); g.DrawLine(myPen, 200, 175, 185, 175); g.DrawLine(myPen, 185, 175, 185, 140); g.DrawLine(myPen, 200, 140, 185, 140); g.DrawLine(myPen, 300, 140, 315, 140); g.DrawRectangle(myPen, 315, 130, 100, 20); g.DrawString("s:=s*h", this.Font, Brushes.Black, 345, 132); g.DrawLine(myPen, 365, 150, 365, 160); g.DrawRectangle(myPen, 315, 160, 100, 20); g.DrawString("вывод s", this.Font, Brushes.Black, 340, 162); g.DrawLine(myPen, 365, 180, 365, 190); g.DrawEllipse(myPen, 315, 190, 100, 20); g.DrawString("конец", this.Font, Brushes.Black, 345, 192); label2.Text = ""; n = 4; s = m2_gr(a, b, n); label2.Text = label2.Text + s + ", N=4" + "\n"; n = 10; s = m2(a, b, n); label2.Text = label2.Text + s + ", N=10" + "\n"; n = 50; s = m2(a, b, n); label2.Text = label2.Text + s + ", N=50" + "\n"; n = 500; s = m2(a, b, n); label2.Text = label2.Text + s + ", N=500" + "\n";
}
private void button3_Click (object sender, EventArgs e) { System.Drawing.Pen myPen = System.Drawing.Pens.Black; System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage3.Handle); g.DrawEllipse(myPen, 200, 20, 100, 20); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.DrawLine(myPen, 250, 40, 250, 50); g.DrawRectangle(myPen, 200, 50, 100, 20); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.DrawLine(myPen, 250, 70, 250, 80); g.DrawRectangle(myPen, 200, 80, 100, 40); g.DrawString("h=(b-a)/N\nx:=a;s:=f(a)", this.Font, Brushes.Black, 217, 88); g.DrawLine(myPen, 250, 120, 250, 130); g.DrawRectangle(myPen, 200, 130, 100, 20); g.DrawString("i=1,N,2", this.Font, Brushes.Black, 225, 132); g.DrawLine(myPen, 250, 150, 250, 160); g.DrawRectangle(myPen, 200, 160, 100, 30); g.DrawString("x:=x+h\ns:=s+4f(x)", this.Font, Brushes.Black, 223, 162); g.DrawLine(myPen, 250, 190, 250, 200); g.DrawRectangle(myPen, 200, 200, 100, 20); g.DrawString("(i+1)==N", this.Font, Brushes.Black, 223, 202); g.DrawLine(myPen, 200, 210, 180, 210); g.DrawLine(myPen, 180, 210, 180, 230); g.DrawRectangle(myPen, 130, 230, 100, 30); g.DrawString("x:=x+h\ns:=s+2f(x)", this.Font, Brushes.Black, 153, 232); g.DrawLine(myPen, 130, 245, 125, 245); g.DrawLine(myPen, 125, 245, 125, 140); g.DrawLine(myPen, 125, 140, 200, 140); g.DrawLine(myPen, 300, 140, 320, 140); g.DrawLine(myPen, 300, 210, 320, 210); g.DrawLine(myPen, 320, 140, 320, 230); g.DrawRectangle(myPen, 270, 230, 100, 40); g.DrawString("x:=b\ns:=s+f(x)\ns=s*h/3", this.Font, Brushes.Black, 293, 232); g.DrawLine(myPen, 320, 270, 320, 280); g.DrawRectangle(myPen, 270, 280, 100, 20); g.DrawString("вывод s", this.Font, Brushes.Black, 290, 282); g.DrawLine(myPen, 320, 300, 320, 310); g.DrawEllipse(myPen, 270, 310, 100, 20); g.DrawString("конец", this.Font, Brushes.Black, 305, 312); label3.Text = ""; n = 4; s = m3_gr(a, b, n); label3.Text = label3.Text + s + ", N=4" + "\n"; n = 10; s = m3(a, b, n); label3.Text = label3.Text + s + ", N=10" + "\n"; n = 50; s = m3(a, b, n); label3.Text = label3.Text + s + ", N=50" + "\n"; n = 500; s = m3(a, b, n); label3.Text = label3.Text + s + ", N=500" + "\n";
}
private void button4_Click (object sender, EventArgs e) { System.Drawing.Pen myPen = System.Drawing.Pens.Black; System.Drawing.Graphics g = System.Drawing.Graphics.FromHwnd(tabPage4.Handle); g.DrawEllipse(myPen, 200, 20, 100, 20); g.DrawString("начало", this.Font, Brushes.Black, 230, 22); g.DrawLine(myPen, 250, 40, 250, 50); g.DrawRectangle(myPen, 200, 50, 100, 20); g.DrawString("ввод a,b,N", this.Font, Brushes.Black, 220, 52); g.DrawLine(myPen, 250, 70, 250, 80); g.DrawRectangle(myPen, 200, 80, 100, 20); g.DrawString("i=1,N,1", this.Font, Brushes.Black, 223, 82); g.DrawLine(myPen, 250, 100, 250, 110); g.DrawRectangle(myPen, 200, 110, 100, 20); g.DrawString("s:=s+f(random())", this.Font, Brushes.Black, 215, 112); g.DrawLine(myPen, 200, 120, 180, 120); g.DrawLine(myPen, 200, 90, 180, 90); g.DrawLine(myPen, 180, 90, 180, 120); g.DrawLine(myPen, 300, 90, 310, 90); g.DrawRectangle(myPen, 310, 80, 100, 20); g.DrawString("s:=s/N", this.Font, Brushes.Black, 333, 82); g.DrawLine(myPen, 360, 100, 360, 110); g.DrawRectangle(myPen, 310, 110, 100, 20); g.DrawString("вывод s", this.Font, Brushes.Black, 330, 112); g.DrawLine(myPen, 360, 130, 360, 140); g.DrawEllipse(myPen, 310, 140, 100, 20); g.DrawString("конец", this.Font, Brushes.Black, 340, 142);
label4.Text = ""; n = 4; s = m4_gr(a, b, n); label4.Text = label4.Text + s + ", N=4" + "\n"; n = 10; s = m4(a, b, n); label4.Text = label4.Text + s + ", N=10" + "\n"; n = 50; s = m4(a, b, n); label4.Text = label4.Text + s + ", N=50" + "\n"; n = 500; s = m4(a, b, n); label4.Text = label4.Text + s + ", N=500" + "\n";
}
private void tabPage1_Click(object sender, EventArgs e) {
}
} }
Заключение
В ходе выполнения данной лабораторной работы были изучены 4 метода численного интегрирования. Было создано приложение, демонстрирующее изученные методы на примере конкретной функции.
Поиск по сайту: |
Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав. Студалл.Орг (0.061 сек.) |