Студопедия

Главная страница Случайная страница

КАТЕГОРИИ:

АвтомобилиАстрономияБиологияГеографияДом и садДругие языкиДругоеИнформатикаИсторияКультураЛитератураЛогикаМатематикаМедицинаМеталлургияМеханикаОбразованиеОхрана трудаПедагогикаПолитикаПравоПсихологияРелигияРиторикаСоциологияСпортСтроительствоТехнологияТуризмФизикаФилософияФинансыХимияЧерчениеЭкологияЭкономикаЭлектроника






Текст программы.




using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; using System.Windows.Forms;   namespace WindowsFormsApplication4 { public partial class Form1: Form { public Form1() { InitializeComponent(); } double x1_shtr(double t, double x1, double alfa, double u) { return x1 * alfa*u; } double x2_shtr(double t, double x1, double alfa, double u) { return x1 *(1-u)*alfa; } private void таблицаToolStripMenuItem_Click(object sender, EventArgs e) {panel1.Visible = false; label3.Text = " Решение представленно в таблице"; dataGridView1.Visible = true; chart1.Visible = false; chart2.Visible = false; label1.Visible = false; label2.Visible = false; label14.Visible = false; dataGridView2.Visible = false; } private void графикиToolStripMenuItem_Click(object sender, EventArgs e) { panel1.Visible = false; label3.Visible = true; label3.Text = " Решение представленно на графиках"; dataGridView1.Visible = false; chart1.Visible = true; chart2.Visible = true; label1.Visible = true; label2.Visible = true; label5.Visible = true; label14.Visible = false; dataGridView2.Visible = false; } private void public void Out(int q, double[] t, double[] x1, double[] x2, double[] u1, double J1) {int k = 0; int q1; q1 = q; while (q1! = 0) double[] u1 = new double[q];; double[] psi1 = new double[q + 1]; double[] psi2 = new double[q + 1]; double J, J1; t[0] = 0; for (int i = 0; i < = q - 1; i++) t[i + 1] = t[i] + h; for (int i = 0; i < = q - 1; i++) u[i] = 0.5; x1[0] = 1; for (int i = 0; i < = q - 1; i++) x1[i + 1] = x1[i] + (1 - u[i]) * x1[i] * h; x2[0] = 0; for (int i = 0; i < = q - 1; i++) x2[i + 1] = x2[i] + u[i] * x1[i] * h; J = -x2[q]; label: psi1[q] = 0; psi2[q] = 1; for (int i = q - 1; i > = 1; i--) { psi1[i] = psi1[i + 1] + psi1[i + 1] * (1 - u[i]) * h + psi2[i + 1] * u[i] * h; psi2[i] = psi2[i + 1]; } for (int i = 0; i < = q - 1; i++) {if (psi1[i + 1] > = psi2[i + 1]) u1[i] = 0; else u1[i] = 1; } x1_1[0] = 1; for (int i = 0; i < = q - 1; i++) x1_1[i + 1] = x1_1[i] + (1 - u1[i]) * x1_1[i] * h; x2_1[0] = 0; for (int i = 0; i < = q - 1; i++) x2_1[i + 1] = x2_1[i] + u1[i] * x1_1[i] * h; J1 = -x2_1[q]; if (J1 < J){ if (Math.Abs(J1 - J) < = epsJ) Out(q, t, x1_1, x2_1, u1, J1); else{J = J1; for (int i = 0; i < = q; i++) {x1[i] = x1_1[i]; x2[i] = x2_1[i]; } for (int i = 0; i < = q - 1; i++) u[i] = u1[i]; goto label; } Else Out(q, t, x1, x2, u, J); }     private void button2_Click(object sender, EventArgs e) { double T; T = Convert.ToDouble(textBox2.Text); int q; q = 1000; double epsJ; epsJ=0.0001; double h; h = T / q; double x1, x2, k1, k2, k3, k4, m1, m2, m3, m4, U; double[] t = new double[q + 1]; double[] x1 = new double[q + 1]; double[] x2 = new double[q + 1]; double[] u = new double[q];; double[] x1_1 = new double[q + 1]; double[] x2_1 = new double[q + 1]; double[] u1 = new double[q];; double[] psi1 = new double[q + 1]; double[] psi2 = new double[q + 1]; double J, J1; t[0] = 0; psi1[q] = 0; psi2[q] = 1; for (int i = q - 1; i > = 1; i--) { psi1[i] = psi1[i + 1] + psi1[i + 1] * (1 - u[i]) * h + psi2[i + 1] * u[i] * h; psi2[i] = psi2[i + 1]; } for (int i = 0; i < = q - 1; i++) {if (psi1[i + 1] > = psi2[i + 1]) u1[i] = 0; else u1[i] = 1; } x1_1[0] = 1; for (int i = 0; i < = q - 1; i++) { k1 = x1_shtr(t, x1, alfa, U); k2 = x1_shtr(t + tau / 2, x1 + tau / 4 * k1, alfa, U); k3 = x1_shtr(t + tau / 2, x1 + tau / 2 * k2, alfa, U); k4 = x1_shtr(t + tau, x1 + tau * k1 - 2 * tau * k2 + 2 * tau * k3, alfa, U); x1_1[i+1] = x1_1[i] + tau / 6 * (k1 + 2 * k2 + 2 * k3 + k4); } t = t + tau; t x2_1[0] = 0; for (int i = 0; i < = q - 1; i++) { k1 = x1_shtr(t, x1, alfa, U); k2 = x1_shtr(t + tau / 2, x1 + tau / 4 * k1, alfa, U); k3 = x1_shtr(t + tau / 2, x1 + tau / 2 * k2, alfa, U); k4 = x1_shtr(t + tau, x1 + tau * k1 - 2 * tau * k2 + 2 * tau * k3, alfa, U); x2_1[i+1] = x2_1[i] + tau / 6 * (k1 + 2 * k2 + 2 * k3 + k4); }   J1 = -x2_1[q]; if (J1 < J){ if (Math.Abs(J1 - J) < = epsJ) Out(q, t, x1_1, x2_1, u1, J1); else{J = J1; for (int i = 0; i < = q; i++) {x1[i] = x1_1[i]; x2[i] = x2_1[i]; } for (int i = 0; i < = q - 1; i++) u[i] = u1[i]; goto label; } Else Out(q, t, x1, x2, u, J); //ТОЧНОЕ РЕШЕНИЕ 1 t = 0; k = 0; while (t < T){if ((t > = 0) & & (t < = (T - 2 / alfa))) {x1_shtr_tochnoe = alfa1 * Math.Exp(alfa * t); dataGridView1.Rows[k].Cells[2].Value = x1_shtr_tochnoe; t = t + tau; k++; chart1.Series[1].Points.AddXY(t, x1_shtr_tochnoe); } else{ x1_shtr_tochnoe = alfa1 * Math.Exp(alfa * T - 2); dataGridView1.Rows[k].Cells[2].Value = x1_shtr_tochnoe; t = t + tau; k++; chart1.Series[1].Points.AddXY(t, x1_shtr_tochnoe); }} //ТОЧНОЕ РЕШЕНИЕ 2t = 0; {q1 = q1 / 10; k++; } chart1.Series.Clear(); chart2.Series.Clear() chart1.Series.Add(" x1(t)"); chart1.Series.Add(" x2(t)"); chart2.Series.Add(" u(t)"); chart1.Series[" x1(t)" ].ChartType = SeriesChartType.Line; chart1.Series[" x2(t)" ].ChartType = SeriesChartType.Line; chart2.Series[" u(t)" ].ChartType = SeriesChartType.Line; chart1.Series[" x1(t)" ].BorderWidth = 2; chart1.Series[" x2(t)" ].BorderWidth = 2; chart2.Series[" u(t)" ].BorderWidth = 2; for (int i = 0; i < = q; i++){ chart1.Series[" x1(t)" ].Points.AddXY(t[i], x1[i]); chart1.Series[" x2(t)" ].Points.AddXY(t[i], x2[i]); } for (int i = 0; i < = q - 1; i++) chart2.Series[" u(t)" ].Points.AddXY(t[i], u1[i]); textBox1.Text = Convert.ToString(J1); string[] row = new string[5]; row[0] = " q"; row[1] = " t"; row[2] = " x(t)"; row[3] = " y(t)"; row[4] = " u(t)"; dataGridView1.ColumnCount = 5; dataGridView1.RowCount = 1; dataGridView1.Rows.Add(row); for (int i = 0; i < = q; i++){ row[0] = i.ToString(); row[1] = Math.Round(t[i], k).ToString(); row[2] = x1[i].ToString(); row[3] = x2[i].ToString(); if (i! = q) {row[4] = u1[i].ToString(); } else {row[4] = " "; } dataGridView1.Rows.Add(row); }} double x1_shtr(double t, double x1, double alfa, double u) { return x1 * alfa*u} double x2_shtr(double t, double x1, double alfa, double u) {return x1 *(1-u)*alfa; } private void button1_Click(object sender, EventArgs e) { double T; T = Convert.ToDouble(textBox2.Text); int q; q = 1000; double epsJ; epsJ=0.0001; double h; h = T / q; double[] t = new double[q + 1]; double[] x1 = new double[q + 1]; double[] x2 = new double[q + 1]; double[] u = new double[q];; double[] x1_1 = new double[q + 1]; double[] x2_1 = new double[q + 1]; for (int i = 0; i < = q - 1; i++) t[i + 1] = t[i] + h; for (int i = 0; i < = q - 1; i++) u[i] = 0.5; x1[0] = 1; for (int i = 0; i < = q - 1; i++) { k1 = x1_shtr(t, x1[i], alfa, U[i]); k2 = x1_shtr(t + tau / 3, x1[i] + tau / 3 * k1, alfa, U[i]); k3 = x1_shtr(t + 2*tau / 3, x1[i] + 2*tau / 3 * k2, alfa, U[i]); x1[i+1] = x1[i] + tau / 4 * (k1 + 3 * k3); t = t + tau; } x2[0] = 0; for (int i = 0; i < = q - 1; i++) { k1 = x2_shtr(t, x1[i], alfa, U[i]); k2 = x2_shtr(t + tau / 3, x1[i] + tau / 3 * k1, alfa, U[i]); k3 = x2_shtr(t + 2*tau / 3, x1[i] + 2*tau / 3 * k2, alfa, U[i]); x2[i+1] = x2[i] + tau / 4 * (k1 + 3 * k3); } J = -x2[q]; label: psi1[q] = 0; psi2[q] = 1; for (int i = q - 1; i > = 1; i--) { psi1[i] = psi1[i + 1] + psi1[i + 1] * (1 - u[i]) * h + psi2[i + 1] * u[i] * h; psi2[i] = psi2[i + 1]; } for (int i = 0; i < = q - 1; i++) {if (psi1[i + 1] > = psi2[i + 1]) u1[i] = 0; else u1[i] = 1; } x1_1[0] = 1; for (int i = 0; i < = q - 1; i++) { k1 = x1_shtr(t, x1[i]_1, alfa, U[i]); k2 = x1_shtr(t + tau / 3, x1[i]_1 + tau / 3 * k1, alfa, U[i]); k3 = x1_shtr(t + 2*tau / 3, x1[i]_1 + 2*tau / 3 * k2, alfa, U[i]); x1_1[i+1] = x1_1[i] + tau / 4 * (k1 + 3 * k3); t x2_1[0] = 0; for (int i = 0; i < = q - 1; i++) { k1 = x2_shtr(t, x1[i], alfa, U[i]); k2 = x2_shtr(t + tau / 3, x1[i] + tau / 3 * k1, alfa, U[i]); k3 = x2_shtr(t + 2*tau / 3, x1[i] + 2*tau / 3 * k2, alfa, U[i]); x2_1[i+1] = x2_1[i] + tau / 4 * (k1 + 3 * k3); } J1 = -x2_1[q]; if (J1 < J){ if (Math.Abs(J1 - J) < = epsJ) Out(q, t, x1_1, x2_1, u1, J1); else{J = J1; for (int i = 0; i < = q; i++) {x1[i] = x1_1[i]; x2[i] = x2_1[i]; } for (int i = 0; i < = q - 1; i++) u[i] = u1[i]; label; } x2[i+1] = x2[i] + tau / 6 * (k1 + 2 * k2 + 2 * k3 + k4); t = t + tau; } J = -x2[q]; label: k = 0; //погрешность между точным и численным решением х1* double max = Math.Abs(Convert. ToDouble(dataGridView1.Rows[0].Cells[2].Value) - Convert.ToDouble(dataGridView1.Rows[0].Cells[0]. Value)); for (int i = 1; i < n; i++){if (max < (Math.Abs(Convert .ToDouble(dataGridView1.Rows[i]}

Данная страница нарушает авторские права?


mylektsii.su - Мои Лекции - 2015-2024 год. (0.005 сек.)Все материалы представленные на сайте исключительно с целью ознакомления читателями и не преследуют коммерческих целей или нарушение авторских прав Пожаловаться на материал