This day, we explored how MATLAB can run hypothetical
simulations and model progress as time continues on. Beginning with Newton’s
Law of Cooling, we considered the rate of energy loss of a system and attempted
to use MATLAB to recreate the situation.
To begin with, we ran the program that simulated the cooling
of a system. We used coffee as the system and looked at the code and the graph
it produced to form hypotheses about the effects changing specific factors
would have on the results.
We considered two variables in particular, Rth (thermal resistance) and C (Heat capacity).
We hypothesized that an increase of Rth caused the system to
cool more slowly. This is because when considering the energy change in the
system for time dt, Rth is in the denominator. Thus, when Rth increases, the
change in energy for that time dt gets smaller, which means that there is less
of an energy change relative to a larger Rth. This causes the graph of K v t to
become less steep and take a longer time to reach the cooled value.
Likewise, a decrease in Rth causes the system to cool more
rapidly.
It is somewhat intuitive that when the thermal resistance
increases, it is “harder” for thermal energy to transfer, which would slow down
the rate of transfer and make the coffee take longer to cool.
We next looked at the effect on the energy change when C was
increased in value. The system then takes longer to cool, which goes with the
intuitive thought that increasing heat capacity allows the system to retain
more heat and for a longer time. The curve is shallower.
When C was decreased, the system takes less time to cool,
resulting in a curve with big changes in energy with each dt that quickly
reaches close to the desired temperature.
Next, we were asked to consider the addition of a heater to
the system. We were given a specific equation that relates the change in
thermal energy to the change in energy/heat capacity. By recognizing that dT =
0, and dt cannot = 0, then (skipping algebraic steps) P = (T-Tair)/Rth. We then
used it in the simulation of heating coffee to the desired temperature.
The simulation's graph:
At this point, we were able to understand how to find Rth
and C. As P = deltaT/Rth, Rth = (Tequilibrium-Tair)/P. To find C, one has to
focus upon the initial slope of the graph created by Temperature vs time. As
the slope is equivalent to P/C there, dividing P by the slope at the initial
points yields C.
We then moved on to feedback and control. Our first
challenge was to create a simulation of a temperature controller that
functioned by the means of bang-bang control. Either the heater was on full or
completely off to meet this requirement.
My code ran as follows (see comments for details):
When graphed, the plot yielded:
Zooming in on a section on the “horizontal” part of the
graph:
Here you can see that as the temperature rises, when it gets
too high, the controller is off (implied by the next point dropping down to
below the “high temperature” value until when the heater turns on again (rises once more).
This approach seems appropriate for many temperature control
systems because it is energy efficient when it comes to shutting off the heat.
Once a reading is above a certain threshold, the controller immediately shuts
off the heat. It is unlikely that the room’s temperature will change so
dramatically that the controller is constantly switching between off and on.
Realistically, in a typical, closed room, temperature will not fluctuate
noticeably. This approach might be inefficient in temperature controls that
operate on a very fine level of precision (e.g. for scientific experiments).
The delay between readings might prevent action being taken in time to change
temperature levels to within parameters.
Our proportional control program uses the characteristic
gain*error format. To begin with, we needed to find what the gain was. We
assigned it the value “K.” See comments for further information.
This yields a graph that proportionally creeps toward the
desired value. The increase in temperature begins as large and then
proportionally grows smaller. However, as we saw in the proportional control
program with the sciborg, small forces such as friction prevent the system from
reaching the desired value. This calls for a “nudge” program – but for the
coffee system.
To create the nudge factor, we had to incorporate a delay in
our bang-bang and proportional programs.
For the bang-bang control program, we defined the value of
the delay. Basically, we assigned the T value used in the loop calculations
(Ti) to be the T value of x seconds previous, where x is the delay. So, we
assigned T(i) = T(i-delay). So every T value recorded is used in the next
calculation because of the delay. This caused slight confusion when updating
what T(i) becomes for the next loop, but I figured it out in the end. See
comments for further details.
Our graph by-and-large looked the same. However, there
should be a horizontal shift to the right to account for the delay. The delay
accounts for the time between the system reaching the temperature and when the
sensor stores that temperature.
Next up was proportional control with a delay.
Although it took me a while to figure this program out, it
turned out to be a rather simple addition to the program. Aside from condensing
Tmax-T into the term “error,” it was a matter of changing T to become
T(i-delay) in most cases, and updating the loop.
The graph:
The delay functions as a “nudge,” and allows the temperature
to reach the target and hold it for 1 second before using the value to realize
that it has reached the desired number.
Hi,
ReplyDeleteI really like that you described the theories and equations behind each exercise and graph you posted, it made you reasoning and work very easy to follow. Good job!