1

我正在使用牛顿法计算一个值,并使用 for 循环来测试它是否收敛。但我觉得在 for 循环中使用固定值并不是最好的方法。有什么建议吗?

double startingRate = 0.1;
double oldStartingRate;
double rateDeviation;
for (int x = 0; x < 50; x++)
{
    oldStartingRate = startingRate;
    startingRate = NewtonMethod(startingRate);
    rateDeviation = Math.Abs(startingRate - oldStartingRate);
    Debug.WriteLine("deviation:" + rateDeviation .ToString()+" rate:" + startingRate);
    if (rateDeviation < deviation)  //deviation is a constant
    {
        return startingRate;
    }
}
4

0 回答 0