## Derivation of the Algorithm in gentherm2

Here's the Steinhart-Hart equation, which gives a thermistors characteristic curve that's within 0.02 C over the temperature range of interest (this, of course, assumes that your resistance measurements are that accurate!). Thanks to David Parrish for finding this.

```   1/T = A + B*ln(R) + C*ln(R)**3
```

The Steinhart-Hart coefficients for the GM sensor are A=0.00150664 B=0.00022484 C=1.25794e-07.

To solve it, first make it look like a matrix equation.

```   A + c1*B + c2*C = c3
```
where
```      c1 = ln(R)
c2 = ln(R)**3
c3 = 1/T
```
So, given three points (Tn, Rn):
```   for n = 1..3:
cn1 = ln(Rn)
cn2 = ln(Rn)**3
cn3 = 1/Tn

A*1 + B*c11 + C*c12 = c13
A*1 + B*c21 + C*c22 = c23
A*1 + B*c31 + C*c32 = c33
```
Do Gaussian elimination in a generic fashion. Subtract the top from each of the bottom two, resulting in:
```   B*(c21-c11) + C*(c22-c12) = c23-c13
B*(c31-c11) + C*(c32-c12) = c33-c13
```
Multiply the bottom one by (c21-c11)/(c31-c11):
```   B*(c21-c11) + C*(c32-c12)*(c21-c11)/(c31-c11) = (c33-c13)*(c21-c11)/(c31-c11)
```
Now subtract this from the top one:
```   C*((c22-c12) - (c32-c12)*(c21-c11)/(c31-c11)) = (c23-c13) - ((c33-c13)*(c21-c11)/(c31-c11))
```
And get C by itself:
```       (c23-c13) - (c33-c13)*(c21-c11)/(c31-c11)
C = -----------------------------------------
(c22-c12) - (c32-c12)*(c21-c11)/(c31-c11)
```
Now that C is known, solve for B:
```       c33-c13 - C*(c32-c12)
B = ---------------------
c31-c11
```
Then A,
```   A = c13 - B*c11 - C*c12
```
Now we need the original equation rewritten as T(R):
```   1/T = A + B*Ln(R) + C*(Ln(R))**3

T(R) = 1 / (A + B*ln(R) + C*ln(R)**3)
```

Here's a source for some test data (in fact it is encoded in gentherm2.c as the default values):

```   Date: Wed, 20 Feb 2002 16:42:22 -0500
From: "Camden Lindsay"
To: megasquirt@yahoogroups.com

just found this spec for an 88 audi quattro temp sensor (engine computer)

Degrees C            Ohms
0                  5 - 6.5K
20                  2 - 3 K
50                  700 - 900
100                  175 - 210

hope this helps

camden
```
Peter Florance told us about an old L-Jet-equipped BMW 528: http://www.firstfives.org/faq/ljet/528i_Ljet_schematic.PDF
``` 70f  1950-3000 ohms
100    950-1600
160    250- 550
```

Here is a plot of the Audi raw data against a curve generated by gentherm2. Also included are the raw data from Bruce's original gentherm program, in yellow (I assumed they were the GM sensor data, but I'm not sure now after comparing the output of gentherm with the airdenfactor.inc and thermfactor.inc files). 