Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Приложеня Методичка МКЭ.docx
Скачиваний:
26
Добавлен:
02.06.2015
Размер:
458.92 Кб
Скачать

Программа расчета потенциального течения жидкости

Форма 1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

using System.Drawing.Drawing2D;

namespace Потенциальный_поток

{

public partial class Form1 : Form

{

public Form2 f2;

List<string> list_st = new List<string>();

string st;

string[] St;

public Double[,] MatrCoor, MatrTop, MatrGran;

public double[] qx, qy;

public int[] cx;

public int[] cy;

public int i = 0, j = 0, n = 0, m = 0, mg = 0;

public Form1()

{

InitializeComponent();

}

private void сохранитьВФайлToolStripMenuItem_Click(object sender, EventArgs e)

{

// Сохранение в файл координатной матрицы

n = 0;

for (i = 0; i < dataGridView1.RowCount - 1; i++) n++;

MatrCoor = new double[n, 4];

for (i = 0; i < n; i++)

{

for (j = 0; j < 4; j++)

MatrCoor[i, j] = Convert.ToDouble(dataGridView1.Rows[i].Cells[j].Value);

}

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = saveFileDialog1.OpenFile() as FileStream;

StreamWriter SR = new StreamWriter(FS);

//dataGridView1.Rows.Add();

for (i = 0; i < n; i++)

{

st = null;

for (j = 0; j < 4; j++)

{

st = st + MatrCoor[i, j].ToString() + " ";

}

SR.WriteLine(st);

}

SR.Close();

FS.Close();

}

}

private void считатьИзФайлаToolStripMenuItem_Click(object sender, EventArgs e)

{

// Считывание из файла координатной матрицы

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FSR = openFileDialog1.OpenFile() as FileStream;

StreamReader SRR = new StreamReader(FSR);

dataGridView1.Rows.Clear();

list_st.Clear();

while (SRR.Peek() > 0)

{

list_st.Add(SRR.ReadLine());

//dataGridView1

dataGridView1.Rows.Add();

}

St = list_st.ToArray();

n = St.Length;

MatrCoor = new double[n, 4];

for (i = 0; i < n; i++)

{

St[i] = St[i].Replace(".", ","); ;

//Разбиение строки St на подстроки aa

string[] aa = St[i].Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

for (j = 0; j < aa.Length; j++)

{

//Заполнение матрицы и таблицы

MatrCoor[i, j] = Convert.ToDouble(aa[j]);

dataGridView1.Rows[i].Cells[j].Value = MatrCoor[i, j];

}

}

SRR.Close();

FSR.Close();

}

}

private void считатьИзФайлаToolStripMenuItem1_Click(object sender, EventArgs e)

{

// Считывание из файла топологической матрицы

tabControl1.DeselectTab(tabPage1);

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FSR = openFileDialog1.OpenFile() as FileStream;

StreamReader SRR = new StreamReader(FSR);

dataGridView2.Rows.Clear();

list_st.Clear();

while (SRR.Peek() > 0)

{

list_st.Add(SRR.ReadLine());

//dataGridView1

dataGridView2.Rows.Add();

}

St = list_st.ToArray();

m = St.Length;

MatrTop = new double[m, 7];

MatrTop = new Double[m, 7];

qx = new double[m];

qy = new double[m];

for (i = 0; i < m; i++)

{

St[i] = St[i].Replace(".", ","); ;

//Разбиение строки St на подстроки aa

string[] aa = St[i].Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

for (j = 0; j < aa.Length; j++)

{

//Заполнение матрицы и таблицы

MatrTop[i, j] = Convert.ToDouble(aa[j]);

dataGridView2.Rows[i].Cells[j].Value = MatrTop[i, j];

}

}

SRR.Close();

FSR.Close();

}

}

private void сохранитьВФайлToolStripMenuItem1_Click(object sender, EventArgs e)

{

tabControl1.DeselectTab(tabPage1);

// Сохранение в файл топологической матрицы

m = 0;

for (i = 0; i < dataGridView2.RowCount - 1; i++) m++;

MatrTop = new double[m, 7];

for (i = 0; i < m; i++)

{

for (j = 0; j < 7; j++)

MatrTop[i, j] = Convert.ToDouble(dataGridView2.Rows[i].Cells[j].Value);

}

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = saveFileDialog1.OpenFile() as FileStream;

StreamWriter SR = new StreamWriter(FS);

//dataGridView1.Rows.Add();

for (i = 0; i < m; i++)

{

st = null;

for (j = 0; j < 7; j++)

{

st = st + MatrTop[i, j].ToString() + " ";

}

SR.WriteLine(st);

}

SR.Close();

FS.Close();

}

}

private void считатьИзФойлаToolStripMenuItem_Click(object sender, EventArgs e)

