当前位置:网站首页>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. ]
边栏推荐
- 一个优酷VIP会员帐号可以几个人用的设备同时登录如何共享多人使用优酷会员账号?
- 【人脸识别】基于直方图Histogram实现人脸识别附matlab代码
- After 4 years of developing two-sided meituan, we finally lost: the interview question of volatile keyword function and principle
- 【单片机仿真】(二十)ORG — 设置起始地址
- C language foundation day4 array
- GraphQL初识
- [single chip microcomputer simulation] (XI) instruction system logic operation instruction - logic and instruction anl, logic or instruction ORL
- This is a mathematical problem
- 2. Actual use of asynctool framework
- [PHP] tp6 multi table connection query
猜你喜欢

05-中央处理器

Advanced usage of the responsibility chain pattern

MySQL日志管理和完全备份增量备份与恢复
![[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

Can't access this website can't find DNS address DNS_ PROBE_ What about started?

1. Introduction, analysis and implementation of asynctool framework

Summary of the most complete methods of string interception in Oracle
![[MCU simulation] (XX) org - set start address](/img/9e/4e44dd779b0de28a190d86fbb1c2c0.png)
[MCU simulation] (XX) org - set start address

【模板记录】字符串哈希判断回文串

Que se passe - t - il lorsque vous compilez et installez une base de données MySQL bloquée dans un système Linux?
随机推荐
yolov5 opencv DNN 推理
【单片机仿真】(十)指令系统 — 算术运算指令 之 乘法指令、除法
多项式插值拟合(三)
Introduction to wangeditor (entry level)
MySQL replication table
ResNet学习笔记
This is a mathematical problem
【单片机仿真】(四)寻址方式 — 寄存器寻址与直接寻址
CorelDRAW 安装不了解决方法
SQL经典练习题(x30)
[MCU simulation] (VI) addressing mode - index addressing and relative addressing
Analysis skills of time complexity and space complexity
[MCU simulation] (I) proteus8.9 installation tutorial
From the perspective of MySQL architecture, how does an SQL statement execute?
[face recognition] face recognition based on histogram histogram with matlab code
Fiddler grabbing
while 循环
Redis' simple dynamic string SDS
【单片机仿真】(五)寻址方式 — 立即寻址与寄存器间接寻址
【单片机仿真】(十九)介绍汇编、汇编指令、伪指令