python plot绘制图片+ 最小二乘--y = c*t**lam + 迭代值和迭代精度

##############################
import matplotlib as mpl
import matplotlib.pyplot as plt
a = [1,2,3]
b = [4,5,6]
plt.plot(a,b)
plt.show()

利用python绘制图片

###===============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
最小二乘算出c和lam = n

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



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值