{

//Считывание из файла граничных условий

tabControl1.DeselectTab(tabPage2);

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FSR = openFileDialog1.OpenFile() as FileStream;

StreamReader SRR = new StreamReader(FSR);

dataGridView3.Rows.Clear();

list_st.Clear();

while (SRR.Peek() > 0)

{

list_st.Add(SRR.ReadLine());

//dataGridView1

dataGridView3.Rows.Add();

}

St = list_st.ToArray();

mg = St.Length;

MatrGran = new double[mg, 4];

for (i = 0; i < mg; i++)

{

St[i] = St[i].Replace(".", ","); ;

//Разбиение строки St на подстроки aa

string[] aa = St[i].Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

for (j = 0; j < aa.Length; j++)

{

//Заполнение матрицы и таблицы

MatrGran[i, j] = Convert.ToDouble(aa[j]);

dataGridView3.Rows[i].Cells[j].Value = MatrGran[i, j];

}

}

SRR.Close();

FSR.Close();

}

}

private void сохранитьВФайлToolStripMenuItem2_Click(object sender, EventArgs e)

{

//Сохранение в файл граничных условий

tabControl1.DeselectTab(tabPage2);

mg = 0;

for (i = 0; i < dataGridView3.RowCount - 1; i++) mg++;

MatrGran = new double[mg, 4];

for (i = 0; i < mg; i++)

{

for (j = 0; j < 4; j++)

MatrGran[i, j] = Convert.ToDouble(dataGridView3.Rows[i].Cells[j].Value);

}

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = saveFileDialog1.OpenFile() as FileStream;

StreamWriter SR = new StreamWriter(FS);

//dataGridView1.Rows.Add();

for (i = 0; i < mg; i++)

{

st = null;

for (j = 0; j < 4; j++)

{

st = st + MatrGran[i, j].ToString() + " ";

}

SR.WriteLine(st);

}

SR.Close();

FS.Close();

}

}

private void button1_Click(object sender, EventArgs e)

{

Close();

}

public void графикToolStripMenuItem_Click(object sender, EventArgs e)

