当前位置:网站首页>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;
}
边栏推荐
- HotSpot VM
- Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
- Cross domain and jsonp details
- DM8 backup set deletion
- Solution to the problem that the root account of MySQL database cannot be logged in remotely
- 10個 Istio 流量管理 最常用的例子,你知道幾個?
- [adjustable delay network] development of FPGA based adjustable delay network system Verilog
- Codeforces Round #770 (Div. 2) B. Fortune Telling
- MySql數據庫root賬戶無法遠程登陸解决辦法
- P2648 make money
猜你喜欢

Basic knowledge of binary tree, BFC, DFS
![[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](/img/41/27ce3741ef29e87c0f3b954fdef87a.png)
[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

【leetcode】1189. Maximum number of "balloons"

Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
![[network] channel attention network and spatial attention network](/img/b5/5e746f0dd6badcf0714cae05fc6e82.jpg)
[network] channel attention network and spatial attention network

MLAPI系列 - 04 - 网络变量和网络序列化【网络同步】

Certbot failed to update certificate solution

The value of two date types is subtracted and converted to seconds

捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统

CertBot 更新证书失败解决
随机推荐
Fedora/REHL 安装 semanage
Global and Chinese market of plasma separator 2022-2028: Research Report on technology, participants, trends, market size and share
Sentinel sliding window traffic statistics
【leetcode】22. bracket-generating
[network] channel attention network and spatial attention network
DM8 archive log file manual switching
【HBZ分享】ArrayList的增删慢查询快的原因
Script lifecycle
Yyds dry goods inventory web components series (VII) -- life cycle of custom components
VPP性能测试
Comprehensive ability evaluation system
Hashlimit rate control
lora网关以太网传输
Stable Huawei micro certification, stable Huawei cloud database service practice
Stable Huawei micro certification, stable Huawei cloud database service practice
729. My schedule I (set or dynamic open point segment tree)
颠覆你的认知?get和post请求的本质
绑定在游戏对象上的脚本的执行顺序
In depth MySQL transactions, stored procedures and triggers
2327. 知道秘密的人数(递推)