我正在使用牛顿方法计算一个值,并使用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;
}
}