变换与线性回归

时间:2018-10-15 02:19:11

标签: python python-3.x

我有一个要绘制的方程:

C(T)=γ T +α T ^ 3

我意识到,如果我分解出“ T”,则它变为C(T)= T(γ+α* T ^ 2),类似于y = x(b + ax ^ 2)。

我已经为另一个数据集编写了大部分代码,但到现在为止,但是我得到的图形似乎不正确。有什么建议吗?

import numpy as np
import matplotlib.pyplot as plt

a=np.loadtxt("CvsT.txt", skiprows=1)

T=a[:,0]
C=a[:,1]

size=a.shape
rows=size[0]
xsum=0
x2sum=0
ysum=0
y2sum=0
xysum=0
for n in range(rows):
    xsum=xsum+T[n]
    x2sum=x2sum+pow(T[n],2)
    ysum=ysum+C[n]
    y2sum=y2sum+pow(C[n],2)
    xysum=xysum+T[n]*C[n]

xsum=xsum/rows
print(xsum)
x2sum=x2sum/rows
print(x2sum)
ysum=ysum/rows
print(ysum)
y2sum=y2sum/rows
print(y2sum)
xysum=xysum/rows
print(xysum)

a=(xysum-xsum*ysum)/(x2sum-xsum**2)
b=(x2sum*ysum-xsum*xysum)/(x2sum-xsum**2)
print("\nThe regression parameters are: a = ",a, "and b = ", b)

TModel=np.linspace(0.20,0.6,100)
CModel=TModel*(a*TModel+b)

plt.plot(TModel, CModel, color="red", linestyle="dashed")
plt.plot(T,C,markersize=10, color="green", marker="o", linestyle="-")
plt.xlabel("T (K)", fontweight="bold", fontsize="large")
plt.ylabel("C (mJ/mol K)", fontweight="bold", fontsize="large", 
color="green")

================================================ ==========================

T[K]    C[mJ/(mol K)
0.244948974 0.538887743
0.264575131 0.595294045
0.316227766 0.727323862
0.331662479 0.769456951
0.360555128 0.865332306
0.374165739 0.927931032
0.424264069 1.107329219
0.447213595 1.185116028
0.479583152 1.294874511
0.509901951 1.417527425
0.547722558 1.588395417

WCF error The client certificate is not provided. Specify a client certificate in ClientCredentials

0 个答案:

没有答案