- 01
- 02
- 03
- 04
- 05
- 06
- 07
- 08
- 09
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
- 22
- 23
- 24
- 25
- 26
- 27
- 28
- 29
- 30
- 31
- 32
- 33
- 34
- 35
- 36
- 37
- 38
- 39
- 40
- 41
- 42
- 43
- 44
- 45
- 46
- 47
- 48
- 49
- 50
- 51
- 52
- 53
- 54
- 55
- 56
- 57
- 58
- 59
- 60
- 61
- 62
- 63
- 64
- 65
- 66
- 67
- 68
- 69
- 70
- 71
- 72
- 73
- 74
- 75
- 76
- 77
- 78
- 79
- 80
- 81
- 82
- 83
- 84
- 85
- 86
- 87
- 88
- 89
namespace Рунге_Кутты_1._4
{
public partial class Form1 : Form
{
double x0 = 1, y0 = 2, z0 = 4, t0 = 0, T = 1, h = 0.001, Eps = 0.000001, fx, fy, fz, xx, yy, zz, Ex, Ey, Ez, Eps1;
double[] x = new double[4]; double[] y = new double[4]; double[] z = new double[4];
double[] Kx = new double[4]; double[] Ky = new double[4]; double[] Kz = new double[4];
bool a;
public void Calculates()
{
System.IO.File.Delete(@"C:\Results\results.dat");
x[0] = x0; y[0] = y0; z[0] = z0;
while (t0 <= T)
{
for (int i = 0; i <= 3; i++)
{
fx = -y[i] - z[i];
fy = x[i] + 0.2 * y[i];
fz = 0.2 + (x[i] - 5.7) * z[i];
Kx[i] = h * fx;
Ky[i] = h * fy;
Kz[i] = h * fz;
x[1] = x[0] + 0.5 * Kx[0];
x[2] = x[0] + 0.5 * Kx[1];
x[3] = x[0] + Kx[2];
y[1] = y[0] + 0.5 * Ky[0];
y[2] = y[0] + 0.5 * Ky[1];
y[3] = y[0] + Ky[2];
z[1] = z[0] + 0.5 * Kz[0];
z[2] = z[0] + 0.5 * Kz[1];
z[3] = z[0] + Kz[2];
}
Ex = Math.Abs(2 * (Kx[0] - Kx[1] - Kx[2] + Kx[3]) / 3);
Ey = Math.Abs(2 * (Ky[0] - Ky[1] - Ky[2] + Ky[3]) / 3);
Ez = Math.Abs(2 * (Kz[0] - Kz[1] - Kz[2] + Kz[3]) / 3);
Eps1 = Eps / 8;
a = Check();
if (a == false)
{
xx = x[0] + (Kx[0] + 2 * Kx[1] + 2 * Kx[2] + Kx[3]) / 6;
yy = y[0] + (Ky[0] + 2 * Ky[1] + 2 * Ky[2] + Ky[3]) / 6;
zz = z[0] + (Kz[0] + 2 * Kz[1] + 2 * Kz[2] + Kz[3]) / 6;
x[0] = xx;
y[0] = yy;
z[0] = zz;
t0 += h;
string f1 = Convert.ToString(xx);
string f2 = Convert.ToString(yy);
string f3 = Convert.ToString(zz);
string[] f = new string[] { f1, f2, f3 };
string path = @"C:\Results\results.dat";
string appendtext = xx + " " + yy + " " + zz + Environment.NewLine;
System.IO.File.AppendAllText(path, appendtext);
}
}
}
public bool Check()
{
bool a;
if (Ex > Eps | Ey > Eps | Ez > Eps)
{
a = true;
h /= 2;
Calculates();
}
else a = false;
return a;
}
public Form1()
{
InitializeComponent();
Calculates();
DrawGraph();
}
public void DrawGraph()
{
GraphPane pane = zedGraph.GraphPane;
pane.CurveList.Clear();
PointPairList list = new PointPairList();
for (t0 = 0; t0 <= T; t0 += h)
{
list.Add(t0, x[0]);
}
LineItem MyCurve = pane.AddCurve("x(t)", list, Color.Blue, SymbolType.None);
zedGraph.AxisChange();
zedGraph.Invalidate();
}
}
}
пытаюсь вывести решения в виде графика. выводится только последнее решение из цикла