You're probably looking at an absolute calibration error. The +/-4C tolerance of the suggested temperature sensor is .. quite horrid, and is what you're seeing here.
Actually, if you look further. Typical specification is +/-2C for all sensors, but may vary from -4C to +6C (!!). That's basically a range of unknown of almost 10 degrees.
You could calibrate the sensor , and as long the slope is accurate, you're still getting a pretty absolute measurement. How accurate? Well, how accurate can you calibrate temperature.
If you assume your reference tells you the measurements are always +3C off, then sure .. subtract -3C from the output and leave it there. May not be very accurate because you're assuming your reference is spot on, and at exactly the same temperature as your sensor is. Even if you did manage that, the sensor would probably have a terrible drift over time as well..
Anyway, on the formula of the input. If you do got the MCP9701, then:
$$V_{0C} = 400mV$$
$$T_C=19.5mV/C$$
$$V_{OUT} = T_C \cdot T_A + V_{0C}$$
$$ \implies 19.5 \cdot T + 400 = output$$
If you want to measure up to about 45 to 50C, you could use the internal reference of the Arduino controller. This is 1.1V for an ATMEGA328. The useful thing about this is that you aren't using the power supply as a reference, which is pretty worse if you want somewhat accurate readings.
At 1.1V, you can calculate a new formula:
The offset is 400mV. 10-bit ADC means that 1.1V will get divided into \$2^{10}\$ steps, which is 1024.
\$\frac{1.1V}{1024}=1.07mV\$ per step
400mV means that you have bytecode 373.8 if the temperature sensor is reading 0C. This is your offset samplecode.
The slope is 19.5mV. ONce again .. 19.5/1.07 is 18(.2) per degree.. So, you could say that the samplecode is derived from:
$$samplecode=373.8+18.2 \cdot T$$
$$T=\frac{samplecode-373.8}{18.2}$$
Simple algebra. Plug one of them into the other and simplify:
mv = code * 5000/1024
temp = (mv - 500) / 10
temp*10 = mv - 500
temp*10 = code * 5000/1024 - 500
temp*10 = (code * 5000) / 1024 - 500
(add divisor/2 before performing an integer division for rounding)
temp*10 = (code * 5000 + 512) / 1024 - 500
temp*10 = ((code * 5000 + 512) >> 10) - 500
One multiply, one shift right by 10, one addition, and one subtraction. Then convert to BCD and display it.
However, if you have an 8-bit ADC, you're probably going to want to divide by 256 instead of 1024 (shift right by 8 instead of 10) and add 128 instead of 512.
And here is an algorithm for converting binary to BCD: http://www.eng.utah.edu/~nmcdonal/Tutorials/BCDTutorial/BCDConversion.html
Just run that, split into groups of 4 bits, and drive each digit in the display with one group (after decoding to the proper 7 segment signals, of course).
Best Answer
No, there is no formula that can calculate the resistors temperature given only the resistor value, the voltage across the resistor, and time.
You need much more information for this calculation, including the ambient temperature, the thermal mass of the resistor, the rate of heat conduction through the resistor leads, and the rate of heat loss to the ambient air.