{

//Построение

double[] x, y;

Double My = 0, MaxY = 0, Mx = 0, MaxX = 0;

int[] yint, xint;

Bitmap myBmp;

x = new double[n];

y = new double[n];

cx = new int[m];

cy = new int[m];

for (i = 0; i < n; i++)

{

x[i] = MatrCoor[i, 1];

y[i] = MatrCoor[i, 2];

}

if (x == null || y == null) return;

MaxY = 0.001;

MaxX = 0.001;

for (i = 0; i < n; i++)

{

if (System.Math.Abs(y[i]) > MaxY)

{

MaxY = System.Math.Abs(y[i]); ;

}

if (System.Math.Abs(x[i]) > MaxX)

{

MaxX = System.Math.Abs(x[i]);

}

}

if (MaxY >= MaxX)

MaxX = MaxY;

else

MaxY = MaxX;

My = (pictureBox1.Height) / 1.2 / MaxY;

Mx = (pictureBox1.Width) / 1.2 / MaxX;

yint = new int[n];

xint = new int[n];

for (int i = 0; i < n; i++)

{

yint[i] = Convert.ToInt32(pictureBox1.Height / 1.1) - Convert.ToInt32(y[i] * My);

xint[i] = Convert.ToInt32(pictureBox1.Width / 10) + Convert.ToInt32(x[i] * Mx);

}

myBmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

Graphics gr1 = Graphics.FromImage(myBmp);

Pen P1 = new Pen(Color.Red, 2);

gr1.DrawRectangle(P1, 1, 1, pictureBox1.Width - 2, pictureBox1.Height - 2);

Pen P2 = new Pen(Color.Green, 2);

Pen P5 = new Pen(Color.Green, 8);

Brush B2 = new SolidBrush(Color.Azure);

Brush B21 = new SolidBrush(Color.SpringGreen);

Pen P3 = new Pen(Color.Brown, 4);

Pen P21 = new Pen(Color.Plum, 2);

Brush B22 = new SolidBrush(Color.Black);

System.Drawing.Font E = new Font("time new roman", 14);

Pen P6 = new Pen(Color.Aqua, 18);

//Закрашивание пористых элементов

for (i = 0; i < m; i++)

{

int xsk1 = xint[(int)MatrTop[i, 1] - 1];

int ysk1 = yint[(int)MatrTop[i, 1] - 1];

int xsk2 = xint[(int)MatrTop[i, 2] - 1];

int ysk2 = yint[(int)MatrTop[i, 2] - 1];

int xsk3 = xint[(int)MatrTop[i, 3] - 1];

int ysk3 = yint[(int)MatrTop[i, 3] - 1];

Point xy1 = new Point(xsk1, ysk1);

Point xy2 = new Point(xsk2, ysk2);

Point xy3 = new Point(xsk3, ysk3);

Point[] xy = { xy1, xy2, xy3 };

Brush B3 = new SolidBrush(Color.Aquamarine);

Brush B4 = new SolidBrush(Color.LightCyan);

if (MatrTop[i, 5] != 1 || MatrTop[i, 6] != 1)

{

gr1.FillPolygon(B3, xy);

}

else

{

gr1.FillPolygon(B4, xy);

}

}

//Построение участков входных скоростей

int l = 0;

if (MatrGran != null)

while (l < mg)

{

gr1.DrawLine(P6, xint[(int)MatrGran[l, 1] - 1], yint[(int)MatrGran[l, 1] - 1], xint[(int)MatrGran[l, 2] - 1], yint[(int)MatrGran[l, 2] - 1]);

l++;

}

//Построение контура элементов

for (i = 0; i < m; i++)

{

cx[i] = (int)(xint[(int)MatrTop[i, 1] - 1] + xint[(int)MatrTop[i, 2] - 1] + xint[(int)MatrTop[i, 3] - 1]) / 3;

cy[i] = (int)(yint[(int)MatrTop[i, 1] - 1] + yint[(int)MatrTop[i, 2] - 1] + yint[(int)MatrTop[i, 3] - 1]) / 3;

}

string stc;

if(checkBox2.Checked)

for (i = 0; i < m; i++)

{

stc = MatrTop[i, 0].ToString();

gr1.DrawLine(P3, xint[(int)MatrTop[i, 1] - 1], yint[(int)MatrTop[i, 1] - 1], xint[(int)MatrTop[i, 2] - 1], yint[(int)MatrTop[i, 2] - 1]);

gr1.DrawLine(P3, xint[(int)MatrTop[i, 2] - 1], yint[(int)MatrTop[i, 2] - 1], xint[(int)MatrTop[i, 3] - 1], yint[(int)MatrTop[i, 3] - 1]);

gr1.DrawLine(P3, xint[(int)MatrTop[i, 1] - 1], yint[(int)MatrTop[i, 1] - 1], xint[(int)MatrTop[i, 3] - 1], yint[(int)MatrTop[i, 3] - 1]);

cx[i] = (int)(xint[(int)MatrTop[i, 1] - 1] + xint[(int)MatrTop[i, 2] - 1] + xint[(int)MatrTop[i, 3] - 1]) / 3;

cy[i] = (int)(yint[(int)MatrTop[i, 1] - 1] + yint[(int)MatrTop[i, 2] - 1] + yint[(int)MatrTop[i, 3] - 1]) / 3;

gr1.DrawString(MatrTop[i, 0].ToString(), E, B22, cx[i], cy[i]);

gr1.DrawRectangle(P21, cx[i], cy[i], stc.Length * 12 + 4, 23);

}

Brush B33 = new SolidBrush(Color.Black);

System.Drawing.Font E1 = new Font("time new roman", 14);

if (checkBox1.Checked)

for (i = 0; i < n; i++)

{

if (MatrCoor[i, 3] != 0)

{

gr1.FillEllipse(B21, xint[i] - 8, yint[i] - 8, 16, 16);

gr1.DrawEllipse(P2, xint[i] - 8, yint[i] - 8, 16, 16);

}

else

{

gr1.FillEllipse(B2, xint[i] - 4, yint[i] - 4, 8, 8);

}

int ii = i + 1;

gr1.DrawEllipse(P2, xint[i] - 4, yint[i] - 4, 8, 8);

int ii1 = i + 1;

Brush B13 = new SolidBrush(Color.DarkBlue);

System.Drawing.Font E11 = new Font("time new roman", 10);

gr1.DrawString(ii1.ToString(), E11, B13, xint[i] - 18, yint[i] - 18);

}

//Построение скоростей потока

Pen P4 = new Pen(Color.Indigo, 6);

// Стиль пера с наконечниками

P4.SetLineCap(LineCap.Flat, LineCap.ArrowAnchor, DashCap.Flat);

int[] iqx, iqy;

iqx = new int[m];

iqy = new int[m];

if (qx != null || qy != null)

{

double Maxqx = 0.001;

double Maxqy = 0.001;

for (i = 0; i < m; i++)

{

if (System.Math.Abs(qx[i]) > Maxqx)

{

Maxqx = System.Math.Abs(qx[i]); ;

}

if (System.Math.Abs(qy[i]) > Maxqy)

{

Maxqy = System.Math.Abs(qy[i]);

}

}

if (Maxqy >= Maxqx)

Maxqx = Maxqy;

else

Maxqy = Maxqx;

double Mvy = (pictureBox1.Height) / 8 / Maxqx;

double Mvx = (pictureBox1.Width) / 8 / Maxqx;

for (i = 0; i < m; i++)

{

iqx[i] = Convert.ToInt32(qx[i] * Mvx);

iqy[i] = -Convert.ToInt32(qy[i] * Mvx);

gr1.DrawLine(P4, cx[i], cy[i], cx[i] + iqx[i], cy[i] + iqy[i]);

}

}

pictureBox1.Image = myBmp;

}

private void рассчетToolStripMenuItem_Click(object sender, EventArgs e)

{

//Расчет

f2 = new Form2(this);

f2.Show();

}

}

}

Форма 2

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

namespace Потенциальный_поток

