using System using System Collections Generic using System ComponentMo

 1
 2
 3
 4
 5
 6
 7
 8
 9
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
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 Численные_методы_решения_ДУ {
public partial class Form1 : Form {
public Form1() {
InitializeComponent();
chart1.Series[0].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Line;
chart1.Series[1].ChartType = System.Windows.Forms.DataVisualization.Charting.SeriesChartType.Point;
}
// +++
public static double GetExactSolution(double x) {
double retValue = 0.0666667 * Math.Pow(Math.E, -2.0 * x) +
0.363254 * Math.Pow(Math.E, x) -
0.000260118 * Math.Pow(Math.E, 3.0 * x);
return retValue;
}
private void Form1_Load(object sender, EventArgs e) {
KeyValuePair<double, double> alpha = new KeyValuePair<double, double>(3.0, -1.2),
beta = new KeyValuePair<double, double>(-2.1, 5.0);
double a = 1.8,
b = 2.9,
h = 0.05,
A = 4.0,
B = -1.0;
Matrix coeff = CollocationMethod.GetCoeff(alpha, beta, a, b, A, B);
double sigma = coeff[0, 0],
gamma = coeff[1, 0];
List<double> xValue = new List<double>(),
yValue = new List<double>(),
xX = new List<double>(new double[] { 2.00, 2.36, 2.40 }),
yCollocation = new List<double>(),
yFD = new List<double>(),
yReduction = new List<double>();
for (double x = a; x <= b; x += h) {
xValue.Add(x);
yValue.Add(GetExactSolution(x));
}
int n = xValue.Count;
for (int i = 0; i < n; ++i) {
yCollocation.Add(CollocationMethod.GetY(beta, a, b, xValue[i], sigma, gamma, xX));
}
for (int i = 0; i < n; ++i) {
tb_x.AppendText(String.Format("{0:f5}\n", xValue[i]));
tb_exactY.AppendText(String.Format("{0:f5}\n", yValue[i]));
// результаты метода коллокаций
tb_y.AppendText(String.Format("{0:f5}\n", yCollocation[i]));
chart1.Series[0].Points.AddXY(xValue[i], yValue[i]);
chart1.Series[1].Points.AddXY(xValue[i], yCollocation[i]);
chart4.Series[0].Points.AddXY(xValue[i], yValue[i] - yCollocation[i]);
}
}
}
}