当前位置:网站首页>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;
}
边栏推荐
- How can programmers resist the "three poisons" of "greed, anger and ignorance"?
- 729. My schedule I (set or dynamic open point segment tree)
- C. The Third Problem(找规律)
- 1291_Xshell日志中增加时间戳的功能
- Sentinel sliding window traffic statistics
- Easyrecovery靠谱不收费的数据恢复电脑软件
- Global and Chinese markets for patent hole oval devices 2022-2028: Research Report on technology, participants, trends, market size and share
- 2327. 知道秘密的人数(递推)
- hashlimit速率控制
- How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server
猜你喜欢
1291_Xshell日志中增加时间戳的功能
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
Slow SQL fetching and analysis of MySQL database
Stable Huawei micro certification, stable Huawei cloud database service practice
Certbot failed to update certificate solution
Practical development of member management applet 06 introduction to life cycle function and user-defined method
Data processing methods - smote series and adasyn
Stable Huawei micro certification, stable Huawei cloud database service practice
Viewing and verifying backup sets using dmrman
Easyrecovery靠谱不收费的数据恢复电脑软件
随机推荐
How does computer nail adjust sound
1291_ Add timestamp function in xshell log
What is the difference between gateway address and IP address in tcp/ip protocol?
P2022 interesting numbers (binary & digit DP)
Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
Figure application details
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
食品行业仓储条码管理系统解决方案
2328. 网格图中递增路径的数目(记忆化搜索)
2/11 matrix fast power +dp+ bisection
View 工作流程
coreldraw2022新版本新功能介绍cdr2022
P2022 有趣的数(二分&数位dp)
Sentinel sliding window traffic statistics
Practical development of member management applet 06 introduction to life cycle function and user-defined method
Introduction to hashtable
Comprehensive ability evaluation system
1291_Xshell日志中增加时间戳的功能
Mlapi series - 04 - network variables and network serialization [network synchronization]