{

public partial class Form2 : Form

{

Form1 f1;

public Double[,] MatrCoor, MatrTop, MatrGran;

public double[,] K, Ke, K1;

public double[] P, P1, u;

public Form2(Form1 f1)

{

InitializeComponent();

this.f1 = f1;

this.MatrCoor = f1.MatrCoor;

this.MatrTop = f1.MatrTop;

this.MatrGran = f1.MatrGran;

Demo();

}

void Demo()

{

int[,] IM;

IM = new int[f1.m, 3];

for (int i = 0; i < f1.n - 1; i++)

{ // Добавление колонки

DataGridViewTextBoxColumn titleColumn1 = new DataGridViewTextBoxColumn();

titleColumn1.HeaderText = "Titlt" + (i + 2).ToString();

//Выравнивание ширины колонки в соответствии с заданным стилем - AllCells

titleColumn1.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;

dataGridView1.Columns.Add(titleColumn1);

dataGridView1.Rows.Add();

dataGridView2.Rows.Add();

}

//Формирование матрицы индексов

for (int i = 0; i < f1.m; i++)

{

for (int j = 0; j < 3; j++)

{

IM[i, j] = Convert.ToInt32(MatrTop[i, j + 1] - 1);

//dataGridView1.Rows[i].Cells[j].Value = IM[i, j];

}

}

K = new double[f1.n, f1.n];

//Формирование матрицы коэффициентов влияния

for (int i = 0; i < f1.m; i++)

{

int n1 = IM[i, 0];

int n2 = IM[i, 1];

int n3 = IM[i, 2];

Double x1 = MatrCoor[n1, 1] * Math.Cos(MatrTop[i, 4]) + MatrCoor[n1, 2] * Math.Sin(MatrTop[i, 4]);

Double y1 = MatrCoor[n1, 2] * Math.Cos(MatrTop[i, 4]) - MatrCoor[n1, 1] * Math.Sin(MatrTop[i, 4]);

Double x2 = MatrCoor[n2, 1] * Math.Cos(MatrTop[i, 4]) + MatrCoor[n2, 2] * Math.Sin(MatrTop[i, 4]);

Double y2 = MatrCoor[n2, 2] * Math.Cos(MatrTop[i, 4]) - MatrCoor[n2, 1] * Math.Sin(MatrTop[i, 4]);

Double x3 = MatrCoor[n3, 1] * Math.Cos(MatrTop[i, 4]) + MatrCoor[n3, 2] * Math.Sin(MatrTop[i, 4]);

Double y3 = MatrCoor[n3, 2] * Math.Cos(MatrTop[i, 4]) - MatrCoor[n3, 1] * Math.Sin(MatrTop[i, 4]);

Double a1 = x3 - x2;

Double a2 = x1 - x3;

Double a3 = x2 - x1;

Double b1 = y2 - y3;

Double b3 = y1 - y2;

Double b2 = y3 - y1;

Double F2 = b1 * a2 - b2 * a1;

Double sx = MatrTop[i, 5];

Double sy = MatrTop[i, 6];

Double[,] fk = new Double[3, 3];

fk[0, 0] = (sx * b1 * b1 + sy * a1 * a1) / (2* F2);

fk[1, 1] = (sx * b2 * b2 + sy * a2 * a2) / (2*F2);

fk[2, 2] = (sx * b3 * b3 + sy * a3 * a3) / (2* F2);

fk[0, 1] = (sx * b1 * b2 + sy * a1 * a2) / (2* F2);

fk[0, 2] = (sx * b1 * b3 + sy * a1 * a3) / (2* F2);

fk[1, 2] = (sx * b3 * b2 + sy * a3 * a2) / (2* F2);

fk[1, 0] = fk[0, 1];

fk[2, 0] = fk[0, 2];

fk[2, 1] = fk[1, 2];

for (int l = 0; l < 3; l++)

{

int ll = IM[i, l];

for (int z = 0; z < 3; z++)

{

int zz = IM[i, z];

K[ll, zz] = K[ll, zz] + fk[l, z];

}

}

}

P = new double[f1.n];

for (int i = 0; i < MatrGran.Length / 4; i++)

{

int ll = Convert.ToInt32(MatrGran[i, 1]) - 1;

int zz = Convert.ToInt32(MatrGran[i, 2]) - 1;

double L = Math.Sqrt(Math.Pow((MatrCoor[ll, 1] - MatrCoor[zz, 1]), 2) + Math.Pow((MatrCoor[ll, 2] - MatrCoor[zz, 2]), 2));

P[ll] = P[ll] + MatrGran[i, 3] /2*L;

P[zz] = P[zz] + MatrGran[i, 3] /2*L;

}

//Копирование матриц

K1 = new double[f1.n, f1.n];

P1 = new double[f1.n];

for (int i = 0; i < f1.n; i++)

{

P1[i] = P[i];

//dataGridView1.Rows[i].Cells[0].Value = P[i];

for (int j = 0; j < f1.n; j++)

{

K1[i, j] = K[i, j];

//dataGridView1.Rows[i].Cells[j].Value = K[i, j];

}

}

//Главные граничные условия

for (int i = 0; i < f1.n; i++)

{

if (MatrCoor[i, 3] != 0)

{

for (int j = 0; j < f1.n; j++)

{

if (i != j)

{

K1[i, j] = 0;

}

}

K1[i, i] = K[i, i];

P1[i] = MatrCoor[i, 3] * K[i, i];

// dataGridView1.Rows[i].Cells[0].Value = P1[i];

}

}

u = new double[f1.n];

for (int i = 0; i < f1.n; i++)

{

u[i] = P1[i];

}

int KS = 0;

ClassSIMQ S = new ClassSIMQ();

S.SIMQ(K1, ref u, f1.n, ref KS);

label1.Text = "Код ошибки равен " + KS.ToString();

for (int i = 0; i < f1.n; i++)

{

dataGridView2.Rows[i].Cells[0].Value = u[i];

for (int j = 0; j < f1.n; j++)

{

dataGridView1.Rows[i].Cells[j].Value = K1[i, j];

}

}

//Расчет скоростей

double[] vx = new double[f1.m];

double[] vx1 = new double[f1.m];

double[] vy = new double[f1.m];

double[] vy1 = new double[f1.m];

double[] v = new double[f1.m];

for (int i = 0; i < f1.m; i++)

{

int n1 = IM[i, 0];

int n2 = IM[i, 1];

int n3 = IM[i, 2];

Double x1 = MatrCoor[n1, 1] * Math.Cos(MatrTop[i, 4]) + MatrCoor[n1, 2] * Math.Sin(MatrTop[i, 4]);

Double y1 = MatrCoor[n1, 2] * Math.Cos(MatrTop[i, 4]) - MatrCoor[n1, 1] * Math.Sin(MatrTop[i, 4]);

Double x2 = MatrCoor[n2, 1] * Math.Cos(MatrTop[i, 4]) + MatrCoor[n2, 2] * Math.Sin(MatrTop[i, 4]);

Double y2 = MatrCoor[n2, 2] * Math.Cos(MatrTop[i, 4]) - MatrCoor[n2, 1] * Math.Sin(MatrTop[i, 4]);

Double x3 = MatrCoor[n3, 1] * Math.Cos(MatrTop[i, 4]) + MatrCoor[n3, 2] * Math.Sin(MatrTop[i, 4]);

Double y3 = MatrCoor[n3, 2] * Math.Cos(MatrTop[i, 4]) - MatrCoor[n3, 1] * Math.Sin(MatrTop[i, 4]);

Double a1 = x3 - x2;

Double a2 = x1 - x3;

Double a3 = x2 - x1;

Double b1 = y2 - y3;

Double b3 = y1 - y2;

Double b2 = y3 - y1;

Double F2 = b1 * a2 - b2 * a1;

Double sx = MatrTop[i, 5];

Double sy = MatrTop[i, 6];

Double u1 = u[n1];

Double u2 = u[n2];

Double u3 = u[n3];

vx[i] = 1.0/F2* sx * (b1 * u1 + b2 * u2 + b3 * u3);

vy[i] = 1.0/F2* sy * (a1 * u1 + a2 * u2 + a3 * u3);

vx1[i] = vx[i] * Math.Cos(MatrTop[i, 4]) - vy[i] * Math.Sin(MatrTop[i, 4]);

vy1[i] = vx[i] * Math.Sin(MatrTop[i, 4]) + vy[i] * Math.Cos(MatrTop[i, 4]);

dataGridView3.Rows.Add();

dataGridView3.Rows[i].Cells[0].Value = i + 1;

dataGridView3.Rows[i].Cells[1].Value = vx1[i];

dataGridView3.Rows[i].Cells[2].Value = vy1[i];

f1.qx[i] = vx1[i];

f1.qy[i] = vy1[i];

v[i] = Math.Sqrt(vx1[i] * vx1[i] + vy1[i] * vy1[i]);

dataGridView3.Rows[i].Cells[3].Value = v[i];

}

}

private void button1_Click(object sender, EventArgs e)

{

//Построение

f1.графикToolStripMenuItem_Click(sender, e);

f1.Activate();

}

}

}

