Last post Nov 30, 2010 08:35 PM by arkan.turk

Participant

1677 Points

713 Posts

### draw equation wave

Hi all

how to draw this equation

```double[] xx = new double[13];
xx[0]=50;
xx[1]=55;
xx[2]=57;
xx[3]=60;
xx[4]=62.5;
xx[5]=65;
xx[6]=67.5;
xx[7]=70;
xx[8]=72.5;
xx[9]=75;
xx[10]=77.5;
xx[11]=80;
xx[12] = 82.5;

for (int i = 0; i < xx.Length; i++)
{
x = xx[i];
y = GetY(xx[i]);

}

}
double GetY(double x)
{

double y=0;
y = (-0.122*Math.Pow(x, 4) ) +( 3.2577* Math.Pow(x, 3)) - (31.182 * Math.Pow(x, 2)) + (128.55 * x) - 192.16;
return y;
}```

the original equation is

y = -0.122x4 + 3.2577x3 - 31.182x2 + 128.55x - 192.16

i was create it with c# by GetY() function

the problem most of input and result is (Double value)

how to draw line from point to point with double value for each x and y

i was read lot of articles but i think i need to know the logic on it

Do it once and do it right and forget it for ever

Participant

1677 Points

713 Posts

### Re: draw equation wave

i think i found some idea

```private void Form2_Paint(object sender, PaintEventArgs e)
{

Graphics g = e.Graphics;
Font vertFont = new Font("Verdana", 10, FontStyle.Bold);
Font horzFont = new Font("Verdana", 10, FontStyle.Bold);
SolidBrush vertBrush = new SolidBrush(Color.Black);
SolidBrush horzBrush = new SolidBrush(Color.Blue);
Pen blackPen = new Pen(Color.Black);
Pen bluePen = new Pen(Color.Blue);

g.DrawLine(blackPen, 50, 225, 50, 15);
g.DrawLine(bluePen, 40, 220, 383, 220);

g.DrawString("5", horzFont, horzBrush, 40, 220);
g.DrawString("6", horzFont, horzBrush, 122, 220);
g.DrawString("7", horzFont, horzBrush, 204, 220);
g.DrawString("8", horzFont, horzBrush, 286, 220);
g.DrawString("9", horzFont, horzBrush, 368, 220);

StringFormat vertStrFormat = new StringFormat();
vertStrFormat.FormatFlags = StringFormatFlags.DirectionVertical;
g.DrawString("-", horzFont, horzBrush, 60, 212, vertStrFormat);
g.DrawString("-", horzFont, horzBrush, 142, 212, vertStrFormat);
g.DrawString("-", horzFont, horzBrush, 224, 212, vertStrFormat);
g.DrawString("-", horzFont, horzBrush, 306, 212, vertStrFormat);
g.DrawString("-", horzFont, horzBrush, 388, 212, vertStrFormat);

g.DrawString("12 -", vertFont, vertBrush, 25, 15);
g.DrawString("10 -", vertFont, vertBrush, 25, 45);
g.DrawString("08 -", vertFont, vertBrush, 25, 75);
g.DrawString("06 -", vertFont, vertBrush, 25, 105);
g.DrawString("04 -", vertFont, vertBrush, 25, 135);
g.DrawString("02 -", vertFont, vertBrush, 25, 165);
g.DrawString("00 -", vertFont, vertBrush, 25, 195);

vertFont.Dispose();
horzFont.Dispose();
vertBrush.Dispose();
horzBrush.Dispose();
blackPen.Dispose();
bluePen.Dispose();

double  y;
double x;

double[] xx = new double[13];
xx[0] = 5;
xx[1] = 5.5;
xx[2] = 5.7;
xx[3] = 6;
xx[4] = 6.25;
xx[5] = 6.5;
xx[6] = 6.75;
xx[7] = 7;
xx[8] = 7.25;
xx[9] = 7.5;
xx[10] = 7.75;
xx[11] = 8;
xx[12] = 8.25;

Point[] curvePoints=new Point [13];

for (int i = 0; i < xx.Length; i++)
{
x = xx[i];
y = GetY(xx[i]);

}

Pen redPen = new Pen(Color.Red, 3);
Pen greenPen = new Pen(Color.Green, 3);
e.Graphics.DrawLines(redPen, curvePoints);

e.Graphics.DrawCurve(greenPen, curvePoints);

}
double GetY(double x)
{

double y=0;
y = (-0.122*Math.Pow(x, 4) ) +( 3.2577* Math.Pow(x, 3)) - (31.182 * Math.Pow(x, 2)) + (128.55 * x) - 192.16;
return y;

}```

please replay if there is other good idea

Do it once and do it right and forget it for ever