当前位置:网站首页>Polynomial interpolation fitting (II)
Polynomial interpolation fitting (II)
2022-07-19 03:09:00 【HySmiley】
Polynomial second-order interpolation formula :y=ax^2+bx+c
interp1d(x,y,kind='quadratic') in kind Parameter values for 'quadratic'
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])
fc=interp1d(x,y,kind='quadratic')
xint=np.linspace(x.min(),x.max(),20)
print("x:",xint)
print("y:",fc(xint))
pl.scatter(xint,fc(xint),marker='o',c='r')
pl.plot(xint,fc(xint),color='blue')
pl.show()
Interpolation point :
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. ]
y: [1. 2.1966759 3.09196676 3.68587258 3.97839335 3.96952909
3.65927978 3.04764543 2.37894737 2.04210526 2.04210526 2.37894737
3.04764543 3.65927978 3.96952909 3.97839335 3.68587258 3.09196676
2.1966759 1. ]
Custom function implementation :
3 Point determination equation parameters
a=-((y2-y3)*x1-(x2-x3)*y1+x2*y3-x3*y2)/((x2-x3)*(x1-x2)*(x1-x3)) b = ((y2 - y3) * x1*x1 +x2*x2*y3-x3*x3*y2-(x2**2-x3**2)*y1) / ((x2 - x3) * (x1 - x2) * (x1 - x3)) c = ((x2*y3-x3*y2)*x1*x1 - (x2*x2*y3-x3*x3*y2) * x1 +(x2*x2*x3-x2*x3*x3)*y1) / ((x2 - x3) * (x1 - x2) * (x1 - x3))
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)
# 2、 secondary
def quadratic_inter(x1,y1,x2,y2,x3,y3,nx):
a=-((y2-y3)*x1-(x2-x3)*y1+x2*y3-x3*y2)/((x2-x3)*(x1-x2)*(x1-x3))
b = ((y2 - y3) * x1*x1 +x2*x2*y3-x3*x3*y2-(x2**2-x3**2)*y1) / ((x2 - x3) * (x1 - x2) * (x1 - x3))
c = ((x2*y3-x3*y2)*x1*x1 - (x2*x2*y3-x3*x3*y2) * x1 +(x2*x2*x3-x2*x3*x3)*y1) / ((x2 - x3) * (x1 - x2) * (x1 - x3))
ny=a*nx*nx+b*nx+c
return ny
#
for i in range(0,len(x),2):
if i + 2 < len(x):
print("---------")
# print(ny)
nx=[]
for val in xint:
if val>=x[i] and val<=x[i+2]:
nx.append(val)
print(nx)
nx=np.array(nx)
ny = quadratic_inter(x[i], y[i], x[i+1], y[i+1],x[i+2],y[i+2], nx)
print(ny)
pl.scatter(nx,ny,c='b',marker='o')
pl.plot(nx,ny,color='red')
pl.show()There is discontinuity in the segment connection , Can be optimized .

Interpolation point :
nx: [1.0, 1.2105263157894737, 1.4210526315789473, 1.631578947368421, 1.8421052631578947, 2.052631578947368, 2.263157894736842, 2.473684210526316, 2.6842105263157894, 2.894736842105263]
ny: [1. 2.04709141 2.87257618 3.47645429 3.85872576 4.01939058
3.95844875 3.67590028 3.17174515 2.44598338]
--------
nx: [3.1052631578947367, 3.3157894736842106, 3.526315789473684, 3.7368421052631575, 3.9473684210526314, 4.157894736842105, 4.368421052631579, 4.578947368421052, 4.789473684210526, 5.0]
ny: [2.44598338 3.17174515 3.67590028 3.95844875 4.01939058 3.85872576
3.47645429 2.87257618 2.04709141 1. ]
边栏推荐
- 【单片机仿真】(七)寻址方式 — 位寻址
- Redis和其他数据库的比较
- 重写equals为什么要重写hashcode
- MySQL master-slave replication + read write separation
- 【单片机仿真】(六)寻址方式 — 变址寻址与相对寻址
- zsh: command not found: mysql
- 【单片机仿真】(二十一)DB(Define Byte)— 定义字节
- Multi table query - case exercise
- About XML file (VI) - the difference between JSON and XML file
- 4. Some thoughts on asynctool framework
猜你喜欢

Detailed explanation of case when usage of SQL

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

04_ Service registration Eureka

【PHP】tp6多表连接查询
![深入理解机器学习——类别不平衡学习(Imbalanced Learning):样本采样技术-[人工采样技术之SMOTE采样法及Borderline-SMOTE采样法]](/img/9f/a0d03b23e66849f12150f9a72f36c5.png)
深入理解机器学习——类别不平衡学习(Imbalanced Learning):样本采样技术-[人工采样技术之SMOTE采样法及Borderline-SMOTE采样法]

MySQL日志管理和完全备份增量备份与恢复

Snapshot: data snapshot (data disclosure method)

4年开发二面美团最终败给:volatile关键字作用和原理这道面试题

GFS distributed file system

SysTick定时器的基础学习以及手撕代码
随机推荐
[MCU simulation] (XXI) dB (define byte) - define byte
【单片机仿真】(九)指令系统 — 算术运算指令 之 ADD、ADDC、SUBB、INC、DEC、DA
Que se passe - t - il lorsque vous compilez et installez une base de données MySQL bloquée dans un système Linux?
Tools and methods - Excel plug-in xltools
1. Introduction, analysis and implementation of asynctool framework
关于XML文件(六)-与JSON的区别
你能用到的Mysql常用命令
【PHP】tp6多表连接查询
About XML file (VI) - the difference between JSON and XML file
2. Actual use of asynctool framework
[redis] what is progressive rehash
[MCU simulation] (IV) addressing mode register addressing and direct addressing
05 central processing unit
Go language realizes sending SMS verification code and logging in
Full virtualization and semi virtualization
【MySQL】数据查询操作(select语句)
[MCU simulation] (IX) instruction system - add, ADDC, sub, Inc, Dec, Da of arithmetic operation instructions
[NoSQL] redis master-slave, sentinel, cluster
MySQL storage engine details
樂視還有400多比特員工?過著沒有老板的神仙日子 官方出來回應了...