Класс ClassSIMQ

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Потенциальный_поток

{

class ClassSIMQ

{

double[] A, B;

public void SIMQ(double[,] K, ref double[] P, int N, ref int KS)

{

A = new double[N * N + 1];

B = new double[N + 1];

int sd = 0;

for (int i = 0; i < N; i++)

{

B[i + 1] = P[i];

for (int j = 0; j < N; j++)

{

sd++;

A[sd] = K[j, i];

}

}

int JY, IT, J, IJ, IMAX = 0, I, I1, k, I2, IQS, IX, JX, IXJX, JJX, IXJ, NY, IB, IA, IC;

double TOL = 0, BIGA = 0, SAVE;

KS = 0;

int JJ = -N;

for (J = 1; J <= N; J++)

{

JY = J + 1;

JJ = JJ + N + 1;

BIGA = 0.0;

IT = JJ - J;

for (I = J; I <= N; I++)

{

IJ = IT + I;

if (Math.Abs(BIGA) - Math.Abs(A[IJ]) < 0)

{

BIGA = A[IJ];

IMAX = I;

}

}//30

if (Math.Abs(BIGA) - TOL <= 0)

{

KS = 1;

return;

}

I1 = J + N * (J - 2);

IT = IMAX - J;

for (k = J; k <= N; k++)

{

I1 = I1 + N;

I2 = I1 + IT;

SAVE = A[I1];

A[I1] = A[I2];

A[I2] = SAVE;

A[I1] = A[I1] / BIGA;

}//50

SAVE = B[IMAX];

B[IMAX] = B[J];

B[J] = SAVE / BIGA;

if ((J - N) == 0)

{

break;

}

IQS = N * (J - 1);

for (IX = JY; IX <= N; IX++)

{

IXJ = IQS + IX;

IT = J - IX;

for (JX = JY; JX <= N; JX++)

{

IXJX = N * (JX - 1) + IX;

JJX = IXJX + IT;

A[IXJX] = A[IXJX] - A[IXJ] * A[JJX];

}

B[IX] = B[IX] - B[J] * A[IXJ];

}

}//65

NY = N - 1;

IT = N * N;

for (J = 1; J <= NY; J++)

{

IA = IT - J;

IB = N - J;

IC = N;

for (k = 1; k <= J; k++)

{

B[IB] = B[IB] - A[IA] * B[IC];

IA = IA - N;

IC = IC - 1;

}

}//80

for (int i = 0; i < N; i++)

{

P[i] = B[i + 1];

}

}

}

}

