当前位置:网站首页>Lagrange polynomial
Lagrange polynomial
2022-07-06 04:21: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) // Polynomial multiplication
{
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; // interpolation ans by n Power
if(n==-1){
cout<<" error "<<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}); // Molecular multiplication (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;
}
边栏推荐
- How does technology have the ability to solve problems perfectly
- 食品行业仓储条码管理系统解决方案
- BOM - location, history, pop-up box, timing
- PTA tiantisai l1-078 teacher Ji's return (15 points) detailed explanation
- SharedPreferences 源码分析
- Overturn your cognition? The nature of get and post requests
- Yyds dry inventory automatic lighting system based on CC2530 (ZigBee)
- C. The third problem
- Jd.com 2: how to prevent oversold in the deduction process of commodity inventory?
- CADD课程学习(7)-- 模拟靶点和小分子相互作用 (柔性对接 AutoDock)
猜你喜欢
VNCTF2022 WriteUp
Viewing and verifying backup sets using dmrman
Fedora/REHL 安装 semanage
Solutions: word coverage restoration, longest serial number, Xiaoyu buys stationery, Xiaoyu's electricity bill
颠覆你的认知?get和post请求的本质
Comprehensive ability evaluation system
捷码赋能案例:专业培训、技术支撑,多措并举推动毕业生搭建智慧校园毕设系统
How do programmers teach their bosses to do things in one sentence? "I'm off duty first. You have to work harder."
[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
MySQL learning record 13 database connection pool, pooling technology, DBCP, c3p0
随机推荐
Lombok原理和同时使⽤@Data和@Builder 的坑
How can programmers resist the "three poisons" of "greed, anger and ignorance"?
Slow SQL fetching and analysis of MySQL database
Codeforces Round #770 (Div. 2) B. Fortune Telling
Guitar Pro 8.0最详细全面的更新内容及全部功能介绍
[network] channel attention network and spatial attention network
10 exemples les plus courants de gestion du trafic istio, que savez - vous?
hashlimit速率控制
729. My schedule I (set or dynamic open point segment tree)
1008 circular right shift of array elements (20 points)
Class A, B, C networks and subnet masks in IPv4
Implementation of knowledge consolidation source code 2: TCP server receives and processes half packets and sticky packets
Global and Chinese market of aircraft anti icing and rain protection systems 2022-2028: Research Report on technology, participants, trends, market size and share
P2102 floor tile laying (DFS & greed)
Solve the compilation problem of "c2001: line breaks in constants"
Recommendation | recommendation of 9 psychotherapy books
The global and Chinese market of negative pressure wound therapy unit (npwtu) 2022-2028: Research Report on technology, participants, trends, market size and share
VPP性能测试
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)