I am doing a practice for a physical case where it involves a resting object moving on an inclined plane where at the end of the slope the object falls freely, the falling object grabs even speed and travels a distance, asks to calculate the distance after the fall.
It is in my case that the values when I finish calculating several values do not read me, they say: "NaN" or "0".
As you can see the acceleration, the time of fall, the distance traveled and the speeds (both in horizontal, as in fall and the slope) are not given to exit.
The structured code is as follows:
private void button1_Click(object sender, EventArgs e)
{
double[] ang, Xp, H, Tiempo, Acel, Vx, Vy, X, Vf, coef, rad;
double d1, d2, g = 9.81, g2 = 4.9, d3;
ang = new double[5]; Tiempo = new double[5]; Acel = new double[5]; H = new double[5];
Xp = new double[5]; Vx = new double[5]; Vy = new double[5]; Vf = new double[5]; X = new double[5];
coef = new double[5]; rad = new double[5];
for (int i = 0; i <= 4; i++)
{
ang[i] = Convert.ToDouble(dataGridView3.Rows[i].Cells[0].Value);
Xp[i] = Convert.ToDouble(dataGridView2.Rows[i].Cells[0].Value);
H[i] = Convert.ToDouble(dataGridView1.Rows[i].Cells[0].Value);
rad[i] = ((ang[i] * Math.PI) / 180);
coef[i] = Math.Round(Math.Tan(rad[i]),3); //Los valores del coeficiente si se muestran.
Acel[i] = Math.Round((g * (Math.Sin(rad[i]) - (coef[i] * Math.Cos(rad[i])))), 2);
Vf[i] = Math.Round(Math.Sqrt(2 * Acel[i] * Xp[i]), 2);
Vx[i] = Math.Round(Vf[i] * Math.Cos(rad[i]), 2);
Vy[i] = Math.Round(Vf[i] * Math.Sin(rad[i]), 2);
}
for (int i = 0; i <= 4; i++) // Aqui se realiza el despeje de la formula de fisica para el tiempo a formula general.
{
d3 = 2 * g2;
d2 = (-4 * g2 * Xp[i]);
d1 = Math.Round(Math.Sqrt(Math.Pow(Vy[i], 2) + d2), 2);
Tiempo[i] = ((-Vy[i]) + d1) / d3;
X[i] = Vx[i] * Tiempo[i];
}
for (int i = 0; i <= 4; i++)
{
dataGridView8.Rows[i].Cells[0].Value = Convert.ToString(Vf[i]);
dataGridView8.Rows[i].Cells[1].Value = Convert.ToString(Vx[i]);
dataGridView8.Rows[i].Cells[2].Value = Convert.ToString(Vy[i]);
dataGridView4.Rows[i].Cells[0].Value = Convert.ToString(Acel[i]);
dataGridView5.Rows[i].Cells[0].Value = Convert.ToString(Tiempo[i]);
dataGridView6.Rows[i].Cells[0].Value = Convert.ToString(X[i]);
}
}
The values of the coefficient are in the debugger and if they give me that it is 0.7, the tangent of the radian of the angle of 35 degrees is 0.7 I do not know exactly what is the error that the values do not appear or if the formula to calculate is not correct.
This error is not because I am presented in this case, being that in other practices for windows form with handling of arrays by GridView if the data is visualized.
I would appreciate if this matter is resolved as soon as possible.