hdu2199 Can you solve this equatio
来源:互联网 发布:2017安全知识网络大赛 编辑:程序博客网 时间:2024/04/30 16:44
newton迭代法计算公式:(参考数值分析(第四版)P148——P152)
设r是f(x) = 0的根,选取x0作为r初始近似值,过点(x0,f(x0))做曲线y = f(x)的切线L,L的方程为y = f(x0)+f'(x0)(x-x0),求出L与x轴交点的横坐标 x1 = x0-f(x0)/f'(x0),称x1为r的一次近似值。过点(x1,f(x1))做曲线y = f(x)的切线,并求该切线与x轴交点的横坐标 x2 = x1-f(x1)/f'(x1),称x2为r的二次近似值。重复以上过程,得r的近似值序列,其中x(n+1)=x(n)-f(x(n))/f'(x(n)),称为r的n+1次近似值,上式称为牛顿迭代公式。
下面列出Newton法的计算步骤:
题目连接:http://acm.hdu.edu.cn/showproblem.php?pid=2199
#include <iostream>#include <cstring>#include <cstdio>#include <cmath>#include <iomanip>#include <algorithm>using namespace std;double x,y,r;#define f 8*x*x*x*x+7*x*x*x+2*x*x+3*x+6-y#define f1 32*x*x*x+21*x*x+4*x+3double newton(double x){ int k=0; while(fabs(f)>1e-6) { x=x-(f)/(f1); k++; if(k>50) return -1; } return x;}int main(){ int t; cin>>t; while(t--) { cin>>y; int sign=0; for(double x=0.0;x<100;x++) { r=newton(x); if(r<=100.0&&r>=0.0) { sign=1; break; } } if(sign==0) cout<<"No solution!"<<endl; else cout<<setiosflags(ios::fixed)<<setprecision(4)<<r<<endl; } return 0;}
- hdu2199 Can you solve this equatio
- HDU2199 Can you solve this equation?
- hdu2199 Can you solve this equation?
- HDU2199:Can you solve this equation?(二分)
- HDU2199 Can you solve this equation?
- hdu2199 Can you solve this equation?
- HDU2199 Can you solve this equation?(二分)
- hdu2199 Can you solve this equation? (二分搜索)
- hdu2199 Can you solve this equation? (二分+double精度)
- hdu2199 Can you solve this equation?(二分)
- 【hdu2199】Can you solve this equation?——二分
- HDU2199:Can you solve this equation?(数学 + 二分)
- 二分搜索--控制精度--hdu2199 Can you solve this equation
- 【个人训练】(HDU2199)Can you solve this equation?
- (step4.1)hdu2199(Can you solve this equation?——二分查找)
- ACM-二分搜索之Can you solve this equation?——hdu2199
- HDU2199 Can you solve this equation 二分求方程的根
- HDU2199.Can you solve this equation?——二分解方程
- 普本计算机小硕2014年校招总结帖
- 学习制作google map地图无法显示问题
- 自学HTML之JavaScript
- 值栈和OGNL 之 7.1 值栈
- 交叉编译中的build、host、target选项的含义
- hdu2199 Can you solve this equatio
- centos集群上安装ganglia-3.6.0监控hadoop-2.2.0和hbase-0.96.0
- 【MoreWindows工作笔记3】 使用cout/pintf输出16进制,8进制,2进制数据
- 黑马程序员---内部类与异常
- Android_ListView_onTouchEvent源码分析
- Ubuntu中firefox chromium安装flash插件
- 几种常见排序算法
- 第12周项目4-计算当年第几天(二)
- 命令启动程序