Coolingh

by Juan Alban Franco

HTML

<html>
<head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/series-label.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
</head>
<body>
Lets use Newtons Cooling Equation to try and get an average cooling equation, at room temperature, for you baby's bottle. <br><br>
Newtons Cooling equation <br>
<i>T</i>(t)=<i>T</i><sub>a</sub> + ( <i>T<sub>o </sub></i> - <i>T<sub>a</sub></i>)e<sup>-<i>kt</i></sup>
<br/><br>
Start by recording the initial temperature of the bottle after it has been heated and record it in the first input box.<br>
Then, try to take a look at the thermostat and record the temperature of the bottle. Type that into the second input box. <br>
Record the amount of time you would like to wait and type the number into the third input box <br>
Lastly, once you have waited that amount of time, record the temperature of the bottle and type it into the fourth input box <br><br>


Input Bottle Temperature (Farenheit) <input type = "text" id = "T0" size = "3" value = "100"/><br>
Input Room Temperature (Farenheit) <input type = "text" id = "Ta" size = "3" value = "72"/><br>
Input Time Spent Cooling in minutes <input type = "text" id = "t" size = "3" value = "10"/><br>
Input Bottle Temperature after cooling <input type = "text" id = "Tt" size = "3" value = "80"/><br>
<br>

<p id = "text"></p>
<div id = minutes>
 How many minutes would you like to model? <input type = text id = max value = 10>
</div>
<p id = "equations"></p>

<input type = "button" style = "display :block" value = "Calculate Cooling Coeficient" id ="CalcK" >

<input type = "button" style = "display :none" value = "Calculate and Plot Equation" id = CalcEquation >

<div id = "chart" syle = "width : 50%"> </div>


</body>

</html>

JavaScript

var ta = 0;
var to = 0;
var t = 0;
var tt = 0;
var min = 0;
var max = 0;
var k = 0;
var x = new Array();
var result = new Array();
var coord = new Array();
$('#minutes').hide();

function find_k (ta,to,t,tt){
	return (-1*Math.log(((tt-ta)/(to-ta))))/t
}

	function calc(num){
		ta = Number($('#Ta').val());
	  to = Number($('#T0').val());
	  t = Number($('#t').val());
	  tt = Number($('#Tt').val());
	  
    if (num == 1){
			max = Number($('#max').val());
      for (var i = 0; i<= max ; i ++){ // i can be used as both the min and the dirver for the array since we dont use negative time..yet..
      		x[i] = i;
          result[i] = ta + (to - ta)*Math.pow(Math.E,(k*-i));
          coord[i] = [x[i], result[i] ];
          
      }
		plotValues();    
    }
   
   else{
     if(tt < ta){alert("Your final temperature cannot be lower than the ambient temperatur"); return false}
	  	k = find_k(ta,to,t,tt);
	  	var s = "Now that we figured out the cooling constant is  "+result+" , enter 			the amount of minutes you would like our model to calculate!" ;  
			s += " <br>Newtons Cooling equation <br> <i>T</i>(t)="+ta+" + ("+to+" - 		"+ta+")e<sup>-<i>"+k+"t</i></sup> <br/><br>"
  	  document.getElementById("text").innerHTML = s;
      $('#minutes').show();
      return true;
      }
	
}

function plotValues()
{
 
    chart = new Highcharts.Chart({
            chart: {
                renderTo: 'chart',
                type: 'line',
                marginRight: 130,
                marginBottom: 25
            },
            title: {
                text: 'Quadratic Equation',
                x: -20 //center
            },
            xAxis: {
                title: {
                    text: 'X'
                }
            },
            yAxis: {
                title: {
                    text: 'Y'
                }   
            }, 
       
       plotOptions: {
                scatter: {
                    marker: {
                        radius: 5,
               ...