void draw() { double t0 = 0, tmax = Math.PI, eps = 10E-6; int n = 1000; Font f = new Font(FontFamily.GenericSerif, 8); Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics im = Graphics.FromImage(bitmap); pictureBox1.Image = bitmap; float hw = Convert.ToInt32(pictureBox1.Width) / 2; float hh = Convert.ToInt32(pictureBox1.Height) / 2; Pen pen = new Pen(Color.Black); pen.Width = 2; Bitmap bitmap2 = new Bitmap(pictureBox2.Width, pictureBox2.Height); Graphics im2 = Graphics.FromImage(bitmap2); pictureBox2.Image = bitmap2; float hw2 = Convert.ToInt32(pictureBox2.Width) / 2; float hh2 = Convert.ToInt32(pictureBox2.Height) / 2; List <koor> graph = new List <koor>(); List <koor> graph2 = new List <koor>(); im.DrawLine(pen, 0, hw, hh * 2, hw); im.DrawLine(pen, hh, 0, hh, hw * 2); im2.DrawLine(pen, 0, hw2, hh2 * 2, hw2); im2.DrawLine(pen, hh2, 0, hh2, hw2 * 2); double rangex = Math.PI, rangey = 0.000075; for (int i = 0; i < 4; i++) { im.DrawLine(pen, i * hh / 2, hw - 5, i * hh / 2, hw + 5); im.DrawLine(pen, hh - 5, i * hw / 2, hh + 5, i * hw / 2); im2.DrawLine(pen, i * hh2 / 2, hw2 - 5, i * hh2 / 2, hw2 + 5); im2.DrawLine(pen, hh2 - 5, i * hw2 / 2, hh2 + 5, i * hw2 / 2); } double g = -rangex; for (int i = 0; i <= 4; i++) { im.DrawString(g.ToString(), f, new SolidBrush(Color.Black), i * hh / 2, hw); im2.DrawString(g.ToString(), f, new SolidBrush(Color.Black), i * hh2 / 2, hw2); g += 2 * rangex / 4; } g = rangey; for (int i = 0; i <= 4; i++) { im.DrawString(g.ToString(), f, new SolidBrush(Color.Black), hh, i * hw / 2); im2.DrawString(g.ToString(), f, new SolidBrush(Color.Black), hh2, i * hw2 / 2); g -= 2 * rangey / 4; } double h = hopt(t0, tmax, n, eps); int m = Convert.ToInt32(Math.Round(tmax / h)) + 1; double huse = tmax / m; for (int i = 0; i < m; i++) { double tloc = t0 + i * huse; var pogr = globalRunge(t0, tloc, m); koor temp2 = new koor(); temp2.rex = tloc; temp2.rey = pogr[1]; graph2.Add(temp2); koor temp = new koor(); temp.rex = tloc; temp.rey = pogr[0]; graph.Add(temp); } pen.Color = Color.Coral; for (int i = 0; i < graph.Count; i++) { graph[i].imx = hh + (pictureBox1.Height / (2 * rangex)) * graph[i].rex; graph[i].imy = hw - (pictureBox1.Width / (2 * rangey)) * graph[i].rey; graph2[i].imx = hh2 + (pictureBox2.Height / (2 * rangex)) * graph2[i].rex; graph2[i].imy = hw2 - (pictureBox2.Width / (2 * rangey)) * graph2[i].rey; } for (int i = 1; i < graph.Count; i++) { Point x = new Point(), y = new Point(); x.X = Convert.ToInt32(graph[i - 1].imx); x.Y = Convert.ToInt32(graph[i - 1].imy); y.X = Convert.ToInt32(graph[i].imx); y.Y = Convert.ToInt32(graph[i].imy); im.DrawLine(pen, x, y); } for (int i = 1; i < graph.Count; i++) { pen.Color = Color.Red; Point x2 = new Point(), y2 = new Point(); x2.X = Convert.ToInt32(graph2[i - 1].imx); x2.Y = Convert.ToInt32(graph2[i - 1].imy); y2.X = Convert.ToInt32(graph2[i].imx); y2.Y = Convert.ToInt32(graph2[i].imy); im2.DrawLine(pen, x2, y2); } }
public List <double> autoshag(double t0, double tmax, double eps) { Font f = new Font(FontFamily.GenericSerif, 8); Bitmap bitmap = new Bitmap(pictureBox1.Width, pictureBox1.Height); Graphics im = Graphics.FromImage(bitmap); pictureBox1.Image = bitmap; float hw = Convert.ToInt32(pictureBox1.Width) / 2; float hh = Convert.ToInt32(pictureBox1.Height) / 2; Pen pen = new Pen(Color.Black); pen.Width = 2; List <koor> graph = new List <koor>(); im.DrawLine(pen, 0, hw, hh * 2, hw); im.DrawLine(pen, hh, 0, hh, hw * 2); double rangex = Math.PI; double A = 2.0 / 11, B = 3.0 / 13, x0 = A * Math.PI, y0 = B * Math.PI, c = 1.0 / 9; List <double> y1 = new List <double>(); List <double> y2 = new List <double>(); y1.Add(y0); y2.Add(x0); double qwe = t0; double hloc = (tmax - t0); int i = 0; while (qwe < tmax) { double a = c, b2 = 1.0 / (2 * c), b1 = 1 - b2; bool rdy = false; double y1plus1 = 0; double y2plus1 = 0; while (!rdy) { double k11 = hloc * f1(y2[i]); double k21 = hloc * f2(y1[i]); double k12 = hloc * f1(y2[i] + a * k21); double k22 = hloc * f2(y1[i] + a * k11); y1plus1 = y1[i] + b1 * k11 + b2 * k12; y2plus1 = y2[i] + b1 * k21 + b2 * k22; var temp = move(y1[i], y2[i], hloc); var y1loc = (Math.Abs(temp[0] - y1plus1) / (1 - Math.Pow(2, -2))); var y2loc = (Math.Abs(temp[1] - y2plus1) / (1 - Math.Pow(2, -2))); if (y1loc > eps * Math.Pow(2, 2) || y2loc > eps * Math.Pow(2, 2)) { hloc /= 2; } else { if ((y1loc > eps && y1loc < eps * Math.Pow(2, 2)) || (y2loc > eps && y2loc < eps * Math.Pow(2, 2))) { hloc /= 2; } else { if (y1loc < eps && y2loc < eps) { rdy = !rdy; } } } } koor point = new koor(); point.rex = qwe; point.rey = hloc; graph.Add(point); y1.Add(y1plus1); y2.Add(y2plus1); //if(udovlet(y1[i],y2[i],y1plus1,y2plus1,hloc,eps)) //{ // y1.Add(y1plus1); // y2.Add(y2plus1); //} //else //{ // hloc=hepsloc(y1[i],y2[i],y1plus1,y2plus1, hloc, eps); // k11 = hloc * f1(y2[i]); // k21 = hloc * f2(y1[i]); // k12 = hloc * f1(y2[i] + a * k21); // k22 = hloc * f2(y1[i] + a * k11); // y1plus1 = y1[i] + b1 * k11 + b2 * k12; // y2plus1 = y2[i] + b1 * k21 + b2 * k22; // y1.Add(y1plus1); // y2.Add(y2plus1); //} //y1.Add(y1plus1); //y2.Add(y2plus1); i++; qwe += hloc; } double rangey = 0.25; //for (int j = 0; j < graph.Count;j++) //{ // if (graph[j].rey > rangey) // rangey = graph[j].rey; //} for (int j = 0; j < 4; j++) { im.DrawLine(pen, j * hh / 2, hw - 5, j * hh / 2, hw + 5); im.DrawLine(pen, hh - 5, j * hw / 2, hh + 5, j * hw / 2); } double g = -rangex; for (int j = 0; j <= 4; j++) { im.DrawString(g.ToString(), f, new SolidBrush(Color.Black), j * hh / 2, hw); g += 2 * rangex / 4; } g = rangey; for (int j = 0; j <= 4; j++) { im.DrawString(g.ToString(), f, new SolidBrush(Color.Black), hh, j * hw / 2); g -= 2 * rangey / 4; } for (int j = 0; j < graph.Count; j++) { graph[j].imx = hh + (pictureBox1.Height / (2 * rangex)) * graph[j].rex; graph[j].imy = hw - (pictureBox1.Width / (2 * rangey)) * graph[j].rey; } pen.Color = Color.Red; for (int j = 1; j < graph.Count; j++) { Point x = new Point(), y = new Point(); x.X = Convert.ToInt32(graph[j - 1].imx); x.Y = Convert.ToInt32(graph[j - 1].imy); y.X = Convert.ToInt32(graph[j].imx); y.Y = Convert.ToInt32(graph[j].imy); im.DrawLine(pen, x, y); } List <double> ret = new List <double>(); ret.Add(y1[y1.Count - 1]); ret.Add(y2[y2.Count - 1]); return(ret); }