我在同一个m文件中实现多个功能时遇到一些问题。以下代码包含在函数HeatTransferModel中调用的三个函数。如果我完全按照以下方式设置m文件,则无法识别RadOnly,analytica和RadConv等函数。但是,如果我为RadOnly,analytica和RadConv创建单独的m文件,则代码可以正常工作。你知道为什么吗?如何将所有这些功能集成在一个m文件中?对所有不必要的信息感到抱歉。
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
答案 0 :(得分:0)
您无法将子功能句柄传递给Ode45,因为它与主要功能位于不同的工作区中。