python计算对角线有理函数插值的方法

yipeiwu_com7年前Python基础

本文实例讲述了python计算对角线有理函数插值的方法。分享给大家供大家参考。具体实现方法如下:

''' p = rational(xData,yData,x)
  Evaluates the diagonal rational function interpolant p(x)
  that passes through he data points
'''  
from numpy import zeros
def rational(xData,yData,x):
  m = len(xData)
  r = yData.copy()
  rOld = zeros(m)
  for k in range(m-1):
    for i in range(m-k-1):
      if abs(x - xData[i+k+1]) < 1.0e-9:
        return yData[i+k+1]
      else:
        c1 = r[i+1] - r[i]
        c2 = r[i+1] - rOld[i+1]
        c3 = (x - xData[i])/(x - xData[i+k+1])
        r[i] = r[i+1] + c1/(c3*(1.0 - c1/c2) - 1.0)
        rOld[i+1] = r[i+1]
  return r[0]

希望本文所述对大家的Python程序设计有所帮助。

相关文章

django加载本地html的方法

django加载本地html的方法

django加载本地html from django.shortcuts import render from django.http import HttpResponse fro...

使用TensorFlow实现SVM

使用TensorFlow实现SVM

较基础的SVM,后续会加上多分类以及高斯核,供大家参考。 Talk is cheap, show me the code import tensorflow as tf from s...

python中sleep函数用法实例分析

本文实例讲述了python中sleep函数用法。分享给大家供大家参考。具体如下: Python中的sleep用来暂停线程执行,单位为秒 #----------------------...

Python实现图片添加文字

在工作中有时候会给图上添加文字,常用的是PS工具,不过我想通过代码的方式来给图片添加文字。 需要使用的Python的图像库:PIL.更加详细的知识点如下: Imaga模块:用来创建,打开...

研究Python的ORM框架中的SQLAlchemy库的映射关系

前面介绍了关于用户账户的User表,但是现实生活中随着问题的复杂化数据库存储的数据不可能这么简单,让我们设想有另外一张表,这张表和User有联系,也能够被映射和查询,那么这张表可以存储关...