当前位置:网站首页>On Lagrange interpolation and its application
On Lagrange interpolation and its application
2022-07-03 16:46:00 【Ouye xjx】
Preface
I've been doing for many years NOI The original title is , And then it did [NOI2019] robot , I was surprised to find that I didn't learn Lagrange interpolation !
There was an inserted question in the previous provincial topic ([ Provincial election joint examination 2022] Tree filling ), But in O n e I n D a r k \rm O\red{neInDark} OneInDark Sterling inversion is used under the recommendation of . Actually, pulling and inserting is very simple , And it is more suitable to do things like filling trees 、 Robots are like this DP Optimize the topic .
brief introduction
Stick to others
In numerical analysis , Lagrange interpolation is based on French 18 Century mathematician Joseph · A polynomial interpolation method named by Lagrange . If you observe a physical quantity in practice , The corresponding observations are obtained in several different places , Lagrange interpolation can find a polynomial , It just takes the observed value at each observation point . The above polynomial is called Lagrange ( interpolation ) polynomial .
Lagrange interpolation
as everyone knows , Give a n n n Polynomial of degree n + 1 n+1 n+1 A point value can uniquely find this polynomial , A simple solution is to list n + 1 n+1 n+1 Equation and then use Gauss elimination , Complexity O ( n 3 ) O(n^3) O(n3), It is often accompanied by the problem of accuracy .
Lagrange interpolation can be used in O ( n 2 ) O(n^2) O(n2) Find the polynomial with enough accuracy in time .
Directly up Lagrange interpolation formula :
f ( x ) = ∑ i = 0 n y i ∏ j ≠ i x − x j x i − x j f(x)=\sum_{i=0}^ny_i\prod_{j\neq i}\frac{x-x_j}{x_i-x_j} f(x)=i=0∑nyij=i∏xi−xjx−xj This formula is very clever , Because you can find that it can just get all the point values , And the maximum number is n n n.
Using this formula to directly find polynomials is also O ( n 3 ) O(n^3) O(n3)( It's slower than high consumption ), But it can be optimized !
We can find out g ( x ) = ∏ i = 0 n ( x − x i ) g(x)=\prod_{i=0}^n(x-x_i) g(x)=∏i=0n(x−xi), Then enumeration y i y_i yi First of all O ( n ) O(n) O(n) Calculate the following ∏ j ≠ i 1 x i − x j \prod_{j\neq i}\frac{1}{x_i-x_j} ∏j=ixi−xj1, And then because of g ( x ) g(x) g(x) It was not cut off when calculating , So single ( x − x i ) (x-x_i) (x−xi) Divisibility g ( x ) g(x) g(x), direct O ( n ) O(n) O(n) Recursively find ∏ j ≠ i ( x − x j ) \prod_{j\neq i}(x-x_j) ∏j=i(x−xj) that will do ( Pay attention to special judgment x i = 0 x_i=0 xi=0). In this way, the total complexity is reduced to O ( n 2 ) O(n^2) O(n2).
Find the value of a single point
Here, to find the value of a single point means to give k ∉ { x i ∣ 0 ≤ i ≤ n } k\notin \{x_i|0\le i\le n\} k∈/{ xi∣0≤i≤n}, We need to ask for f ( k ) f(k) f(k).
Obviously, we can directly find f ( x ) f(x) f(x) Then bring in the solution , But when our goal is only to find f ( k ) f(k) f(k) when , Doing so is cumbersome and inefficient .
We might as well bring Lagrange interpolation formula directly :
f ( k ) = ∑ i = 0 n y i ∏ j ≠ i k − x j x i − x j f(k)=\sum_{i=0}^ny_i\prod_{j\neq i}\frac{k-x_j}{x_i-x_j} f(k)=i=0∑nyij=i∏xi−xjk−xj Because it is no longer a polynomial , So we can O ( n ) O(n) O(n) Find all in time ∏ j ≠ i ( k − x j ) \prod_{j\neq i}(k-x_j) ∏j=i(k−xj), Then enumerate each time y i y_i yi Just ask ∏ j ≠ i 1 x i − x j \prod_{j\neq i}\frac{1}{x_i-x_j} ∏j=ixi−xj1 了 . Although still O ( n 2 ) O(n^2) O(n2), But it reduces the constant and is simpler .
O(n) Find the value of a single point
Or just ask f ( k ) f(k) f(k).
In most topics applied to pull and insert , this n + 1 n+1 n+1 A point value satisfies subscript continuity , Or equidistant , namely x 1 − x 0 = x 2 − x 1 = . . . = x n − x n − 1 x_1-x_0=x_2-x_1=...=x_n-x_{n-1} x1−x0=x2−x1=...=xn−xn−1.
At this time, we can do some pretreatment ( For example, when the spacing is equal to 1 When , You need to preprocess the inverse of factorial ), Then you can do it once O ( 1 ) O(1) O(1) Find out ∏ j ≠ i 1 x i − x j \prod_{j\neq i}\frac{1}{x_i-x_j} ∏j=ixi−xj1.( Special attention should be paid to symbols )
application
There's a classic question : Calculation ∑ i = 1 n i k \sum_{i=1}^ni^k ∑i=1nik. This problem can obviously be inversed by Stirling O ( k log k ∼ k 2 ) O(k\log k\sim k^2) O(klogk∼k2) solve .
As we all know, this thing is about n n n Of k + 1 k+1 k+1 Sub polynomial , So we can O ( k ) O(k) O(k)( Ignore fast exponents , You can also use a linear sieve ) Before finding out k + 2 k+2 k+2 A point value , Then use the above method O ( k ) O(k) O(k) Pull and insert n n n Answer at , In this way, the total complexity is only O ( k ) O(k) O(k).
More practical scenarios are in some DP In question , For example, you need to ask m m m individual DP Value to transfer , But you find this m m m A function with a point value is a function with a small number of times n n n Sub polynomial , Then you can just ask for the front n + 1 n+1 n+1 individual DP value , The rest can be pulled and inserted .
Generally, it needs inductive proof to see that this is a polynomial , But I will not
边栏推荐
- Détails du contrôle de la congestion TCP | 3. Espace de conception
- [combinatorics] polynomial theorem (polynomial theorem | polynomial theorem proof | polynomial theorem inference 1 item number is the number of non negative integer solutions | polynomial theorem infe
- Yu Wenwen, Hu Xia and other stars take you to play with the party. Pipi app ignites your summer
- Daily code 300 lines learning notes day 10
- 于文文、胡夏等明星带你玩转派对 皮皮APP点燃你的夏日
- function overloading
- 跟我学企业级flutter项目:简化框架demo参考
- 中南大学|通过探索理解: 发现具有深度强化学习的可解释特征
- Interpretation of several important concepts of satellite antenna
- What material is sa537cl2? Analysis of mechanical properties of American standard container plate
猜你喜欢
CC2530 common registers for crystal oscillator settings
What material is sa537cl1? Sa537cl1 corresponds to the national standard material
智慧之道(知行合一)
To resist 7-Zip, list "three sins"? Netizen: "is the third key?"
Two sides of the evening: tell me about the bloom filter and cuckoo filter? Application scenario? I'm confused..
IDEA-配置插件
消息队列消息丢失和消息重复发送的处理策略
2022.02.14_ Daily question leetcode five hundred and forty
Idea configuration plug-in
Le zèbre a été identifié comme un chien, et la cause de l'erreur d'AI a été trouvée par Stanford
随机推荐
QT串口ui设计和解决显示中文乱码
网络安全web渗透技术
[combinatorics] recursive equation (outline of recursive equation content | definition of recursive equation | example description of recursive equation | Fibonacci Series)
[statement] about searching sogk1997 and finding many web crawler results
Caching mechanism of Hibernate / session level caching mechanism
【剑指 Offer】58 - II. 左旋转字符串
8 cool visual charts to quickly write the visual analysis report that the boss likes to see
Recommendation of good books on learning QT programming
Aike AI frontier promotion (7.3)
What material is sa537cl2 equivalent to in China? Sa537cl2 corresponding material
What kind of material is 14Cr1MoR? Analysis of chemical composition and mechanical properties of 14Cr1MoR
ucore概述
Mysql 单表字段重复数据取最新一条sql语句
Mysql database DDL and DML
Cocos Creator 2.x 自动打包(构建 + 编译)
Develop team OKR in the way of "crowdfunding"
arduino-esp32:LVGL项目(一)整体框架
Visual SLAM algorithms: a survey from 2010 to 2016
MySQL single table field duplicate data takes the latest SQL statement
香港理工大学|数据高效的强化学习和网络流量动态的自适应最优周界控制