using System using System Collections Generic using System Drawing usi

 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
75
76
77
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
namespace LR2
{
class BraunMethod
{
PictureBox pictureBox;
RichTextBox richTextBox;
Graphics g;
float scale = 35;
public BraunMethod(PictureBox pictureBox, RichTextBox richTextBox, float scale = 35)
{
this.scale = scale;
this.pictureBox = pictureBox;
this.richTextBox = richTextBox;
if (pictureBox != null)
{
g = pictureBox.CreateGraphics();
g.TranslateTransform(pictureBox.Width / 2, pictureBox.Height / 2);
g.Clear(Color.White);
g.DrawLine(Pens.Black, 0, -200, 0, 200);
g.DrawLine(Pens.Black, -200, 0, 200, 0);
drawGraphic();
}
}
public void solve(double eps, PointF startPoint)
{
richTextBox.Text = string.Empty;
PointF cloned = new PointF(startPoint.X, startPoint.Y);
PointF curPoint, nextPoint = startPoint;
double curQ = 1e9, curP = 1e9;
richTextBox.Text += "xk = " + nextPoint.X.ToString() + ";\nyk = " + nextPoint.Y + ";\n\n";
while (Math.Max(Math.Abs(curQ), Math.Abs(curP)) > eps)
{
curPoint = nextPoint;
double xkv = curPoint.X - (curPoint.Y + curPoint.X * curPoint.X + 1) / (2 * curPoint.X);
curQ = ((curPoint.Y * curPoint.Y + 2 * xkv - 1) * 2 * curPoint.X)
/ (2 * curPoint.X * 2 * curPoint.Y - 1 * 2);
curP = (curPoint.Y + curPoint.X * curPoint.X + 1 - curQ * 1) / (2 * curPoint.X);
nextPoint.X = curPoint.X - (float)curP;
nextPoint.Y = curPoint.Y - (float)curQ;
g.DrawLine(Pens.Black, scale * curPoint.X, -scale * curPoint.Y, nextPoint.X * scale, -nextPoint.Y * scale);
g.FillEllipse(Brushes.Red, nextPoint.X * scale - 2, -nextPoint.Y * scale - 2, 4, 4);
richTextBox.Text += "xk = " + nextPoint.X.ToString() + ";\nyk = " + nextPoint.Y + ";\n\n";
}
g.FillEllipse(Brushes.Blue, cloned.X * scale - 3, -cloned.Y * scale - 3, 6, 6);
g.FillEllipse(Brushes.Green, nextPoint.X * scale - 3, -nextPoint.Y * scale - 3, 6, 6);
}
private bool isEqualNull(double x)
{
return Math.Abs(x) <= 1e-8;
}
private void drawGraphic()
{
float x, y1, y2, _y2;
for (x = -4; x < 4; x += (float)0.01)
{
y1 = -1 - x * x;
y2 = (float)Math.Sqrt((1.0 - 2 * (double)x));
_y2 = -(float)Math.Sqrt((1.0 - 2 * (double)x));
g.FillEllipse(Brushes.Blue, (float)(x * scale - 1), (float)(-y1 * scale - 1), 2, 2);
g.FillEllipse(Brushes.Cyan, (float)(x * scale - 1), (float)(-y2 * scale - 1), 2, 2);
g.FillEllipse(Brushes.Cyan, (float)(x * scale - 1), (float)(-_y2 * scale - 1), 2, 2);
}
}
}
}