当前位置:网站首页>拉格朗日插值法
拉格朗日插值法
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;
}
边栏推荐
- Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
- Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
- Solve the compilation problem of "c2001: line breaks in constants"
- DM8 backup set deletion
- About some basic DP -- those things about coins (the basic introduction of DP)
- 【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
- How does technology have the ability to solve problems perfectly
- math_ Derivative function derivation of limit & differential & derivative & derivative / logarithmic function (derivative definition limit method) / derivative formula derivation of exponential functi
- Le compte racine de la base de données MySQL ne peut pas se connecter à distance à la solution
- lora网关以太网传输
猜你喜欢

Chinese brand hybrid technology: there is no best technical route, only better products

How to solve the problem of slow downloading from foreign NPM official servers—— Teach you two ways to switch to Taobao NPM image server

10個 Istio 流量管理 最常用的例子,你知道幾個?

Figure application details

Deep learning framework installation (tensorflow & pytorch & paddlepaddle)

How many of the 10 most common examples of istio traffic management do you know?

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

Stack and queue

Practical development of member management applet 06 introduction to life cycle function and user-defined method
随机推荐
asp. Core is compatible with both JWT authentication and cookies authentication
绑定在游戏对象上的脚本的执行顺序
About some basic DP -- those things about coins (the basic introduction of DP)
P2022 有趣的数(二分&数位dp)
Mysql数据库慢sql抓取与分析
关于进程、线程、协程、同步、异步、阻塞、非阻塞、并发、并行、串行的理解
pd. to_ numeric
Lambda expression learning
Mlapi series - 04 - network variables and network serialization [network synchronization]
【PSO】基于PSO粒子群优化的物料点货物运输成本最低值计算matlab仿真,包括运输费用、代理人转换费用、运输方式转化费用和时间惩罚费用
How does technology have the ability to solve problems perfectly
Record the pit of NETCORE's memory surge
食品行业仓储条码管理系统解决方案
asp. Core is compatible with both JWT authentication and cookies authentication
The Research Report "2022 RPA supplier strength matrix analysis of China's banking industry" was officially launched
Global and Chinese market of rubber wheel wedges 2022-2028: Research Report on technology, participants, trends, market size and share
颠覆你的认知?get和post请求的本质
Solution to the problem that the root account of MySQL database cannot be logged in remotely
[introduction to Django] 11 web page associated MySQL single field table (add, modify, delete)
In depth MySQL transactions, stored procedures and triggers