Экранные формы:

Форма 1.

Форма 2.

ПРИЛОЖЕНИЕ 4

Программа исследования вращения твердого тела

Форма 1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.Drawing.Drawing2D;

namespace WindowsFormsApplicationL4

{

public partial class Form1 : Form

{

//Описание делегата

public delegate Double y(Double x1, Double x2);

Double a=-10, b=10, h=0.1,w=0;

double[] T, Y, Iny;

int i,n;

Bitmap myBmp, myBmp2;

double Mx, My, My1, MaxY1, MaxY, MaxT;

public Form1()

{

InitializeComponent();

}

private void button1_Click(object sender, EventArgs e)

{ // Вычисление

dataGridView1.Rows.Clear();

a = Convert.ToDouble(textBox1.Text);

b = Convert.ToDouble(textBox2.Text);

h = Convert.ToDouble(textBox3.Text);

w = Convert.ToDouble(textBox4.Text);

// Создание экземпляра делегата

y fx;

fx = null;

int s = 0;

//MS = new System.MessageBox.messageBox(this) ;

if (this.radioButton1.Checked) s = 1;

if (this.radioButton2.Checked) s = 2;

if (this.radioButton3.Checked) s = 3;

switch (s)

{

// Использование делегата

case 1: fx = new y(fx1); break;

case 2: fx = new y(fx2); break;

case 3: fx = new y(fx3); break;

default:

String Str="Выберите функцию";

//Вывод сообщения

MessageBox.Show(Str,"Ошибка",MessageBoxButtons.OK, MessageBoxIcon.Warning);

return;

}

//Вызов процедуры вычисления интеграла

Integral(a, b, h, fx);

}

private void button2_Click(object sender, EventArgs e)

{ // Выход

Close();

}

// Процедура вычисления интеграла с переменным верхним

//пределом методом тарпеций и заполнение таблицы

void Integral(double a1, double b1, double h1, y f)

{

n = Convert.ToInt32(Math.Abs((b1 - a1) / h1));

Y = new double[n + 1];

T = new double[n + 1];

Iny = new double[n + 1];

T[0] = a1;

Y[0] = f(T[0], w);

Iny[0] = w;

for (i = 1; i < n + 1; i++)

{

dataGridView1.Rows.Add();

T[i] = a1 + i * h1;

Y[i] = f(T[i],Iny[i-1]);

Iny[i] = Iny[i - 1] + (Y[i] + Y[i - 1]) / 2 * h1;

}

for (i = 0; i < n + 1; i++)

{ // Заполнение таблицы

dataGridView1.Rows[i].Cells[0].Value = i;

dataGridView1.Rows[i].Cells[1].Value = T[i];

dataGridView1.Rows[i].Cells[2].Value = Y[i];

dataGridView1.Rows[i].Cells[3].Value = Iny[i];

}

}

// Функции соответствующие делегату y(x)

double fx1(Double x1, Double x2)

{

if (x2 < 300)

{

return (600 - 15 * x1-2*x1*x1);

}

else

{

return (300-30*x1-2*x1*x1);

}

}

double fx2(Double x1, Double x2)

{

return - 2*x1 * x1;

}

double fx3(Double x1, Double x2)

{

if (x2 < 300 )

{

return 600 - 15 * x1 ;

}

else

{

return 300 - 30 * x1 ;

}

}

// Построение

private void button3_Click(object sender, EventArgs e)

{

// Построение графика

int[] yint, y1int, xint;

if (T == null || Y == null || Iny == null) return;

MaxY = 0;

MaxT = 0;

MaxY1 = 0;

myBmp = new Bitmap(pictureBox1.Width, pictureBox1.Height);

Graphics gr1 = Graphics.FromImage(myBmp);

Pen P1 = new Pen(Color.Red, 2);

gr1.DrawRectangle(P1, 1, 1, pictureBox1.Width - 2, pictureBox1.Height - 2);

for (int i = 0; i < n + 1; i++)

{

if (System.Math.Abs(Y[i]) > MaxY)

{

MaxY = System.Math.Abs(Y[i]); ;

}

if (System.Math.Abs(T[i]) > MaxT)

{

MaxT = System.Math.Abs(T[i]);

}

if (System.Math.Abs(Iny[i]) > MaxY1)

{

MaxY1 = System.Math.Abs(Iny[i]);

}

}

My = (pictureBox1.Height) / 2.2 / MaxY;

My1 = (pictureBox1.Height) / 2.8 / MaxY1;

Mx = (pictureBox1.Width) / 1.2 / MaxT;

yint = new int[n + 1];

y1int = new int[n + 1];

xint = new int[n + 1];

for (int i = 0; i < n + 1; i++)

{

yint[i] = (pictureBox1.Height) / 2 - Convert.ToInt32(Y[i] * My);

y1int[i] = (pictureBox1.Height) / 2 - Convert.ToInt32(Iny[i] * My1);

xint[i] = 20 + Convert.ToInt32(T[i] * Mx);

}

Pen P2 = new Pen(Color.Green, 6);

for (int i = 0; i < n; i++)

{

gr1.DrawLine(P2, xint[i], yint[i], xint[i + 1], yint[i + 1]);

}

Pen P3 = new Pen(Color.Brown, 6);

for (int i = 0; i < n; i++)

{

gr1.DrawLine(P3, xint[i], y1int[i], xint[i + 1], y1int[i + 1]);

}

Pen P4 = new Pen(Color.Black, 3);

//Стиль линии с наконечниками

P4.SetLineCap(LineCap.Flat, LineCap.ArrowAnchor, DashCap.Flat);

//Кисть для шрифта на рисунке

Brush B2 = new SolidBrush(Color.Black);

System.Drawing.Font E = new Font("time new roman", 14);

// Вывод надписей на рисунке

gr1.DrawString("y, Инт.y", E, B2, 30, 0);

gr1.DrawString("t", E, B2, pictureBox1.Width - 20, pictureBox1.Height / 2);

gr1.DrawLine(P4, 10, (pictureBox1.Height) / 2, pictureBox1.Width - 10, (pictureBox1.Height) / 2);

gr1.DrawLine(P4, 20, (pictureBox1.Height) - 10, 20, 10);

pictureBox1.Image = myBmp;

legenda();

}

void legenda()

{// Вывод легенды

myBmp2 = new Bitmap(pictureBox2.Width, pictureBox2.Height);

Graphics gr1 = Graphics.FromImage(myBmp2);

Pen P1 = new Pen(Color.Green, 6);

gr1.DrawLine(P1, pictureBox2.Width / 2, 20, pictureBox2.Width - 10, 20);

Pen P2 = new Pen(Color.Brown, 6);

gr1.DrawLine(P2, pictureBox2.Width / 2, 50, pictureBox2.Width - 10, 50);

Brush B2 = new SolidBrush(Color.Black);

System.Drawing.Font E = new Font("time new roman", 14);

gr1.DrawString("y(t)", E, B2, 7, 7);

gr1.DrawString("Инт.y", E, B2, 7, 37);

pictureBox2.Image = myBmp2;

}

}

}

