from scipy import interpolate
import matplotlib.pyplot as plt
import numpy as np

def f(x):
    x_points = [ 0, 1, 2, 3, 4, 5]
    y_points = [0,1,4,9,16,25]  #实际函数关系式为:y=x^2

    xnew = np.linspace(min(x_points),max(x_points),100) #新制作100个x值。(等差、list[]形式存储)

    tck = interpolate.splrep(x_points, y_points)
    ynew = interpolate.splev(xnew, tck) #通过拟合的曲线,计算每一个输入值。(100个结果,list[]形式存储)

    plt.scatter(x_points[:], y_points[:], 25, "red") #绘制散点
    plt.plot(xnew,ynew) #绘制拟合曲线图
    plt.show()
    return interpolate.splev(x, tck)

print(f(10))

结果:

参考资料:

https://stackoverflow.com/questions/31543775/how-to-perform-cubic-spline-interpolation-in-python

https://docs.scipy.org/doc/scipy/reference/tutorial/interpolate.html

最新文章

  1. 一步步构造自己的vue2.0+webpack环境
  2. 35、重新复习html与css(1)
  3. java的封装
  4. iOS - OC/Swift:验证手机号/固话用正则表达式
  5. SecureCRT清屏
  6. 通过源码看android系列之multidex库
  7. ClassLoader(摘录)
  8. 利用merge优化
  9. easyui 获取cloumns字段
  10. Memcached在.net中的应用
  11. dd if=/dev/zero of=的含义是什么?Linux 下的dd命令使用详解
  12. Delphi 常用API 函数
  13. 【转】IntelliJ IDEA2016.1 + maven 创建java web 项目
  14. 复制vmware中的centos后无法上网问题
  15. Python学习笔记十一
  16. HangFire循环作业中作业因执行时间太长未完成新作业开启导致重复数据的问题
  17. OpenCV教程(43) harris角的检测(1)
  18. ssm,dubbo框架搭建得配置文件
  19. IFE2017笔记
  20. MySQL存储引擎对比

热门文章

  1. JVM中垃圾收集算法总结
  2. Go基础系列:数据类型转换(strconv包)
  3. Python 通过 SMTP 发送邮件
  4. Redis学习笔记(2)-新建虚拟电脑,安装系统CentOSMini
  5. c#的WebService和调用
  6. spring boot @ResponseBody转换JSON 时 Date 类型处理方法,Jackson和FastJson两种方式,springboot 2.0.9配置fastjson不生效官方解决办法
  7. JavaScript碎片—函数闭包(模拟面向对象)
  8. mac gulp: command not found
  9. 关于Object数组强转成Integer数组的问题:Ljava.lang.Object; cannot be cast to [Ljava.lang.Integer;
  10. 初识HTTP协议web开发