# -*- 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()

  

最新文章

  1. 「译」JUnit 5 系列:架构体系
  2. js从外部获取图片
  3. Android (二维码)关于java.lang.UnsatisfiedLinkError的小案例
  4. Intellisense for Xrm.Page in CRM 2011
  5. BZOJ 3505
  6. dijkstra,bellman-ford,floyd分析比较
  7. LeetCode Balanced Binary Tree (判断平衡树)
  8. javascript 上传 预览图片 兼容 谷歌 ie
  9. 搭建LAMP架构
  10. javascript变量说明
  11. 微信小程序学习总结(1)
  12. Ext JS 5 beta版发布
  13. localStorage sessionStorage cookie indexedDB
  14. python 匿名函数&内置函数
  15. Disconf源码分析之启动过程分析上(1)
  16. python3+selenium入门07-元素等待
  17. 判断手机是安卓还是ios
  18. python中,类方法和静态方法区别。
  19. ztree删除某个节点下的全部子节点后,父节点图标还是文件夹
  20. BBS-项目流程分析-表的创建

热门文章

  1. Oracle Statistic 统计信息 小结
  2. HDU 4035 Maze 概率DP 搜索
  3. java导出Excel 好文收藏
  4. day 2Linux软件从主机安装到服务器和安装JDK软件
  5. 多个sshkey 指定key来clone仓库
  6. [连载]Java程序设计(03)---任务驱动方式:寻找高富帅和屌丝
  7. NOSQL之MONGODB
  8. 如何彻底卸载Jenkins(Windows版本)
  9. maven 知识点2
  10. 【python】正则表达式-常用函数