Экранная форма

ПРИЛОЖЕНИЕ 5

Программа расчета условий равновесия системы сил

Форма 1

using System;

using System.Collections.Generic;

using System.ComponentModel;

using System.Data;

using System.Drawing;

using System.Linq;

using System.Text;

using System.Windows.Forms;

using System.IO;

namespace Равновесие_системы_сил

{

public partial class Form1 : Form

{

double[,] MatrA;

double[] MatrB;

int i, j;

int m = 6;

string st;

List<string> list_st = new List<string>();

string[] St;

public Form1()

{

InitializeComponent();

}

private void выходToolStripMenuItem_Click(object sender, EventArgs e)

{

Close();

}

private void сохранитьВФайлToolStripMenuItem_Click(object sender, EventArgs e)

{

// Сохранение в файл исходной матрицы

MatrA = new double[m, m];

for (i = 0; i < m; i++)

{

for (j = 0; j < m; j++)

MatrA[i, j] = Convert.ToDouble(dataGridView3.Rows[i].Cells[j].Value);

}

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = saveFileDialog1.OpenFile() as FileStream;

StreamWriter SR = new StreamWriter(FS);

for (i = 0; i < m; i++)

{

st = null;

for (j = 0; j < m; j++)

{

st = st + MatrA[i, j].ToString() + " ";

}

SR.WriteLine(st);

}

SR.Close();

FS.Close();

}

}

private void считатьИзФайлаToolStripMenuItem_Click(object sender, EventArgs e)

{

// Считывание из файла исходной матрицы

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = openFileDialog1.OpenFile() as FileStream;

StreamReader SR = new StreamReader(FS);

dataGridView3.Rows.Clear();

list_st.Clear();

while (SR.Peek() > 0)

{

list_st.Add(SR.ReadLine());

//dataGridView1

dataGridView3.Rows.Add();

}

St = list_st.ToArray();

MatrA = new double[m, m];

for (i = 0; i < m; i++)

{

St[i] = St[i].Replace(".", ","); ;

//Разбиение строки St на подстроки aa

string[] aa = St[i].Split(" \t".ToCharArray(), StringSplitOptions.RemoveEmptyEntries);

for (j = 0; j < m; j++)

{

//Заполнение матрицы и таблицы

MatrA[i, j] = Convert.ToDouble(aa[j]);

dataGridView3.Rows[i].Cells[j].Value = MatrA[i, j];

}

}

SR.Close();

FS.Close();

}

}

