当前位置:网站首页>Newton method for solving roots of polynomials
Newton method for solving roots of polynomials
2022-06-12 12:40:00 【April 16!】
Give me an initial value , Solving roots of polynomials by Newton method ;
#include<iostream>
#include<math.h>
#include<vector>
using namespace std;
struct Newton {
public:
double ini_para;
// The highest n Time , List of coefficients , initial value
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); // Primitive function
if(i<n)
daof += (n-i)*coffer[i]*pow(x,n-i-1); // Derivative function
i++;
}
double chu = yuanf / daof; // Primitive function / Derivative function
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); // Primitive function
i++;
}
cout << " Total iterations :" << 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 The result is :\n" << a << endl;
system("pause");
return 0;
}
边栏推荐
- Simple picture preview
- Lightweight ---project
- 【您编码,我修复】WhiteSource正式更名为Mend
- ITK Examples/RegistrationITKv4/DeformableRegistration
- 机械臂改进的DH参数与标准DH参数理论知识
- Implementation principle of kotlin extension function
- Soft test network engineer notes
- 时序数据库 - InfluxDB2 docker 安装
- Video speed doubling in PC browser
- C语言深度解剖篇——关键字&&补充内容
猜你喜欢

深度剖析指针的进阶——C语言的进阶篇

VS2019 设置 CTRL+/ 为注释和取消注释快捷键

Buu question brushing record - 6

SEO optimization of web pages

Deep analysis of advanced pointer -- advanced chapter of C language

一个ES设置操作引发的“血案”
![[an Xun cup 2019]iamthinking](/img/86/f83f3ca7967eae6c4be4562db45150.jpg)
[an Xun cup 2019]iamthinking

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

数组——二维数组的花式遍历技巧

wx. Login and wx Getuserprofile simultaneous use problem
随机推荐
[an Xun cup 2019]iamthinking
VGG小卷积代替大卷积 VS 深度可分离卷积
itk neighbhood
VGg small convolution instead of large convolution vs deep separable convolution
Vs2019 set ctrl+/ as shortcut key for annotation and uncomment
Principle of master-slave replication of redis
Take the web page animation effects that can be used. Don't you come and have a look?
vtk 图像序列鼠标交互翻页
Congratulations to splashtop for winning the 2022 it Europa "vertical application solution of the year" award
Uniapp wechat applet long press the identification QR code to jump to applet and personal wechat
从基础到源码统统帮你搞定,技术详细介绍
轻量化---Project
安全KNN
Buu question brushing record - 6
Bank layout meta universe: digital collections, digital employees become the main track!
wx. Login and wx Getuserprofile simultaneous use problem
JS how to get the values of multiple objects in an array
Is yuancosmos a short-term speculation or a future trend?
What can LDAP and SSO integration achieve?
Problems encountered in generating MP3 from text to speech through iFLYTEK voice API