Oven

Oven#

Introduction#

Wait a few seconds until Python interaction ready! is shown in the top.

After that follow the instructions in the Grasple Exercise.

On this webpage the system of differential equations

\[\begin{split} \begin{cases} \frac{dT_m}{dt} = \alpha(T_0-T_m)+\beta(T_i-T_m)+s(t),\\ \frac{dT_i}{dt} = \gamma(T_m-T_i) ,\end{cases} \end{split}\]

is considered, with initial condition

\[\begin{split} \begin{pmatrix}T_m(0)\\T_i(0)\end{pmatrix}=\begin{pmatrix}T_0\\T_0\end{pmatrix}, \end{split}\]

and

\[\begin{split} s(t) = \begin{cases} C & {\rm if~}t\leq t_s,\\ s & {\rm if~}t> t_s. \end{cases} \end{split}\]

This webpage solves this initial-value problem symbolically, using sympy, and then uses numpy and matplotlib to display the obtained exact solution.

import micropip
await micropip.install("ipympl")
import matplotlib
if not hasattr(matplotlib.rcParams, '_get'):
    matplotlib.rcParams._get = matplotlib.rcParams.get
%matplotlib widget
import sympy as sp
import numpy as np
import matplotlib.pyplot as plt
    
def Oven(a,b,g,s,C,ts):
    
    def solve_ivp(a,b,g,s,C,ts):
        T0 = 295
        Tm0 = T0
        Ti0 = T0
        t = sp.symbols('t')
        Tm = sp.Function('Tm')
        Ti = sp.Function('Ti')
        # solve on the first part
        ode = [ sp.diff(Tm(t),t) - a*(T0-Tm(t)) - b*(Ti(t)-Tm(t)) - C, sp.diff(Ti(t),t) - g*(Tm(t)-Ti(t))]
        sol = sp.dsolve(ode)
        constants = sp.solve([sol[0].rhs.subs(t,0)-Tm0,sol[1].rhs.subs(t,0)-Ti0],sp.symbols('C1 C2'))
        u = sol[0].rhs.subs(constants)
        v = sol[1].rhs.subs(constants)
        # solve on the second part
        ode2 = [ sp.diff(Tm(t),t) - a*(T0-Tm(t)) - b*(Ti(t)-Tm(t)) - s, sp.diff(Ti(t),t) - g*(Tm(t)-Ti(t))]
        sol2 = sp.dsolve(ode2)
        constants2 = sp.solve([sol2[0].rhs.subs(t,ts)-u.subs(t,ts),sol2[1].rhs.subs(t,ts)-v.subs(t,ts)],sp.symbols('C1 C2'))
        u2 = sol2[0].rhs.subs(constants2)
        v2 = sol2[1].rhs.subs(constants2)
        
        u_ans = sp.Piecewise((u,t<=ts),(u2,t>ts))
        v_ans = sp.Piecewise((v,t<=ts),(v2,t>ts))
          
        return u_ans,v_ans

    t = sp.symbols('t')

    Tm,Ti = solve_ivp(a,b,g,s,C,ts)

    t_vals = np.linspace(0, 20, 1001)
    lam_Tm = sp.lambdify(t,Tm,modules=['numpy'])
    Tm_vals = lam_Tm(t_vals)
    lam_Ti = sp.lambdify(t,Ti,modules=['numpy'])
    Ti_vals = lam_Ti(t_vals)

    Te = 295+s/a

    plt.close('all')
    fig = plt.figure()
    plt.plot(t_vals,Tm_vals,label='$T_m$')
    plt.plot(t_vals,Ti_vals,label='$T_i$')
    plt.plot(t_vals,Te*np.ones_like(t_vals),'--',label='$T_{i,eq}$')
    plt.plot(t_vals,1.01*Te*np.ones_like(t_vals),':k',label='$(1 \pm 0.01)T_{i,eq}$')
    plt.plot(t_vals,0.99*Te*np.ones_like(t_vals),':k')
    plt.xlim(0,20)
    plt.xlabel('$t$')
    plt.ylabel('Temperature')
    plt.legend()
    plt.show()
    plt.figure()
    plt.title('Zoom')
    plt.plot(t_vals,Tm_vals,label='$T_m$')
    plt.plot(t_vals,Ti_vals,label='$T_i$')
    plt.plot(t_vals,Te*np.ones_like(t_vals),'--',label='$T_{i,eq}$')
    plt.plot(t_vals,1.01*Te*np.ones_like(t_vals),':k',label='$(1 \pm 0.01)T_{i,eq}$')
    plt.plot(t_vals,0.99*Te*np.ones_like(t_vals),':k')
    plt.xlim(5,12)
    plt.ylim(Te-20,Te+20)
    plt.xlabel('$t$')
    plt.ylabel('Temperature')
    plt.legend()
    plt.show()
    plt.grid()
    fig.canvas.toolbar_visible = True
    
    pass

INPUT CELL#

In the cell below you should put the values of the parameters you see in Grasple.

Please note: Each attempt in Grasple contains different values for the parameters.

After you run the cell the results of the calculations are shown with the set parameter values.

If you point your mouse below a figure, controls will appear that you can use to pan and zoom.

''' Set the given values in the following lines '''
alpha = 0.03
beta = 0.2
gamma = 0.6
s = 7
C = 80
t_s = 3.5

''' The next line performs the calculations and shows the results. '''
Oven(alpha,beta,gamma,s,C,t_s)