To simulate ice being heated in Python, we need to compute the temperature profile of the ice block as we heat it. This can be done using a simple heat transfer model, assuming that the ice is in a one-dimensional slab with uniform thermal properties.
We can use the following equation to compute the temperature profile of the ice as a function of time:
$T(x,t) = T_{0} + (T_{i} - T_{0}) \cdot Erfc(\frac{x}{2\sqrt{\alpha t}})$
where $T_{0}$ is the initial temperature, $T_{i}$ is the temperature of the surroundings (i.e., the heating element), $Erfc$ is the complementary error function, $x$ is the distance from the surface of the ice, $\alpha$ is the thermal diffusivity of ice, and $t$ is time.
Using this equation, we can compute the temperature profile of the ice at any point in time, and then use that to compute the rate of heat transfer into the ice. We can then use a numerical integration method (e.g., the trapezoidal rule) to integrate this rate of heat transfer over time, and thus compute the total amount of energy that is transferred to the ice.
Here's some example code that implements this simulation using numpy:
main.py1076 chars41 lines
This code should produce a simulation of the ice block being heated over time, with the temperature of the ice increasing until it reaches the temperature of the surroundings. Note that the parameters of the simulation can be adjusted to simulate different scenarios (e.g., different starting temperatures, different heating elements, different sizes of the ice block).
gistlibby LogSnag