当前位置:网站首页>拉格朗日插值法
拉格朗日插值法
2022-07-06 04:16: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) //多项式乘法
{
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; //插值ans为n次方
if(n==-1){
cout<<"错误"<<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}); //分子连乘(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;
}
边栏推荐
- Security xxE vulnerability recurrence (XXe Lab)
- HotSpot VM
- 《2022年中国银行业RPA供应商实力矩阵分析》研究报告正式启动
- MySQL master-slave replication
- About some basic DP -- those things about coins (the basic introduction of DP)
- VPP性能测试
- P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
- STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
- 绑定在游戏对象上的脚本的执行顺序
- TCP/IP协议里面的网关地址和ip地址有什么区别?
猜你喜欢
绑定在游戏对象上的脚本的执行顺序
Lora gateway Ethernet transmission
Record the pit of NETCORE's memory surge
User datagram protocol UDP
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
[Key shake elimination] development of key shake elimination module based on FPGA
Slow SQL fetching and analysis of MySQL database
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
[tomato assistant installation]
随机推荐
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
E. Best Pair
自动化测试的好处
Record the pit of NETCORE's memory surge
2/11 matrix fast power +dp+ bisection
Overturn your cognition? The nature of get and post requests
Leetcode32 longest valid bracket (dynamic programming difficult problem)
2/13 qaq~~ greed + binary prefix sum + number theory (find the greatest common factor of multiple numbers)
Lombok principle and the pit of ⽤ @data and @builder at the same time
颠覆你的认知?get和post请求的本质
Codeforces Round #770 (Div. 2) B. Fortune Telling
IDEA编译JSP页面生成的class文件路径
1291_ Add timestamp function in xshell log
BOM - location, history, pop-up box, timing
math_极限&微分&导数&微商/对数函数的导函数推导(导数定义极限法)/指数函数求导公式推导(反函数求导法则/对数求导法)
MySQL master-slave replication
Redis (replicate dictionary server) cache
Basic knowledge of binary tree, BFC, DFS
Tips for using dm8huge table
Query the number and size of records in each table in MySQL database