I am having some issues implementing multiple functions in the same m file. The following code includes three functions which are called in the function HeatTransferModel. If I set up the m file exactly like the following, it is unable to recognize the functions RadOnly,analytica and RadConv. However, if I create separate m file for RadOnly,analytica and RadConv, the code works. Do you know why? How can I integrate all these functions in one m file? Sorry about all the unnecessary information.
function HeatTransferModel
global e rho sigma c V Arad Twall Ti tend h Tinf
e = 0.87;
rho = 770; %kg/m3
sigma = 5.67E-08; %Stefan Boltzman constant
c = 1900; %Heat capacity of white oak wood
Lavg = 0.3686;
Wavg = 0.08382;
Havg = 0.05715;
V = 10*Lavg*Wavg*Havg; %Volume of the lumped wood
Arad =2*(Lavg*3*Havg) + 2*(3*Havg*3*Wavg) + Lavg*3*Wavg ; %Surface area of the lump that is exposed to radiation
Twall = 755; %Wall temperature of the furnace
Ti = 300; %Initial temperature of the wood when it is thrown in the furnace
tend = 500; %Seconds
h = 10;
Tinf = 500; %Temperature of the incoming air
[timeODE,TODE] = ode45('RadOnly',[0:1:tend],Ti);
[timeRadConv,TRadConv] = ode45('RadConv',[0,tend],Ti);
timeanalytical = analytical(TODE);
plot(timeODE,TODE,timeanalytical,TODE,timeRadConv,TRadConv);
legend('ODE Solver','Analytical Solution','RadConv');
title('Lumped Capacitance Model')
xlabel('Time [s]')
ylabel('Bulk Wood Temperature [K]')
end
function RadiationODE = RadOnly(t,T)
global e rho sigma c V Arad Twall h Tinf
RadiationODE = -e*Arad*sigma*(T^4 - Twall^4)/(rho*V*c);
end
function time = analytical(T)
global e rho sigma c V Arad Twall Ti
time = ((rho*V*c)./(4*e*Arad*sigma*Twall^3)).*( log( abs((Twall + T)./(Twall-T))) - log(abs((Twall + Ti)./(Twall-Ti))) + 2*( atan(T./Twall) - atan(Ti/Twall)));
end
function RadConvODE = RadConv(t,T)
global e rho sigma c V Arad Twall h Tinf
RadConvODE = -e*Arad*sigma*(T.^4 - Twall^4)./(rho*V*c) + (h*Arad.*(T - Tinf))./(rho*V*c);
end