You are on page 1of 3

Label (Temperture)

private void label1_Click(object sender, EventArgs e)


{

}
Button 1(solution method 1)
private void button1_Click(object sender, EventArgs e)
{
double T = double.Parse(textBox1.Text);
double z = 4;
float ans;
Point mid = new Point(250, 250);
Point mid1 = new Point(450, 250);
Graphics gg = CreateGraphics();
SolidBrush b1 = new SolidBrush(Color.Purple);
DrawAxes(mid, "s", "s");
DrawAxes(mid1, "s", "tanh(JZ<s>/(KBT))");

for (float s = -1; s < 1; s=s+(float)0.01)


{
//plot<s.versus <s>>
gg.FillEllipse(b1, (float)(mid.X + s * 100), (float)(mid.Y - s * 100),
(float)6.0,(float)6.0);
ans = (float)Math.Tanh(z * s / T);
//Plot <s> versus tanh()
gg.FillEllipse(b1, (float)(mid1.X + s * 100), (float)(mid1.Y - ans *
100), (float)6.0, (float)6.0);
Thread.Sleep(10);
}
}
public void DrawAxes(Point o, string xs, string ys)
{
Point px1 = new Point(o.X - 100, o.Y);
Point px2 = new Point(o.X + 100, o.Y);
Point py1 = new Point(o.X, o.Y-100);
Point py2 = new Point(o.X, o.Y + 100);
Graphics gg = CreateGraphics();
Pen p = new Pen(Color.DarkRed);
SolidBrush sb = new SolidBrush(Color.Green);
gg.DrawLine(p, px1, px2);
gg.DrawLine(p, py1, py2);
Font f = new Font("Arial", 12,FontStyle.Bold);
gg.DrawString(xs, f, sb, o.X + 100, o.Y);
gg.DrawString(ys, f, sb, o.X, o.Y-100);

Btton 3 ( s vs t)
private void button3_Click(object sender, EventArgs e)
{
double z = 4;
float ans;
Point mid = new Point(250, 250);
Graphics gg = CreateGraphics();
SolidBrush b1 = new SolidBrush(Color.Black);
DrawAxes(mid, "T", "s");
for (double T = 0.1; T < 10; T=T+(float)0.05)
{
for (float s = 1; s >= -1; s = s - (float)0.01)
{
ans = s - (float)(Math.Tanh(z * s / T));
if (Math.Abs(ans) < 0.001)
{
gg.FillEllipse(b1, (float)(mid.X + T * 50), (float)(mid.Y - s *
100), (float)6.0, (float)6.0);
Thread.Sleep(10);
}
}
}
}

Button 2 Solution method 2


private void button2_Click(object sender, EventArgs e)
{
double T = double.Parse(textBox1.Text);
double z = 4;
float ans;
Point mid = new Point(250, 250);
Graphics gg = CreateGraphics();
SolidBrush b1 = new SolidBrush(Color.DarkRed);

for (float s = -1; s < 1; s = s + (float)0.01)


{
ans = s - (float)Math.Tanh(z * s / T);
textBox1.Refresh();
Thread.Sleep(10);
textBox1.Text = ans.ToString();
gg.FillEllipse(b1, (float)(mid.X + s * 100), (float)(mid.Y - ans * 100),
(float)6.0, (float)6.0);

}
}

Button 4
private void button4_Click(object sender, EventArgs e)
{
Graphics gg = CreateGraphics();
SolidBrush b1 = new SolidBrush(Color.RoyalBlue);
float ans2, ans3;
for (double T = 0.1; T < 4; T = T + (float)0.005)
{
ans2=(float)Math.Pow((4-(float)T),0.5);
ans3 = -(float)Math.Pow((4 - (float)T), 0.5);
gg.FillEllipse(b1, (float)(200 + T * 100), (float)(250 - ans2 * 100),
(float)6.0, (float)6.0);
gg.FillEllipse(b1, (float)(200 + T * 100), (float)(250 - ans3 * 100),
(float)6.0, (float)6.0);
}

Button 5
private void button5_Click(object sender, EventArgs e)
{
Graphics gg = CreateGraphics();
SolidBrush b1 = new SolidBrush(Color.Peru);
double z = 4;
float ans;
double s1 = 1;
double T = double.Parse(textBox1.Text);
for (float s = -2; s <= 2; s = s + (float)0.005)
{
if (s < 0)
{
s1 = -1;
}
else
{
s1 = 1;
}
if (s <= 0)
{
ans = -(float)s - (float)(Math.Tanh(z * s / T) * s1);
}
else
{
ans = (float)s - (float)(Math.Tanh(z * s / T) * s1);
}
gg.FillEllipse(b1, (float)(300 + s * 100), (float)(250 - ans * 100),
(float)3.0, (float)3.0);
}
}

private void Form1_Load(object sender, EventArgs e)


{

}
}
}

You might also like