## unsolvable matlab problem

1. The problem statement, all variables and given/known data
Process description
The system of interest is a multi‐purpose batch unit used for cooling, decantation and storage. This
kind of unit is used worldwide in a range of industries and there are many design variations. The
particular unit of interest is located under cover, is sheltered from weather events and does not
receive any direct solar radiation. The air velocity in the vicinity of the unit is below detectable limits
(<0.1 m/s). The unit is shown in its normal operating environment in Figure 1. The operating
procedure of the unit is as follows:
 The vessel is initially empty and at ambient temperature.
 The unit is charged with a batch of hot process fluid.
 The unit is allowed to cool until the process fluid is within ~2°C of ambient temperature.
 At the end of cooling step, the process fluid is decanted and the vessel is cleaned.
A series of plant trials have been conducted to collect data for model validation and possibly
calibration purposes. Figure 2 shows the unit undergoing testing.

***the vessel is a coffee cup, cooling to room temperature

6 different experiments were conducted and the data given to us for comparisons sake.

in regards to the code

Ti = the ambient air temperature (average)
T = temperature of coffee at given time (t)
lam = heat transfer coefficient (λ)

2. Relevant equations

dT/dt = -λ(T-Ti)
C = T - Ti
λ = ln(u)/(t*ln(C*Ti))

3. The attempt at a solution

Code:
Script file:

%Ti=[27.7 26.66 28.2 20.8 21.54 22.8];
Ti1=27.7;
Ti2=26.66;
Ti3=28.2;
Ti4=20.8;
Ti5=21.54;
Ti6=22.8;

T1o=64.7;
T2o=86.3;
T3o=80.7;
T4o=68.8;
T5o=82.8;
T6o=71.1;

%State

%Packing
p={ Ti1, Ti2, Ti3, Ti4, Ti5, Ti6};
y0 = [T1o, T2o, T3o, T4o, T5o, T6o];

%, lam1, lam2, lam3, lam4, lam5, lam6

%time
interval = 1;
tspan= [0 : 1 : 360]; %#ok<NBRAK>

[t,y] = ode45(@(t,y) function3(t,y,p),tspan,y0);

T1 = y(:,1);
T2 = y(:,2);
T3 = y(:,3);
T4 = y(:,4);
T5 = y(:,5);
T6 = y(:,6);

%Solve Algebraic Equations

%Solve For C and lam

%Plots of Data

plot (t,T1,t,T2,t,T3,t,T4,t,T5,T,T6);
grid on
title('Temperature Simulation');
xlabel('Time in seconds');
ylabel('Temperature (degC)')
legend('T1','T2','T3','T4','T5','T6');
Function file:

Code:
function dydt = function3(t,y,p)

%Mapping y to local state variables
T1 = y(1);
T2 = y(2);
T3 = y(3);
T4 = y(4);
T5 = y(5);
T6 = y(6);

%Unpack parameters
[Ti1, Ti2, Ti3, Ti4, Ti5, Ti6]= p{:};
%lam1, lam2, lam3, lam4, lam5, lam6,

%Solving the algebraic equations

%Algebraics
C1=T1-Ti1;
C2=T2-Ti2;
C3=T3-Ti3;
C4=T4-Ti4;
C5=T5-Ti5;
C6=T6-Ti6;

lam1 = -(log(T1)./(1.*log(C1.*Ti1)));
lam2 = -(log(T2)./(1.*log(C2.*Ti2)));
lam3 = -(log(T3)./(1.*log(C3.*Ti3)));
lam4 = -(log(T4)./(1.*log(C4.*Ti4)));
lam5 = -(log(T5)./(1.*log(C5.*Ti5)));
lam6 = -(log(T6)./(1.*log(C6.*Ti6)));

%Evaluate Derivatives
dT1dt =-lam1.*(T1-Ti1);
dT2dt =-lam2.*(T2-Ti2);
dT3dt =-lam3.*(T3-Ti3);
dT4dt =-lam4.*(T4-Ti4);
dT5dt =-lam5.*(T5-Ti5);
dT6dt =-lam6.*(T6-Ti6);

dydt = [dT1dt dT2dt dT3dt dT4dt dT5dt dT6dt]';
end
The code is "working" but the graphs are completely wrong and we get this message:

Warning: Imaginary parts of complex X and/or Y arguments ignored
> In Script3 at 49

 Tags chemical engineering, coffee, matlab, modelling software, ode