当前位置:网站首页>newton interpolation
newton interpolation
2022-07-06 04:21:00 【Python ml】
#include <vector>
#include <iostream>
using namespace std;
void print(vector<double> s)
{
for(double x:s)
{
cout<<x<<" ";
}
cout<<endl;
}
vector<double> mul(vector<double> a,vector<double> b) // Polynomial multiplication
{
int n=a.size(), m=b.size();
vector<double> s(n+m-1,0);
for(int i=0;i<n;++i)
{
for(int j=0;j<m;++j)
{
s[i+j]+=a[i]*b[j];
}
}
return s;
}
vector<double> add(vector<double> a,vector<double> b)
{
int n=a.size(), m=b.size();
vector<double> s(max(n,m),0);
for(int i=0;i<n;++i){
s[i]+=a[i];
}
for(int i=0;i<m;++i){
s[i]+=b[i];
}
return s;
}
void print_chashang_table(vector<vector<double>> A)
{
int n=A.size(), m=A[0].size();
for(int i=0;i<n;++i)
{
for(int j=0;j<=i;++j)
{
printf("% 5.2f ",A[i][j]);
}
printf("\n");
}
}
vector<double> Newton(vector<vector<double>> Point){
int n=Point.size()-1;
if(n==-1){
cout<<" error "<<endl;
}
vector<vector<double>> diffCoef_Table;
for(int i=0;i<n+1;++i){
//n+1 Item difference quotient , Initialize the difference quotient table
vector<double> V(i+1,0);
diffCoef_Table.emplace_back(V);
diffCoef_Table[i][0]=Point[i][1]; // The first column of the difference quotient table is the function value
}
for(int k=1;k<=n;++k){
// Recursively calculate the difference quotient table
for(int i=k;i<=n;++i){
diffCoef_Table[i][k]=(diffCoef_Table[i][k-1]-diffCoef_Table[i-1][k-1])/(Point[i][0]-Point[i-k][0]);
}
}
print_chashang_table(diffCoef_Table);
vector<double> ans(n+1,0);
ans[0]=Point[0][1];
for(int k=1;k<=n;++k){
vector<double>s={
diffCoef_Table[k][k]};
for(int j=0;j<=k-1;++j){
s=mul(s,{
-Point[j][0],1});
}
ans=add(ans,s);
}
return ans;
}
int main(){
vector<vector<double>> P={
{
0,0},{
2,0},{
1,1},{
5,3}};
vector<double> s=Newton(P);
cout<<endl;
print(s);
system("pause");
return 0;
}
边栏推荐
- 【leetcode】22. bracket-generating
- 食品行业仓储条码管理系统解决方案
- Recommendation | recommendation of 9 psychotherapy books
- Comprehensive ability evaluation system
- asp. Core is compatible with both JWT authentication and cookies authentication
- HotSpot VM
- MySQL transaction isolation level
- 2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- Fedora/rehl installation semanage
猜你喜欢
Figure application details
Basic knowledge of binary tree, BFC, DFS
Recommendation | recommendation of 9 psychotherapy books
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
About some basic DP -- those things about coins (the basic introduction of DP)
CertBot 更新证书失败解决
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
[PSO] Based on PSO particle swarm optimization, matlab simulation of the calculation of the lowest transportation cost of goods at material points, including transportation costs, agent conversion cos
Recommendation system (IX) PNN model (product based neural networks)
随机推荐
CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
asp. Core is compatible with both JWT authentication and cookies authentication
hashlimit速率控制
Data processing methods - smote series and adasyn
绑定在游戏对象上的脚本的执行顺序
About some basic DP -- those things about coins (the basic introduction of DP)
2/13 review Backpack + monotonic queue variant
What is the difference between gateway address and IP address in tcp/ip protocol?
[Zhao Yuqiang] deploy kubernetes cluster with binary package
cdc 能全量拉去oracle 表嘛
Practical development of member management applet 06 introduction to life cycle function and user-defined method
CADD课程学习(8)-- 化合物库虚拟筛选(Virtual Screening)
我想问一下 按照现在mysql-cdc的设计,全量阶段,如果某一个chunk的binlog回填阶段,
Solve the compilation problem of "c2001: line breaks in constants"
Several important classes in unity
Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
Hashlimit rate control
Stable Huawei micro certification, stable Huawei cloud database service practice
JVM garbage collector concept
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution