当前位置:网站首页>Polynomial interpolation fitting (I)
Polynomial interpolation fitting (I)
2022-07-19 03:08:00 【HySmiley】
Use polynomial interpolation to fit between points .
Polynomial equation :

Unfolding form :f(x)=a0x+a1x^2+a2x^3+...
Given n Plane coordinate points , It can be solved by polynomial equation n Parametric solutions of equations , And the solution is unique ( Self evidence ).
The solution adopts vandermund determinant .

Segment region fitting is sometimes used in image processing , Therefore, the interpolation method will n Add points between points .
First order equation :y=kx+b Two points are needed (x1,y1),(x0,y0)
Parameters k=(y1-y0)/(x1-x0),b=y0-k*x0
have access to scipy Interpolation classes in the library
for instance : Yes 5 First order interpolation between points
import numpy as np
from scipy.interpolate import interp1d,interp2d
import pylab as pl
x=np.array([1,2,3,4,5])
y=np.array([1,4,2,4,1])
fun=interp1d(x,y,kind='linear')# function y Is a series of points , according to x,y Relation derivation function
xint=np.linspace(x.min(),x.max(),20)
print(" library x:",xint)
print(" library y:",fun(xint))
pl.scatter(x,y,c='b',marker='o')
pl.plot(xint,fun(xint),color='red')
pl.show()Interpolated image

Output interpolation results
library x: [1. 1.21052632 1.42105263 1.63157895 1.84210526 2.05263158
2.26315789 2.47368421 2.68421053 2.89473684 3.10526316 3.31578947
3.52631579 3.73684211 3.94736842 4.15789474 4.36842105 4.57894737
4.78947368 5. ]
library y: [1. 1.63157895 2.26315789 2.89473684 3.52631579 3.89473684
3.47368421 3.05263158 2.63157895 2.21052632 2.21052632 2.63157895
3.05263158 3.47368421 3.89473684 3.52631579 2.89473684 2.26315789
1.63157895 1. ]
Custom interpolation
import numpy as np
from scipy.interpolate import interp1d,interp2d
import pylab as pl
#------------------------
x=np.array([1,2,3,4,5])
y=np.array([1,4,2,4,1])
xint=np.linspace(x.min(),x.max(),20)
# 1、 linear
def linear_inter(x0,y0,x1,y1,nx):
k=(y1-y0)/(x1-x0)
b=y0-k*x0
ny=k*nx+b
return ny
for i in range(1,len(x)):
print("----- The first ",i," Interval data -----")
# print(ny)
nx=[]
for val in xint:
if val>=x[i-1] and val<=x[i]:
nx.append(val)
print(nx)
nx=np.array(nx)
ny = linear_inter(x[i - 1], y[i - 1], x[i], y[i], nx)
print(" result ",ny)
pl.scatter(x,y,c='b',marker='o')
pl.plot(nx,ny,color='red')
pl.show()Because the segmented connection is different from the results in the above figure .

Obtained from each two-point interval y All values are equal .
----- The first 1 Interval data -----
[1.0, 1.2105263157894737, 1.4210526315789473, 1.631578947368421, 1.8421052631578947]
result [1. 1.63157895 2.26315789 2.89473684 3.52631579]
----- The first 2 Interval data -----
[2.052631578947368, 2.263157894736842, 2.473684210526316, 2.6842105263157894, 2.894736842105263]
result [3.89473684 3.47368421 3.05263158 2.63157895 2.21052632]
----- The first 3 Interval data -----
[3.1052631578947367, 3.3157894736842106, 3.526315789473684, 3.7368421052631575, 3.9473684210526314]
result [2.21052632 2.63157895 3.05263158 3.47368421 3.89473684]
----- The first 4 Interval data -----
[4.157894736842105, 4.368421052631579, 4.578947368421052, 4.789473684210526, 5.0]
result [3.52631579 2.89473684 2.26315789 1.63157895 1. ]
边栏推荐
猜你喜欢

04_服务注册Eureka

快照:数据快照(数据兜底方式)

Detailed explanation of case when usage of SQL

Oracle gets the last and first data (gets the first and last data by time)

Code demonstration of fcos face detection model in openvino

2. Actual use of asynctool framework
![[face recognition] face recognition based on histogram histogram with matlab code](/img/a6/ae776d084a207647501ca951e32000.png)
[face recognition] face recognition based on histogram histogram with matlab code

Redis和其他数据库的比较

【PHP】tp6多表连接查询
![2022-07-16:以下go语言代码输出什么?A:[];B:[5];C:[5 0 0 0 0];D:[0 0 0 0 0]。 package main import ( “fmt“ )](/img/e4/ff7f1e19583f42377307de7291f870.png)
2022-07-16:以下go语言代码输出什么?A:[];B:[5];C:[5 0 0 0 0];D:[0 0 0 0 0]。 package main import ( “fmt“ )
随机推荐
ncnn 线程
Multi table query - case exercise
4. Some thoughts on asynctool framework
Can't access this website can't find DNS address DNS_ PROBE_ What about started?
ubuntu清除cuda缓存
LETV has more than 400 employees? Living a fairy life without a boss, the official responded
3. Asynctool framework principle source code analysis
Snapshot: data snapshot (data disclosure method)
We should increase revenue and reduce expenditure
Pytorch best practices and code templates
显而易见的事情
人脸关键点检测
[MCU simulation] (IX) instruction system - add, ADDC, sub, Inc, Dec, Da of arithmetic operation instructions
05 central processing unit
[regression prediction] lithium ion battery life prediction based on particle filter with matlab code
【PHP】tp6多表连接查询
【单片机仿真】(十九)介绍汇编、汇编指令、伪指令
自动装配 & 集合注入
Specifications, multi table query basis
From the perspective of MySQL architecture, how does an SQL statement execute?