private void cToolStripMenuItem_Click(object sender, EventArgs e)

{

// Считывание из файла вектор-столбца

if (openFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = openFileDialog1.OpenFile() as FileStream;

StreamReader SR = new StreamReader(FS);

dataGridView2.Rows.Clear();

list_st.Clear();

while (SR.Peek() > 0)

{

list_st.Add(SR.ReadLine());

//dataGridView1

dataGridView2.Rows.Add();

}

St = list_st.ToArray();

MatrB = new double[m];

for (i = 0; i < m; i++)

{

St[i] = St[i].Replace(".", ","); ;

//Заполнение матрицы и таблицы

MatrB[i] = Convert.ToDouble(St[i]);

dataGridView2.Rows[i].Cells[0].Value = MatrB[i];

}

SR.Close();

FS.Close();

}

}

private void сохранитьВВайлToolStripMenuItem_Click(object sender, EventArgs e)

{

// Сохранение в файл вектор-столбца

MatrB = new double[m];

for (i = 0; i < m; i++)

{

MatrB[i] = Convert.ToDouble(dataGridView2.Rows[i].Cells[0].Value);

}

if (saveFileDialog1.ShowDialog() == DialogResult.OK)

{

FileStream FS = saveFileDialog1.OpenFile() as FileStream;

StreamWriter SR = new StreamWriter(FS);

for (i = 0; i < m; i++)

{

st = null;

st = MatrB[i].ToString() + " ";

SR.WriteLine(st);

}

SR.Close();

FS.Close();

}

}

private void вычислениеНеизвестныхToolStripMenuItem_Click(object sender, EventArgs e)

{

int KS = 0;

double[] MB = new double[6];

for (i = 0; i < m; i++)

{

MB[i]=MatrB[i];

}

ClassSIMQ S = new ClassSIMQ();

S.SIMQ(MatrA, ref MB, m, ref KS);

label1.Text = "Код ошибки равен " + KS.ToString();

for (i = 0; i < m; i++)

{

//Заполнение таблицы S

dataGridView1.Rows[0].Cells[i].Value = MB[i];

}

}

}

}

Класс ClassSIMQ

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

namespace Равновесие_системы_сил

{

class ClassSIMQ

{

double[] A, B;

public void SIMQ(double[,] K, ref double[] P, int N, ref int KS)

{

A = new double[N * N + 1];

B = new double[N + 1];

int sd = 0;

for (int i = 0; i < N; i++)

{

B[i + 1] = P[i];

for (int j = 0; j < N; j++)

{

sd++;

A[sd] = K[j, i];

}

}

int JY, IT, J, IJ, IMAX = 0, I, I1, k, I2, IQS, IX, JX, IXJX, JJX, IXJ, NY, IB, IA, IC;

double TOL = 0, BIGA = 0, SAVE;

KS = 0;

int JJ = -N;

for (J = 1; J <= N; J++)

{

JY = J + 1;

JJ = JJ + N + 1;

BIGA = 0.0;

IT = JJ - J;

for (I = J; I <= N; I++)

{

IJ = IT + I;

if (Math.Abs(BIGA) - Math.Abs(A[IJ]) < 0)

{

BIGA = A[IJ];

IMAX = I;

}

}//30

if (Math.Abs(BIGA) - TOL <= 0)

{

KS = 1;

return;

}

I1 = J + N * (J - 2);

IT = IMAX - J;

for (k = J; k <= N; k++)

{

I1 = I1 + N;

I2 = I1 + IT;

SAVE = A[I1];

A[I1] = A[I2];

A[I2] = SAVE;

A[I1] = A[I1] / BIGA;

}//50

SAVE = B[IMAX];

B[IMAX] = B[J];

B[J] = SAVE / BIGA;

if ((J - N) == 0)

{

break;

}

IQS = N * (J - 1);

for (IX = JY; IX <= N; IX++)

{

IXJ = IQS + IX;

IT = J - IX;

for (JX = JY; JX <= N; JX++)

{

IXJX = N * (JX - 1) + IX;

JJX = IXJX + IT;

A[IXJX] = A[IXJX] - A[IXJ] * A[JJX];

}

B[IX] = B[IX] - B[J] * A[IXJ];

}

}//65

NY = N - 1;

IT = N * N;

for (J = 1; J <= NY; J++)

{

IA = IT - J;

IB = N - J;

IC = N;

for (k = 1; k <= J; k++)

{

B[IB] = B[IB] - A[IA] * B[IC];

IA = IA - N;

IC = IC - 1;

}

}//80

for (int i = 0; i < N; i++)

{

P[i] = B[i + 1];

}

}

}

}

Экранная форма проекта