当前位置:网站首页>牛顿法解多项式的根
牛顿法解多项式的根
2022-06-12 12:26:00 【4月16!】
给个初值,用牛顿法解多项式的根;
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
struct Newton {
public:
double ini_para;
// 最高n次,系数列表,初值
double resultNewton(int n,std::vector<double> coffer,double ini_para) {
int c = 0;
double x = ini_para, x2 = 0;
while (true) {
c++;
double b;
int i = 0;
double yuanf = 0, daof = 0;
while( i < n+1 ){
yuanf += coffer[i] * pow(x,n-i); // 原函数
if(i<n)
daof += (n-i)*coffer[i]*pow(x,n-i-1); //导函数
i++;
}
double chu = yuanf / daof; //原函数/导函数
x2 = x - chu;
if (abs(x2 - x) < 0.00001)
break;
x = x2;
}
int i = 0;
double reslt = 0;
while (i < n + 1) {
reslt += coffer[i] * pow(x2, n - i); // 原函数
i++;
}
cout << "总共迭代了:" << c << " "<< reslt;
return x2;
}
};
int main() {
std::vector<double> coff = { 1,0 ,0,0,5,6};
Newton newton;
int a = newton.resultNewton(coff.size()-1, coff,-10);
cout << "\n结果为:\n" << a << endl;
system("pause");
return 0;
}
边栏推荐
- 恭喜Splashtop 荣获2022年 IT Europa “年度垂直应用解决方案”奖
- Principle of master-slave replication of redis
- A short guide to SSH port forwarding
- 回溯法, 八皇后
- Advanced chapter of C language -- ten thousand words explanation pointer and qsort function
- 导航中,添加边框影响布局的解决方法
- Implementation principle of kotlin extension function
- 轻量化---Project
- golang的channel和条件变量在单生产单消费场景下的性能对比测试
- [译] Go语言测试进阶版建议与技巧
猜你喜欢

【Leetcode】79. Word search

C语言深度解剖篇——关键字&&补充内容

C语言进阶篇——深度解剖数据在内存中的存储(配练习)

Numpy数值计算基础

NDT registration principle

Examples of Cartesian product and natural connection of relational algebra

Reasons for college students' leave

Advanced chapter of C language -- ten thousand words explanation pointer and qsort function

大学生请假理由

左右案例+小圆点的轮播图+无时间
随机推荐
Shielding does not display vs warning
你不会只会用console.log()吧?
What can LDAP and SSO integration achieve?
【C语言】关键字static&&多文件&&猜字游戏
【Leetcode】199. Right view of binary tree
【Leetcode】79. Word search
JS method of exporting DOM as picture
ACE配置IPv6, VS静态编译ACE库
Quantization and Training of Neural Networks for Efficient Integer-Arithmetic-Only Inference
Matlab install license manager error -8
NDT配准原理
Quic wire layout specification - packet types and formats | quic protocol standard Chinese translation (2) package type and format
NDT registration principle
imx6-uboot添加lvds1显示
Kdd2022 | edge information enhancement graph transformer
[译] Go References - The Go Memory Model | golang官方文档中文翻译之内存模型
宏编译 预处理头 WIN32_LEAN_AND_MEAN
SEO optimization of web pages
Lightweight ---project
[C language] keyword static & Multi file & guessing game