Page 1 of 3 Problem session #1 – HT_Spring2024 Problem Session #1 Heat Transfer, MECE:315:001, Spring 2024 Name: ____________ (Jan. 17, Wednesday) Ordinary Differential Equations (ODE) and Solutions: 1. First-Order and Second-Order Ordinary Differential Equations: For a function, y = −0.5 x 4 + 4 x 3 − 10 x 2 + 8.5 x + 1 , One has, dy = −2 x 3 + 12 x 2 − 20 x + 8.5 dx d2y dx 2 = −6 x 2 + 24 x − 20 (1) - first-order ordinary differential equation (2) - second-order ordinary differential equation (3) 2. Solution of an ODE by Integration – Integral Constants: One can integrate Eq. (2) once to obtain the solution of this ODE: y = −0.5 x 4 + 4 x 3 − 10 x 2 + 8.5 x + C where C is the constant of integration and has to be determined based on a given condition (called initial condition). For example, Eq. (1) become the solution of the ODE if one specifies that, → C = 1. y (0) = 1 For the second-order ODE as Eq. (3), one has to integrate it twice. First integration gives, dy = −2 x 3 + 12 x 2 − 20 x + C1 , dx and integrate one more time, one has 1 y = − x 4 + 4 x3 − 10 x 2 + C1x + C2 2 (4) where we have two integral constants, C1 and C2. 3. Initial-Value and Boundary-Value ODEs: We need to have two conditions to determine the two constants C1 and C2 in the solution (4). If one specifies both values of function y and its first derivative y′ at x = 0, y (0) = 1 y′(0) = 8.5 (5) in this case, Eq. (4) together with conditions, Eq. (5), then make up to an initial-value problem (since for transient problems, the two conditions are specified at the beginning of time). We can also use the following tow conditions: y (0) = 1 y (2) = 2 (6) where the function values at two locations, x = 0 and x = 2, are specified. Then the problem is called boundary-value ordinary differential equation. This is typical for problems involving changes in space. Page 2 of 3 Problem session #1 – HT_Spring2024 4. Initial-Value ordinary differential equation of ingot cooling The variation of the ingot temperature, T(t), with time, t, during transient cooling of an metallic ingot quenched inside a liquid tank is governed by the following initial-value, first order ordinary differential equation, dT (7) τ = −(T − T∞ ) dt where τ is the time constant and T∞ is the temperature of liquid far away from the ingot surface. For the ingot with a given initial temperature Ti, the solution of Eq. (7) has an initial condition, (7a) T (0) = Ti . Equation (8) can be solved by the method of separation, together with the initial condition, giving dθ dt = − θ → τ θ (t ) ∫ θ i dθ θ t = −∫ dt 0 τ % % t τ 80 Ingot cooling in water o C) 70 60 50 40 30 50 100 150 200 250 300 t, (s) Finally, one has, − MATLAB ode45 0 % % θ (t ) = θi e Exact Solution for water 90 20 θ (t ) t = − θi τ → ln 100 T, ( Let us define an excess temperature, θ= (t ) T (t ) − T∞ , then Eq. (7) become a homogeneous first-order ODE equation, dθ (8) τ = −θ dt with an initial condition of (8a) θ (0)= θ=i Ti − T∞ or T (t ) − T∞ = (Ti − T∞ )e → T (t ) = T∞ + (Ti − T∞ )e − − t τ t τ % % % % % % Problem_session_1_1 Spring 2024 clc;clear; Fe Ingot (Fe) cooling by convection Given: (all SI units) D = 0.05; L = 0.08; Ti = 80; % T, oC rho_Fe = 7870; cp_Fe = 485; % cp, J/kg-K A = 2*(pi*D^2/4)+pi*D*L; % surface area, m^2 Vol = pi*D^2/4*L; % volume of ingot, m^3 Coolant: water T_inf = 25; h = 800; % W/m^2-K tao = Vol*rho_Fe*cp_Fe/h/A % time constant,1/s Analytical solution dT/dt = -(T-T_inf)/tao T_e =@(t) T_inf + (Ti-T_inf)*exp(-t/tao); t1 = linspace(0, 300, 20); T_exact = T_e(t1); plot(t1,T_exact,'k--','LineWidth',1) axis([0 300 20 100]) xlabel('t, (s)','fontsize',15) ylabel('T, (^oC)','fontsize',15) grid on hold on Numerical solution by MATLAB built-in function, ode45 T0 = Ti; % initial condition f = @(t,T) -(T-T_inf)/tao; [t2,T_n] = ode45(f, [0 300], T0); plot(t2,T_n,'o','MarkerFaceColor','r') text(120, 75, 'Ingot cooling in water', 'FontSize',15) legend('Exact Solution for water','MATLAB ode45') hold off Page 3 of 3 Problem session #1 – HT_Spring2024 5. Numerical Methods to Solve a System of Initial-Value 1st-Order Ordinary Differential Equations: For example, dy = f (t , y ) = 4e 0.8t − 0.5 y dt y ( 0) = 2 The analytical solution, 4.1 MATLAB built-in function: ode45 [t,y] = ode45(f, [0 5], y0); 4 0.8t (e − e − 0.5t ) + 2e − 0.5t 1.3 70 Exact Solution MATLAB ode45 60 50 40 y(t) % Problem_session_1_2 % % MATLAB build-in ode solver % ode45 or ode23 % clc;clear f = @(t,y) 4*exp(0.8*t)-0.5*y; y_e =@(t) 4/1.3*(exp(0.8*t)-exp(-0.5*t))+2*exp(-0.5*t); % t1 = linspace(0, 5, 100); ye = y_e(t1); % plot(t1,ye,'k--','LineWidth',0.05) axis([0 4 0 70]) xlabel('t','fontsize',15) ylabel('y(t)','fontsize',15) grid on hold on % % MATLAB ode45 y0 = 2; [t,y] = ode45(f, [0 4], y0); plot(t,y,'o','MarkerFaceColor','r') legend('Exact Solution','MATLAB ode45') hold off y= 30 20 10 0 0 1 0.5 1.5 2 t 2.5 3 3.5 4 4.2 For a high-order ODE: Solve the following second-order van der Pol equation by transforming it as a pair of 1st-order ODES: − µ (1 − y12 ) dt 2 y1 (0) = 1 y1′ (0) = 1 dy1 + y1 = 0 dt y1 = y1 Let dy1 → dt dy2 d 2 y1 = 2 dt dt y2 = function Problem_session_1_3 % Problem_session_1_3 % solve the {predator-prey models by MATLAB ode45 clc;clear % m = 100; y1_0 = 1; y2_0 = 1; [t,y] = ode23(@dydt1, [0 1000], [y1_0 y2_0],[], m); plot(t,y(:,1),'r','LineWidth',1.5) hold on axis([0 1000 -3 3]) xlabel('t','fontsize',15) ylabel('y(t)','fontsize',15) grid on text(50,2.5,'mu=100','FontSize',15) hold off end function [ dy] = dydt1(t,y,m) % Set up functions of system of ODEs % for van der Pol equation f1 = y(2); f2 = m*(1-y(1)^2)*y(2)-y(1); dy = [f1; f2]; end dy1 = y2 dt dy2 = µ (1 − y12 ) y2 − y1 dt y1 (0) = 1 y2 (0) = 1 3 mu=100 2 1 y(t) d 2 y1 0 -1 -2 -3 0 100 200 300 400 500 t 600 700 800 900 1000