Find the coefficients of the polynomial that fits the specified data in the least squares sense,,''' c = poly
文章由Byrx.net分享于2019-03-23 10:03:42
Find the coefficients of the polynomial that fits the specified data in the least squares sense,,''' c = poly
''' c = polyFit(xData,yData,m). Returns coefficients of the polynomial p(x) = c[0] + c[1]x + c[2]x^2 +...+ c[m]x^m that fits the specified data in the least squares sense. sigma = stdDev(c,xData,yData). Computes the std. deviation between p(x) and the data.''' from numpy import zerosfrom math import sqrtfrom gaussPivot import *def polyFit(xData,yData,m): a = zeros((m+1,m+1)) b = zeros(m+1) s = zeros(2*m+1) for i in range(len(xData)): temp = yData[i] for j in range(m+1): b[j] = b[j] + temp temp = temp*xData[i] temp = 1.0 for j in range(2*m+1): s[j] = s[j] + temp temp = temp*xData[i] for i in range(m+1): for j in range(m+1): a[i,j] = s[i+j] return gaussPivot(a,b)def stdDev(c,xData,yData): def evalPoly(c,x): m = len(c) - 1 p = c[m] for j in range(m): p = p*x + c[m-j-1] return p n = len(xData) - 1 m = len(c) - 1 sigma = 0.0 for i in range(n+1): p = evalPoly(c,xData[i]) sigma = sigma + (yData[i] - p)**2 sigma = sqrt(sigma/(n - m)) return sigma
相关内容
- python中使用MD5加密字符串,pythonmd5,#--encoding=
- python中创建关联数组(字典),python数组,# Dictionary
- 睡眠排序法 - python版,排序python,import sys,
- django获得用户ip地址,django获得ip,def get_clie
- python计算方程式的根的代码,python计算方程式,''' root
- matplotlib中,如何在坐标系中画一个矩形,matplotlib坐标系
- python连接url的不同部分,python连接url不同,import urlpa
- python通过while循环计算1到n的和,pythonwhile,def sum(n):
- 在python中使用tempconv模块转换问题,pythontempconv,from te
- python简单的函数定义和使用范例,python函数范例,def c
评论关闭