Monday, April 4, 2016

Simulating Thermal Systems using MATLAB (Part 1)

Day 18 (4/1/16)

Our next project to develop our computer coding skills and understanding was using MATLAB to model the behavior of thermal systems. We worked with our final project partner, in my case Sara, to model the behavior of a cup of coffee using different techniques and using different parameters.

Question 1: How does the behavior of the cup of coffee change when we vary the thermal resistance (Rth) and/or the heat capacity (C).

Answer:
To answer this question we can simply look at the equation for the change in temperature:

As you can see, both Rth and C are in the denominator of the equation. So, when either of them is increased, the temperature will change (dT) by less. In other words, an increase in Rth or C will slow the drop in temperature of the cup of coffee.

We can also see this result by writing a script in matlab and varying both of those parameters to see what happens. Here is the script we used:



I using this script, I ran it multiple times changing just Rth, then just C and then changing both variables. Here is the plot I got of the different behavior for changing just Rth (the value of Rth for each line is listed in the text box at the top):

Here are the different behaviors for just changing C:

And here are the different plots for varying both Rth and C ( I plotted all possible combinations for increasing and decreasing Rth and C values):

As the plots show, increasing C and Rth will slow down the cooling process for a hot cup of coffee.

Question 2: Calculate a good value for P (power) if we want our coffee to heat up to 84 degrees C (356 K).

Answer:
This question gave us the revised equation for dT that included the introduction of a power source. Here is the revised equation:


And here is how I solved this equation for P with known values for C, T, Tair, and Rth:



A reasonable power amount is 74 watts.

Question 3: Simulate a temperature controller that uses bang bang control to reach and maintain the desired temperature. Why is bang bang control appropriate for many thermal systems? When might it be insufficient?

Answer:
To modify the code to include bang bang control, we used an if else statement so that when the temperature is above the desired 357K, there is no power delivered to heating the coffee and when it is below the desired temperature, we deliver 74W of power to the temperature controller. Here is what the code looked like:



And here is the plot for bang bang control:

Bang bang control is appropriate for many thermal systems because temperature takes time to vary. A change in the temperature of something is not very abrupt, so it is easy to maintain the temperature around the desired value. Also, with a lot of thermal systems, it is not crucial that the temperature be exactly the single temperature, so the small variance caused by bang bang does not cause any problems. Bang bang control will be insufficient when an exact temperature needs to be obtained and maintained. Bang bang will cause some minor fluctuations in temperature by turning on or turning off an external heat source, so for high accuracy thermal systems, you need higher accuracy than bang bang.

Question 4: Create a program that uses proportional control to reach and maintain the desired temperature. How does this approach compare to bang bang control?

Answer: 
To use proportional control you have to apply the concepts I talked about in my previous blog post (Sciborgs Part 3)

Strength = k * error
where k is the gain constant
and error = goal - reality

When this is applied to the code, it becomes:




Here is the resulting plot for proportional control:


The main difference between the effects of bang bang control versus proportional control is that at small times, proportional control has much larger changes in temperature than bang bang. But, after that initial rapid spike in temperature, proportional control levels off quickly and approaches the target temperature at a much slower rate. Interestingly, proportional control undershoots the target value and slowly works its way towards it, where as bang bang goes until it reaches the target temperature and then reacts.

Question 5: Modify your program to include a delay time for when the temperature sensor records the temperature. What is the impact of this sensor delay on your system in each case? What other delay(s) might you expect in your thermodynamic system, apart from sensor delays?

Answer:
For the bang bang control, to add in the delay, all you had to do was set the initial time equal to the delay. So the new code looked like this:


Compared to without the delay this is how the function behaved. The red is without the delay and the blue one is with delay:


Apart from the sensor delay, we can expect delays from the changing temperature. As I mentioned earlier, changing the temperature of something is not an abrupt task, it takes time to heat something up or cool it down. The delays from the sensor and the changing temperatures would likely continue to add up making the bang bang control system less and less effective.

For proportional control, I did the same thing to add the delay. I just added a variable called delay, which was whatever time value the delay was, and then set the initial time to the delay. I wont show the code becuase it is almost exactly the same with the exception of the two lines I changed (the exact same ones as bang bang). Here is how the delay effected the results (once again red is no delay, blue is delay) :

For the proportional delay system, there will also be the temperature delay that I mentioned for bang bang. However, all in all I believe the proportional system will be less effected by delay and will be more accurate in the long run.



2 comments:

  1. the way you plotted your changes on the same graph really helps visualize the differences! great job!

    ReplyDelete
  2. Nice picture! It is clear which line stands for what from the labels!

    ReplyDelete