当前位置:网站首页>拉格朗日插值法
拉格朗日插值法
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;
}
边栏推荐
- 【leetcode】1189. Maximum number of "balloons"
- During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
- Use js to complete an LRU cache
- 2328. 网格图中递增路径的数目(记忆化搜索)
- Security xxE vulnerability recurrence (XXe Lab)
- Fedora/REHL 安装 semanage
- Web components series (VII) -- life cycle of custom components
- 2/10 parallel search set +bfs+dfs+ shortest path +spfa queue optimization
- Path of class file generated by idea compiling JSP page
- In depth MySQL transactions, stored procedures and triggers
猜你喜欢

【leetcode】1189. Maximum number of "balloons"

Introduction to hashtable

Query the number and size of records in each table in MySQL database

解决“C2001:常量中有换行符“编译问题

Viewing and verifying backup sets using dmrman

Ipv4中的A 、B、C类网络及子网掩码

Lombok principle and the pit of ⽤ @data and @builder at the same time

食品行业仓储条码管理系统解决方案

【FPGA教程案例11】基于vivado核的除法器设计与实现

lora网关以太网传输
随机推荐
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
Basic use of MySQL (it is recommended to read and recite the content)
20、 EEPROM memory (AT24C02) (similar to AD)
Global and Chinese markets for otolaryngology devices 2022-2028: Research Report on technology, participants, trends, market size and share
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
About some basic DP -- those things about coins (the basic introduction of DP)
食品行业仓储条码管理系统解决方案
绑定在游戏对象上的脚本的执行顺序
[Zhao Yuqiang] deploy kubernetes cluster with binary package
1008 circular right shift of array elements (20 points)
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
Mixed development of QML and QWidget (preliminary exploration)
SSTI template injection explanation and real problem practice
DM8 archive log file manual switching
使用JS完成一个LRU缓存
判断当天是当月的第几周
Fundamentals of SQL database operation
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
What is the difference between gateway address and IP address in tcp/ip protocol?
Explain in simple terms node template parsing error escape is not a function