一、牛顿迭代法介绍
牛顿迭代法(Newton's method)又称牛顿-拉夫逊方法,是一种在实数域和复数域上的近似求解方程的方法。
二、开方根的实现
/*
*实现环境 TMS320F28335
*/
typedef unsigned char uint8_t;
typedef unsigned short int uint16_t;
typedef unsigned int uint32_t;
static uint16_t sqrt_uint32(uint32_t square_data)
{
uint16_t i;
uint16_t k;
uint32_t tmp;
uint32_t stop;
i = 0U;
tmp = square_data;
while (tmp > 0U)
{
tmp >>= 1U;
i++;
}
k = i>>1U;
if (i & 0x0001U == 0x0001U)
{
tmp = (uint32_t)((uint32_t)1U<>(k + 2U));
}
else
{
tmp = (uint32_t)((uint32_t)1U<<(k - 1U));
tmp += (uint32_t)(square_data>>(k + 2U));
tmp *= 23170U;
tmp >>= 14U;
}
for (i = 0U; i < 5U; i++)
{
stop = tmp;
tmp += square_data / tmp;
tmp >>= 1U;
if (tmp >= stop)
{
break;
}
}
return((uint16_t)tmp);
}