Why Does My MATLAB Model of Coffee Cooling Produce Complex Numbers?

  • Thread starter Peter File
  • Start date
  • Tags
    Matlab
In summary: Use the correct set of equations3. Define the heat transfer coefficient (lam) as a function of time4. Break down the problem into smaller steps and test each step separately5. Comment your code to improve readability and understanding.
  • #1
Peter File
1
0

Homework Statement


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 (λ)

Homework Equations



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

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
 
Last edited:
Physics news on Phys.org
  • #2

In odearguments at 87
In ode45 at 114
In Script3 at 19
In odearguments at 87
In ode45 at 114
In Script3 at 19

First, I would like to clarify that the problem statement is not clear enough to fully understand what is being asked. From my understanding, the task is to model the cooling process of a multi-purpose batch unit, which in this case is a coffee cup, by using the given data and equations.

In your code, you have defined the ambient temperature (Ti) and the initial temperature of the coffee (To) for each of the 6 experiments. However, you have not used these values in your function file to solve the differential equations. Instead, you have used the algebraic equations to calculate the heat transfer coefficient (lam) for each experiment. This is where the warning message is coming from, since you are taking the logarithm of negative temperatures (since T is always smaller than Ti).

To solve this problem, you need to use the correct equations and the given data. From the problem statement, it is not clear what the data represents. Is it the temperature of the coffee at different time intervals, or is it the difference between the ambient temperature and the coffee temperature? This needs to be clarified in order to proceed with the solution.

Assuming that the data represents the temperature of the coffee at different time intervals, the correct equations to use are:

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

where Ti is the ambient temperature, T is the temperature of the coffee at the given time (t), and lam is the heat transfer coefficient.

You will also need to define the heat transfer coefficient (lam) as a function of time, since it is not a constant value. This can be done by using the given data and solving for lam at each time step.

I would also suggest breaking down the problem into smaller steps and testing each step separately. This will help you identify any errors and fix them before moving on to the next step. Additionally, it is always a good practice to comment your code explaining what each line is doing, as this will help you and others understand the code better.

In summary, the key points to consider when solving this problem are:

1. Clarify what the given data represents (temperature of the coffee or difference between the ambient temperature and the coffee
 

Related to Why Does My MATLAB Model of Coffee Cooling Produce Complex Numbers?

1. What is an "Unsolvable Matlab Problem"?

An "Unsolvable Matlab Problem" refers to a computational issue that cannot be solved using the Matlab programming language. This could be due to various reasons such as incorrect code syntax, insufficient computational power, or limitations of the Matlab software itself.

2. How can I determine if my problem is unsolvable in Matlab?

You can determine if your problem is unsolvable in Matlab by thoroughly checking your code for any errors or bugs. You can also consult the official Matlab documentation or seek help from experienced Matlab users through online forums or community groups.

3. Can an "Unsolvable Matlab Problem" ever be solved?

In most cases, an "Unsolvable Matlab Problem" can be solved by identifying and fixing the underlying issue in the code. However, there may be rare cases where the problem is beyond the capabilities of Matlab and cannot be solved.

4. Are there alternative solutions to Matlab for solving "Unsolvable" problems?

Yes, there are alternative programming languages and software that can be used to solve problems that are deemed unsolvable in Matlab. Some popular options include Python, R, and Julia.

5. How can I avoid encountering "Unsolvable Matlab Problems" in the future?

To avoid encountering "Unsolvable Matlab Problems" in the future, it is important to regularly update your Matlab software and stay updated on the latest coding techniques and best practices. It is also helpful to thoroughly test and debug your code before running it on large datasets or complex problems.

Similar threads

  • Engineering and Comp Sci Homework Help
Replies
1
Views
2K
  • Introductory Physics Homework Help
Replies
2
Views
2K
Back
Top