simulate and plot the temperature of ice being heated using heat enthalpy in python

To simulate and plot the temperature of ice being heated using heat enthalpy in Python, you can utilize numerical integration methods such as Euler's method or the Runge-Kutta method. Here's an example implementation using Euler's method:

main.py
import numpy as np
import matplotlib.pyplot as plt

# Constants
m = 0.05    # mass of ice in kg
C = 2100    # specific heat capacity of ice in J/(kg*K)
Lf = 334000 # heat of fusion of ice in J/kg
L = 2260    # heat of fusion of water in J/(kg*K)
T0 = 260    # initial temperature of ice in K
Tf = 273   # final temperature (melting point) of ice in K
dt = 0.01   # time step in seconds
t_final = 1000  # total time of simulation in seconds

# Heat enthalpy function
def q(T):
    if T < Tf:
        return C*(T-T0) + Lf
    else:
        return C*(T-Tf)

# Simulation using Euler's method
t = np.arange(0, t_final, dt)
T = np.zeros(len(t))
T[0] = T0

for i in range(1, len(t)):
    T[i] = T[i-1] + q(T[i-1])/(m*C) * dt

# Plotting results
plt.plot(t, T)
plt.xlabel('Time (s)')
plt.ylabel('Temperature (K)')
plt.title('Temperature of ice being heated')
plt.show()
863 chars
35 lines

In this example, we define the constants such as the mass of ice, specific heat capacity, heat of fusion, and initial and final temperatures. We also define the heat enthalpy function q, which returns the heat enthalpy of ice as a function of its temperature.

We then simulate the temperature of ice using Euler's method, which updates the temperature T at each time t based on the heat enthalpy and the specific heat capacity of ice. Finally, we plot the simulated temperature over time using Matplotlib.

Note that this is a simplified example and does not take into account factors such as heat transfer between the ice and its environment or changes in the heat conduction properties of the ice as it melts.

gistlibby LogSnag