i am trying to create a calculated column. originally the column was constructed with a for loop and values were hard coded in. this WORKED for testing purposes, however changes needed to be made so that users could input different values.
the problem is that the calculation has a limit. there's a root and you can't have anything below zero in the root, so i have been trying to figure out a way to stop the loop before hitting that limit.
i tried running the do-while loop and keep getting outof memory exceptions and apparently i have something like 3+gb physical memory.
thoroughly unsure what to do, thank you for any help
here's my initial for loop:
public DataTable sphCalcBCZone1(decimal b2, decimal b5, decimal b16)
{
DataTable dt = new DataTable();
DataColumn c = new DataColumn("Z1_BC");
c.DataType = System.Type.GetType("System.Decimal");
dt.Columns.Add(c);
decimal stepPoint = 0M;
double stepd = Convert.ToDouble(stepPoint);
decimal gobbledegook = 8.6M;
for (stepd = 0; stepPoint <= gobbledegook; stepPoint = stepPoint + .005M)
{
DataRow row = dt.NewRow();
double stepd = Convert.ToDouble(stepPoint); double b2d = Convert.ToDouble(b2); double b5d = Convert.ToDouble(b5); double b16d = Convert.ToDouble(b16);
double valC1 = Math.Pow(stepd, 2) / (b2d + Math.Sqrt(Math.Pow(b2d, 2) - b5d * Math.Pow(stepd, 2))) + b16d;
decimal valC2 = Convert.ToDecimal(valC1);
row["Z1_BC"] = valC2; dt.Rows.Add(row);
}
return dt;
}
here's my do-while loop in which i tried to put in the "limit" and i got the outofmemory exception
public DataTable sphCalcBCZone1(decimal b2, decimal b5, decimal b16)
{
DataTable dt = new DataTable();
DataColumn c = new DataColumn("Z1_BC");
c.DataType = System.Type.GetType("System.Decimal");
dt.Columns.Add(c);
double b2d = Convert.ToDouble(b2); double b5d = Convert.ToDouble(b5); double b16d = Convert.ToDouble(b16);
double limit = Math.Pow(b2d, 2) - b5d * Math.Pow(step, 2);
do
{
DataRow row = dt.NewRow();
double valC1 = Math.Pow(step, 2) / (b2d + Math.Sqrt(Math.Pow(b2d, 2) - b5d * Math.Pow(step, 2))) + b16d;
decimal valC2 = Convert.ToDecimal(valC1);
row["Z1_BC"] = valC2; dt.Rows.Add(row);
step = step + .005;
} while (limit > 0);
return dt;
}