58 lines
1.3 KiB
Python
58 lines
1.3 KiB
Python
import pandas as pd
|
|
import numpy as np
|
|
|
|
data = pd.read_csv('PTC_LUT.csv', comment='#')
|
|
|
|
temp = data['Temperature']
|
|
resist = data['Resistance']
|
|
|
|
volt = 403.2
|
|
dissiFac = 0.0195
|
|
ambTemp = 45
|
|
|
|
powerLoss = -1
|
|
powerCreate = 0
|
|
i = 0
|
|
|
|
# Find the zone where the lines intersect
|
|
while powerCreate>powerLoss:
|
|
powerLoss = (temp[i] - ambTemp)*dissiFac
|
|
powerCreate = np.square(volt) / resist[i]
|
|
i = i + 1
|
|
|
|
# put zone into points to solve for intersection
|
|
p1 = [i-1, (temp[i-1] - ambTemp)*dissiFac]
|
|
p2 = [i, (temp[i] - ambTemp)*dissiFac]
|
|
|
|
p3 = [i-1, np.square(volt) / resist[i-1]]
|
|
p4 = [i, np.square(volt) / resist[i]]
|
|
|
|
# Line 1 dy, dx and determinant
|
|
a11 = (p1[1] - p2[1])
|
|
a12 = (p2[0] - p1[0])
|
|
b1 = (p1[0]*p2[1] - p2[0]*p1[1])
|
|
|
|
# Line 2 dy, dx and determinant
|
|
a21 = (p3[1] - p4[1])
|
|
a22 = (p4[0] - p3[0])
|
|
b2 = (p3[0]*p4[1] - p4[0]*p3[1])
|
|
|
|
# Construction of the linear system
|
|
# coefficient matrix
|
|
A = np.array([[a11, a12],
|
|
[a21, a22]])
|
|
|
|
# right hand side vector
|
|
b = -np.array([b1,
|
|
b2])
|
|
# solve
|
|
try:
|
|
intersection_point = np.linalg.solve(A,b)
|
|
print('Intersection point detected at:', intersection_point)
|
|
print('Result:')
|
|
print('Temperature: ', intersection_point[1]/dissiFac+ambTemp)
|
|
print('Resistance: ', np.square(volt)/intersection_point[1])
|
|
except np.linalg.LinAlgError:
|
|
print('No single intersection point detected')
|
|
|