当前位置:网站首页>拉格朗日插值法
拉格朗日插值法
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;
}
边栏推荐
- pd. to_ numeric
- Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
- Thread sleep, thread sleep application scenarios
- 判断当天是当月的第几周
- 【按鍵消抖】基於FPGA的按鍵消抖模塊開發
- Redis (replicate dictionary server) cache
- Maxay paper latex template description
- When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation
- Solution of storage bar code management system in food industry
- Lambda expression learning
猜你喜欢
VNCTF2022 WriteUp
Cross domain and jsonp details
lora网关以太网传输
20、 EEPROM memory (AT24C02) (similar to AD)
Redis (replicate dictionary server) cache
Solution to the problem that the root account of MySQL database cannot be logged in remotely
Solution of storage bar code management system in food industry
【可调延时网络】基于FPGA的可调延时网络系统verilog开发
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Thread sleep, thread sleep application scenarios
随机推荐
查询mysql数据库中各表记录数大小
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
Record the pit of NETCORE's memory surge
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
深入浅出node模板解析错误escape is not a function
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
1291_Xshell日志中增加时间戳的功能
MySQL master-slave replication
HotSpot VM
Slow SQL fetching and analysis of MySQL database
IDEA编译JSP页面生成的class文件路径
P3033 [usaco11nov]cow steelchase g (similar to minimum path coverage)
Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
Explain in simple terms node template parsing error escape is not a function
hashlimit速率控制
Lambda expression learning
Global and Chinese markets for endoscopic drying storage cabinets 2022-2028: Research Report on technology, participants, trends, market size and share
Mlapi series - 04 - network variables and network serialization [network synchronization]
Solve the compilation problem of "c2001: line breaks in constants"
Web components series (VII) -- life cycle of custom components