All pastes #2071819 Raw Edit

Something

public python v1 · immutable
#2071819 ·published 2011-05-30 04:14 UTC
rendered paste body
'''Created on May 22, 2011@author: sugarfrosted'''from numpy import concatenatefrom numpy import arrayfrom numpy import array_splitfrom numpy import arangefrom numpy import dotfrom numpy import copyfrom math import sinfrom math import cosfrom numpy import matrixdef RREF( M):    if not M: return    lead = 0    rowCount = len(M)    columnCount = len(M[0])    for r in range(rowCount):        if lead >= columnCount:            return        i = r        while M[i][lead] == 0:            i += 1            if i == rowCount:                i = r                lead += 1                if columnCount == lead:                    return        M[i],M[r] = M[r],M[i]        lv = M[r][lead]        M[r] = [ mrx / lv for mrx in M[r]]        for i in range(rowCount):            if i != r:                lv = M[i][lead]                M[i] = [ iv - lv*rv for rv,iv in zip(M[r],M[i])]        lead += 1         def augment(a):    SIZE=a.shape[1]    b= array_split(a,SIZE,axis=1)[SIZE-1]    return bdef polyBfit(XYp,degree):    XY=XYp.copy()    temp=array_split(XY,2,axis=1)    X=temp[0]    Y=temp[1]    b=Y.copy()    power=X.copy()    A=copy(Y)    A.fill(1.)    for i in range(0,degree):        A=concatenate((power,A),axis=1)        power=power*X    Ap=dot(A.T,A)    bp=dot(A.T,b)    ans=concatenate((Ap,bp),axis=1)    calc=ans.tolist()    RREF(calc)    return array(calc)def SineFit(XYp):    XY=XYp.copy()    temp=array_split(XY,2,axis=1)    X=temp[0].copy()    Y=temp[1].copy()    A=X.copy()    A.fill(1.)    mylist=X.tolist()    sine = map(sin, mylist)    A=concatenate(((array(sine),A)),axis=1)    cosi = map(cos, mylist)    A=concatenate(((array(cosi),A)),axis=1)    Ap=dot(A.T,A)    bp=dot(A.T,Y)    ans=concatenate((Ap,bp),axis=1)    calc=ans.tolist()    RREF(calc)    return array(calc)#if __name__ == '__main__':XY=array([[0.,75.],          [1.,80.],          [2.,88.],          [3.,96.],          [4.,104.],          [5.,113.],          [6.,112.],          [7.,112.],          [8.,115.],          [9.,106.],          [10.,90.],          [11.,79.]])print SineFit(XY)