1

我有进行计算并将数据添加到集合列表的方法。下面是我的代码

IterateDtColl iterateDataList = new IterateDtColl();

        double answer;
        //Array to hold the previous initail tempreture
        double[] TempArray = new double[9];

        for (int tVal = 0; tVal < exdatalist.count(); tVal++)
        {
            ValidateDataColl validatelist = new ValidateDataColl();

            //Assign my initial tempreture
            if (iterateDataList.count() > 0)
            {
                TempArray[0] = iterateDataList.getexceldata(tVal - 1).Pi1;
                TempArray[1] = iterateDataList.getexceldata(tVal - 1).Pi2;
                TempArray[2] = iterateDataList.getexceldata(tVal - 1).Pi3;
                TempArray[3] = iterateDataList.getexceldata(tVal - 1).Pi4;
                TempArray[4] = iterateDataList.getexceldata(tVal - 1).Pi5;
                TempArray[5] = iterateDataList.getexceldata(tVal - 1).Pi6;
                TempArray[6] = iterateDataList.getexceldata(tVal - 1).Pi7;
                TempArray[7] = iterateDataList.getexceldata(tVal - 1).Pi8;
                TempArray[8] = iterateDataList.getexceldata(tVal - 1).Pi9;
            }
            else
            {
                TempArray[0] = Convert.ToDouble(initProbTxtBx.Text);
                TempArray[1] = TempArray[0];
                TempArray[2] = TempArray[0];
                TempArray[3] = TempArray[0];
                TempArray[4] = TempArray[0];
                TempArray[5] = TempArray[0];
                TempArray[6] = TempArray[0];
                TempArray[7] = TempArray[0];
                TempArray[8] = TempArray[0];
            }

            //Holds Value for last calculated values..
            double[] LastCalValue = new double[9];

            for (int iVal = 0; iVal < 9; iVal++)
            {
                answer = 0.0;

                if (iVal == 0)
                {
                    answer = (TempArray[iVal] + (r_val(dxval(lval, nval)) * (exdatalist.getexceldata(tVal).CentreTemp + initVal))) / (1 + (2 * r_val(dxval(lval, nval))));
                }
                else if (iVal == 8)
                {
                    answer = (TempArray[iVal] + (r_val(dxval(lval, nval)) * (LastCalValue[iVal - 1] + exdatalist.getexceldata(tVal).SurfaceTemp))) / (1 + (2 * r_val(dxval(lval, nval))));
                }
                else
                {
                    answer = (TempArray[iVal] + (r_val(dxval(lval, nval)) * (LastCalValue[iVal - 1] + initVal))) / (1 + (2 * r_val(dxval(lval, nval))));
                }

                //Hold the values at the present index so it can be used at the next index
                LastCalValue[iVal] = answer;

                //Adds the data to be validated to my collection list
                validatelist.addvaliddt(new ValidateDataCl(initVal, LastCalValue[iVal], TempArray[iVal]));
            }

我想检查验证列表中的initVal和LastCalValue[index]之间的差异是否小于0.0001,如果不是,则进行下面的计算直到满足条件。

for (int check = 0; check < validate.count(); check++)
            {
                double newAnswer;
                double NewVal = 0.0;

                if (check == 0)
                {
                    //Set my new value to the value at the next index(Which then becomes my guess)
                    NewVal = validate.getvaliddata(check + 1).NewValue;
                    newAnswer = (validate.getvaliddata(check).InitTemp + (r_val(dxval(lval, nval)) * (CentreTemp + NewVal))) / (1 + (2 * r_val(dxval(lval, nval))));
                }
                else if (check == 8)
                {
                    NewVal = OldVal[check - 1];
                    newAnswer = (validate.getvaliddata(check).InitTemp + (r_val(dxval(lval, nval)) * (NewVal + SurfaceTemp))) / (1 + (2 * r_val(dxval(lval, nval))));
                }
                else
                {
                    NewVal = validate.getvaliddata(check + 1).NewValue;
                    newAnswer = (validate.getvaliddata(check).InitTemp + (r_val(dxval(lval, nval)) * (OldVal[check - 1] + NewVal))) / (1 + (2 * r_val(dxval(lval, nval))));
                }

                validate.getvaliddata(check).InitGuess = NewVal;
                validate.getvaliddata(check).NewValue = newAnswer;

                OldVal[check] = newAnswer;
            }

            //ValidateDataColl ValidatedList = CalNewData(validatelist, exdatalist.getexceldata(tVal).CentreTemp, exdatalist.getexceldata(tVal).SurfaceTemp);

            iterateDataList.additerdt(new IterateClass(exdatalist.getexceldata(tVal).CentreTemp, ValidatedList.getvaliddata(0).NewValue, ValidatedList.getvaliddata(1).NewValue, ValidatedList.getvaliddata(2).NewValue, ValidatedList.getvaliddata(3).NewValue, ValidatedList.getvaliddata(4).NewValue, ValidatedList.getvaliddata(5).NewValue, ValidatedList.getvaliddata(6).NewValue, ValidatedList.getvaliddata(7).NewValue, ValidatedList.getvaliddata(8).NewValue, exdatalist.getexceldata(tVal).SurfaceTemp));
        }

        return iterateDataList;

我怎样才能做到这一点?

4

0 回答 0