当前位置:网站首页>Lagrange polynomial
Lagrange polynomial
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;
}
vector<double>Lagrange(vector<vector<double>> Point){
int n=Point.size()-1; // interpolation ans by n Power
if(n==-1){
cout<<" error "<<endl;
}
vector<double> ans(n,0);
for(int k=0;k<=n;++k)
{
double Poly_k_const=Point[k][1];
vector<double> Poly_k={
1};
for(int i=0;i<=n;++i)
{
if(i==k) continue;
Poly_k=mul(Poly_k,{
-Point[i][0],1}); // Molecular multiplication (x-Point[i][0])
Poly_k_const/=(Point[k][0]-Point[i][0]);
}
for(int i=0;i<Poly_k.size();++i){
Poly_k[i]*=Poly_k_const;
}
ans=add(ans,Poly_k);
}
return ans;
}
边栏推荐
- Basic use of MySQL (it is recommended to read and recite the content)
- Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
- View 工作流程
- Fundamentals of SQL database operation
- Fedora/rehl installation semanage
- Python book learning notes - Chapter 09 section 01 create and use classes
- Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
- Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
- Script lifecycle
- CertBot 更新证书失败解决
猜你喜欢
The value of two date types is subtracted and converted to seconds
电脑钉钉怎么调整声音
Cross domain and jsonp details
1291_Xshell日志中增加时间戳的功能
Class A, B, C networks and subnet masks in IPv4
1291_ Add timestamp function in xshell log
What is the difference between gateway address and IP address in tcp/ip protocol?
Comprehensive ability evaluation system
[Zhao Yuqiang] deploy kubernetes cluster with binary package
Path of class file generated by idea compiling JSP page
随机推荐
P3500 [poi2010]tes intelligence test (two points & offline)
In depth MySQL transactions, stored procedures and triggers
2/12 didn't learn anything
Lora gateway Ethernet transmission
Tips for using dm8huge table
R note prophet
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
User datagram protocol UDP
C. The third problem
DM8 backup set deletion
Query the number and size of records in each table in MySQL database
2328. Number of incremental paths in the grid graph (memory search)
[Zhao Yuqiang] deploy kubernetes cluster with binary package
图应用详解
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
About some basic DP -- those things about coins (the basic introduction of DP)
Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
电脑钉钉怎么调整声音
拉格朗日插值法
Recommendation system (IX) PNN model (product based neural networks)