牛顿迭代法
2017-08-14 16:30
162 查看
今天粗略看了一下牛顿迭代法。。。
这篇生动形象简单易懂:https://www.zhihu.com/question/20690553
这篇用牛顿迭代法求平方根:http://blog.csdn.net/wumuzi520/article/details/7026808
牛顿迭代法求平方根:
这篇生动形象简单易懂:https://www.zhihu.com/question/20690553
这篇用牛顿迭代法求平方根:http://blog.csdn.net/wumuzi520/article/details/7026808
牛顿迭代法求平方根:
#include <bits/stdc++.h> using namespace std; const double eps = 1e-5; double y; double df(double x) //函数的导数 { return 2*x; } double f(double x) //要求根的函数 { return x*x - y; } double newton_iteration(double x) { int tot = 0; //这里不用eps控制循环的原因是当输入的数很大时,经过一定次数的迭代求出的根已经足够精确了,但是用f(x)放大x后造成了巨大的误差,导致不能结束循环。。。 // while(fabs(f(x) - 0) > eps) // { // x = x - f(x) / df(x); // if(++tot > 100) return -1; // } while(++tot <= 100) { x = x - f(x) / df(x); } return x; } int main() {//不能处理负数的喔 while(~ scanf("%lf", &y)) { //printf("%.6f %.6f\n", sqrt(y), pow(y, 0.5)); double ans = newton_iteration(y / 2.0); if(fabs(-1 - ans) < eps) puts("无解"); else printf("%.6f\n", ans); } return 0; }
相关文章推荐
- 牛顿迭代法、迭代逼近
- 用牛顿迭代法求浮点数的平方根
- 很牛的牛顿迭代法
- 【专题】三分法和牛顿迭代法总结
- 计算方法之牛顿迭代法求方程根
- matlab实现牛顿迭代法求解非线性方程组
- 关于使用牛顿迭代法和二分法解方程的算法说明
- 一个求实数立方根的C语言函数(牛顿迭代法)
- 利用牛顿迭代法求平方根
- poj 3111 K Best 参数搜索之牛顿迭代法
- 牛顿迭代法及最小二乘法
- 使用牛顿迭代法求平方根
- 牛顿迭代法应用——求数的平方根和立方根
- 牛顿迭代法
- 牛顿迭代法(Newton's Method)
- 1.6_牛顿迭代法求方程的根
- 牛顿迭代法(Newton's Method)
- 用牛顿迭代法求下面方程在1.5附近的根:2x^3-4x^2+3x-6=0
- 牛顿迭代法求方程根--C语言
- 牛顿迭代法