Find an algorithm to evaluate radical signx for a positive real numberx.
时间: 2024-02-21 22:00:41 浏览: 32
To evaluate the square root of a positive real number x, we can use the Babylonian method or the Newton-Raphson method. Here is the Babylonian method:
1. Start with a guess for the square root, say g.
2. Calculate the quotient x / g.
3. Average g and x / g to get a new guess, say ng.
4. Repeat steps 2 and 3 with ng until ng is close enough to the actual square root.
Here is the algorithm in pseudocode:
```
function square_root(x):
g = x/2 // start with a guess
while abs(g*g - x) > 0.0001:
g = (g + x/g) / 2 // calculate the average of g and x/g
return g
```
This algorithm starts with a guess of x/2 and iteratively improves the guess until the difference between the guess squared and the actual x is less than a small value (0.0001 in this case).
Note that this algorithm can also be extended to evaluate higher order roots (e.g., cube roots) by adjusting the initial guess and the averaging step accordingly.
相关推荐
![doc](https://img-home.csdnimg.cn/images/20210720083327.png)
![pdf](https://img-home.csdnimg.cn/images/20210720083512.png)
![zip](https://img-home.csdnimg.cn/images/20210720083736.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)
![](https://csdnimg.cn/download_wenku/file_type_ask_c1.png)