##############################
import matplotlib as mpl
import matplotlib.pyplot as plt
a = [1,2,3]
b = [4,5,6]
plt.plot(a,b)
plt.show()
利用python绘制图片
最小二乘算出c和lam = n###===============t ,s(t) 函数的最小二乘拟合函数======================### from numpy import * from math import * t = array([1.0,2.0,4.0,8.0,16.0,32.0,64.0]) s = array([4.22,4.02,3.85,3.58,3.44,3.02,2.59]) k = t m = s l = -1 ##==============对t取ln求和 for i in t: l = l+1 #print 'i:',i #print 'l:',l a = log(i,math.e) #print 'a:',a k[l] = a #print 'k[',l,']:',k[l] print k ###========================================### l = -1 for i in s: l = l+1 a = log(i,math.e) m[l] = a print m ###========================================### t = k s = m sumt = sum(t) #suma = int(suma) tt = sum(t*t) #aa = int(aa) wl = [[7,sumt],[sumt,tt]] wl = mat(wl) print 'wl:',wl sums = sum(s) ts = sum(t*s) wr = [[sums],[ts]] wr = mat(wr) print 'wr:',wr ans = wl.I * wr print 'ans:',ans m,n = ans m = float(m) c = math.e ** m print 'c:',c
迭代值和迭代精度计算from numpy import * #x1 last number x2 this number def a(x1,i,x2): w = 1.83928675521 i = i + 1 x1 = x2 x2 = 1 + 1 / x1 + 1 / (x1 ** 2) if abs((x1 - x2)) >= 10 ** -32: a(x1,i,x2) c = abs(w - x2)/abs(w - x1) print 'c:',c elif abs(x1 - x2) < 10 ** -100: print 'x1:',x1 print 'x2:',x2 print 'i:',i a(1.7,0,1.7)
添加汉字,不让其报错
# coding: utf-8