当前位置:网站首页>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;
}
边栏推荐
- itk neighbhood
- Numpy numerical calculation basis
- A short guide to SSH port forwarding
- InfluxDB2.x 基准测试工具 - influxdb-comparisons
- El select data echo, display only value but not label
- Imx6 uboot add lvds1 display
- ITK 多阶段配准
- [JS] some handwriting functions: deep copy, bind, debounce, etc
- Promise+ handwritten promise
- Kdd2022 | edge information enhancement graph transformer
猜你喜欢

InfluxDB2.x 基准测试工具 - influxdb-comparisons

安全KNN

机械臂改进的DH参数与标准DH参数理论知识

Buu question brushing record - 5

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

Advanced C language -- storage of floating point in memory

二叉树(序列化篇)

this.$ How to solve the problem when refs is undefined?

Buu question brushing record - 7

NDT registration principle
随机推荐
机械臂改进的DH参数与标准DH参数理论知识
The 4th Zhejiang CTF preliminary contest web pppop
Principle of master-slave replication of redis
Suggestions and skills for advanced version of go language test
Problems encountered in generating MP3 from text to speech through iFLYTEK voice API
Deep analysis of advanced pointer -- advanced chapter of C language
Boot entry directory
2022 ARTS|Week 23
Vs2019 set ctrl+/ as shortcut key for annotation and uncomment
一个ES设置操作引发的“血案”
Part of the fourth Zhejiang CTF finals
[C language] keyword static & Multi file & guessing game
一个ES设置操作引发的“血案”
Kdd2022 | edge information enhancement graph transformer
【VIM】.vimrc配置,已经安装Vundle,YoucompleteMe
Advanced C language -- storage of floating point in memory
Start with Xiaobai, take the weight parameter from the trained model and draw the histogram
itk::SymmetricForcesDemonsRegistrationFilter
Matlab install license manager error -8
SWI-Prolog的下载与使用