当前位置:网站首页>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. ]
边栏推荐
- GraphQL初识
- [MCU simulation] (XIV) instruction system bit operation instructions - bit data transmission instructions MOV, bit variable modification instructions
- yolov5 ncnn 推理
- RESNET learning notes
- 當你在Linux系統中編譯安裝MySQL數據庫卡住了怎麼辦?
- OpenVINO中的FCOS人脸检测模型代码演示
- 05_服务调用Ribbon
- 【单片机仿真】(二十一)DB(Define Byte)— 定义字节
- MySQL multi table query
- Redis' simple dynamic string SDS
猜你喜欢
随机推荐
05 central processing unit
D. Permutation Restoration(贪心/双指针/set)
[MCU simulation] (V) addressing mode - immediate addressing and register indirect addressing
JDBC连接Mysql数据库
Can't access this website can't find DNS address DNS_ PROBE_ What about started?
SQL经典练习题(x30)
【单片机仿真】(十六)控制转移类指令 — 无条件转移指令、条件转移指令
重写equals为什么要重写hashcode
【人脸识别】基于直方图Histogram实现人脸识别附matlab代码
仿射变换实现
[face recognition] face recognition based on histogram histogram with matlab code
【MySQL】MHA高可用
BiSeNetV1 面部分割
【单片机仿真】(七)寻址方式 — 位寻址
Summary of the most complete methods of string interception in Oracle
05-中央处理器
MySQL replication table
无法访问此网站无法找到DNS地址DNS_PROBE_STARTED怎么办?
【单片机仿真】(五)寻址方式 — 立即寻址与寄存器间接寻址
[MCU simulation] (XIX) introduction to assembly, assembly instructions, pseudo instructions









