当前位置:网站首页>拉格朗日插值法
拉格朗日插值法
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;
}
边栏推荐
- Detailed explanation of serialization and deserialization
- 2328. 网格图中递增路径的数目(记忆化搜索)
- 自动化测试的好处
- Execution order of scripts bound to game objects
- 10 exemples les plus courants de gestion du trafic istio, que savez - vous?
- 80% of the diseases are caused by bad living habits. There are eight common bad habits, which are both physical and mental
- 【可调延时网络】基于FPGA的可调延时网络系统verilog开发
- . Net interprocess communication
- One question per day (Mathematics)
- Lora gateway Ethernet transmission
猜你喜欢

1291_ Add timestamp function in xshell log

Lora gateway Ethernet transmission

Fundamentals of SQL database operation

One question per day (Mathematics)

CertBot 更新证书失败解决

Solution of storage bar code management system in food industry

When debugging after pycharm remote server is connected, trying to add breakpoint to file that does not exist: /data appears_ sda/d:/segmentation

Path of class file generated by idea compiling JSP page
![[Key shake elimination] development of key shake elimination module based on FPGA](/img/47/c3833c077ad89d4906e425ced945bb.png)
[Key shake elimination] development of key shake elimination module based on FPGA

STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
随机推荐
HotSpot VM
AcWing 243. A simple integer problem 2 (tree array interval modification interval query)
Recommendation system (IX) PNN model (product based neural networks)
Interface idempotency
Deep learning framework installation (tensorflow & pytorch & paddlepaddle)
[FPGA tutorial case 12] design and implementation of complex multiplier based on vivado core
E. Best Pair
图应用详解
Global and Chinese markets for medical gas manifolds 2022-2028: Research Report on technology, participants, trends, market size and share
20、 EEPROM memory (AT24C02) (similar to AD)
2/11 matrix fast power +dp+ bisection
CertBot 更新证书失败解决
Network security - Security Service Engineer - detailed summary of skill manual (it is recommended to learn and collect)
During pycharm debugging, the view is read only and pause the process to use the command line appear on the console input
Yyds dry goods inventory hcie security Day11: preliminary study of firewall dual machine hot standby and vgmp concepts
Overturn your cognition? The nature of get and post requests
STC8H开发(十二): I2C驱动AT24C08,AT24C32系列EEPROM存储
Esp32 (based on Arduino) connects the mqtt server of emqx to upload information and command control
Security xxE vulnerability recurrence (XXe Lab)
[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