当前位置:网站首页>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;
}
边栏推荐
- Practical development of member management applet 06 introduction to life cycle function and user-defined method
- How to execute an SQL statement in MySQL
- Implementation of knowledge consolidation source code 1: epoll implementation of TCP server
- 解决“C2001:常量中有换行符“编译问题
- Patent | subject classification method based on graph convolution neural network fusion of multiple human brain maps
- In depth MySQL transactions, stored procedures and triggers
- 2327. Number of people who know secrets (recursive)
- 牛顿插值法
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- 拉格朗日插值法
猜你喜欢
题解:《单词覆盖还原》、《最长连号》、《小玉买文具》、《小玉家的电费》
颠覆你的认知?get和post请求的本质
[adjustable delay network] development of FPGA based adjustable delay network system Verilog
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
电脑钉钉怎么调整声音
解决“C2001:常量中有换行符“编译问题
[network] channel attention network and spatial attention network
MySql數據庫root賬戶無法遠程登陸解决辦法
[face recognition series] | realize automatic makeup
Understanding of processes, threads, coroutines, synchronization, asynchrony, blocking, non blocking, concurrency, parallelism, and serialization
随机推荐
Sorting out the latest Android interview points in 2022 to help you easily win the offer - attached is the summary of Android intermediate and advanced interview questions in 2022
电脑钉钉怎么调整声音
Fedora/REHL 安装 semanage
Web components series (VII) -- life cycle of custom components
拉格朗日插值法
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
1291_ Add timestamp function in xshell log
VPP performance test
Lambda expression learning
Viewing and verifying backup sets using dmrman
HotSpot VM
SharedPreferences 源码分析
2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
Leetcode32 longest valid bracket (dynamic programming difficult problem)
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
Lombok原理和同时使⽤@Data和@Builder 的坑
Solve the compilation problem of "c2001: line breaks in constants"
Lora gateway Ethernet transmission
How to realize automatic playback of H5 video