Advertisement
ksoltan

Coffee Cooling ode45 (Exercise 6.1)

Oct 18th, 2015
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.40 KB | None | 0 0
  1. function coffee_model()
  2. % Model of a ceramic mug of coffee cooling over time
  3.     radius = 0.04; %m
  4.     height = 0.10; %m
  5.     V = pi * radius^2 * height; % cylindrical cup of coffee
  6.     k = 1.5; % W/m/K
  7.     A = height * 2 * pi * radius + pi * radius ^ 2; % sides and bottom
  8.     d = 0.007; % m
  9.     m = V * 1000; % 1000kg/m^3 density of coffee
  10.     c = 4186; % J/kg/K
  11.     h = 100; % W / m^2 / K
  12.     Tinit = 370; % K
  13.     Troom = 290; % K
  14.  
  15.     function res = coffee_U_change(t, U)
  16.         % Change in the internal energy of the coffee by conductive and
  17.         % convective heat transfers
  18.         % dependent on the temperature of the coffee
  19.         temp_coffee = U / m / c;
  20.         conduction = k * A / d * (Troom - temp_coffee);
  21.         convection = h * pi * radius ^ 2 * (Troom - temp_coffee);
  22.         res = conduction + convection;
  23.     end
  24.  
  25.     time_init = 0;
  26.     time_final = 30 * 60; % seconds (30 minutes)
  27.    
  28.     % Plot the change in temperature over time
  29.     dUdt = @coffee_U_change;
  30.     % Use ode45 to evaluate the change in temperature for each point in
  31.     % time to generate a line. Advanced Euler's method without a constant
  32.     % time step
  33.     [time_2, U_2] = ode45(dUdt, [time_init, time_final], m * c * Tinit);
  34.     plot(time_2, U_2 / m / c, 'b*')
  35.    
  36.     title('Temperature of Coffee in Ceramic Mug Over Time')
  37.     xlabel('Time (seconds)')
  38.     ylabel('Temperature (Kelvin)')
  39. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement