[Python] Hermite 插值
2024-08-24 16:51:33
# -*- coding: utf-8 -*-
#Program 0.5 Hermite Interpolation import matplotlib.pyplot as plt
import numpy as np #计算基函数的导数值
def dl(i, xi):
result = 0.0
for j in range(0,len(xi)):
if j!=i:
result += 1/(xi[i]-xi[j])
result *= 2
return result #计算基函数值
def l(i, xi, x):
deno = 1.0
nu = 1.0 for j in range(0, len(xi)):
if j!= i:
deno *= (xi[i]-xi[j])
nu *= (x-xi[j]) return nu/deno #Hermite插值函数
def get_Hermite(xi, yi, dyi):
def he(x):
result = 0.0
for i in range(0, len(xi)):
result += (yi[i]+(x-xi[i])*(dyi[i]-2*yi[i]*dl(i, xi))) * ((l(i,xi,x))**2)
return result
return he import math
sr_x = [(i * math.pi) + (math.pi / 2) for i in range(-3, 3)]
sr_fx = [math.sin(i) for i in sr_x]
deriv = [0 for i in sr_x] # 导数都为 0
Hx = get_Hermite(sr_x, sr_fx, deriv) # 获得插值函数
tmp_x = [i * 0.1 * math.pi for i in range(-20, 20)] # 测试用例
tmp_y = [Hx(i) for i in tmp_x] # 根据插值函数获得测试用例的纵坐标 #画图
plt.plot(sr_x, sr_fx, 'ro')
plt.plot(tmp_x, tmp_y, 'b-')
plt.title('Hermite Interpolation')
plt.show()
最新文章
- 「译」JUnit 5 系列:架构体系
- js从外部获取图片
- Android (二维码)关于java.lang.UnsatisfiedLinkError的小案例
- Intellisense for Xrm.Page in CRM 2011
- BZOJ 3505
- dijkstra,bellman-ford,floyd分析比较
- LeetCode Balanced Binary Tree (判断平衡树)
- javascript 上传 预览图片 兼容 谷歌 ie
- 搭建LAMP架构
- javascript变量说明
- 微信小程序学习总结(1)
- Ext JS 5 beta版发布
- localStorage sessionStorage cookie indexedDB
- python 匿名函数&;内置函数
- Disconf源码分析之启动过程分析上(1)
- python3+selenium入门07-元素等待
- 判断手机是安卓还是ios
- python中,类方法和静态方法区别。
- ztree删除某个节点下的全部子节点后,父节点图标还是文件夹
- BBS-项目流程分析-表的创建