.


:




:

































 

 

 

 


-21 .

.

:

, :

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;

using System.Drawing.Drawing2D;

 

namespace 1

{

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 Form1_Load(object sender, EventArgs e)

{

 

}

 

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 button3_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 < 50)

{

return 60 +4 * x1-2*x1*x1;

}

else

{

return 60-10*x1-2*x1*x1;

}

}

double fx2(Double x1, Double x2)

{

 

 

return - 1000*Math.Abs(Math.Cos(x1/2));

 

}

double fx3(Double x1, Double x2)

{

if (x2 < 50)

{

return 60 + 4 * x1;

}

else

{

return 60 - 10 * x1;

}

 

}

 

private void button2_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;

}

}

}

. 1, 2, 3:

. 1. .

 

 

. 2. .

. 3. .

 

 



<== | ==>
, . . |
:


: 2016-10-22; !; : 292 |


:

:

, .
==> ...

1014 - | 829 -


© 2015-2024 lektsii.org - -

: 0.024 .