index calculations
조회 수: 1 (최근 30일)
이전 댓글 표시
Hi, I need to do index calculations. I've a vertical column divided into thin layers, for which properties are considered constant. The temperature T(i + 1) and the heat flow Q(i + 1), at the bottom of each layer, are determined from the temperature T(i) and the heat flow Q(i) at the top of each layer by
T(i+1) = T(i) + (Q(i).*Dz(i))./k(i) - (A(i).*Dz(i).^2)./2.*k(i)
and
Q(i+1) = Q(i) - A(i).*Dz(i)
where A(i) and k(i) are known for each layer and Dz(i) is the layer thickness and set to 1. Somebody can suggests me how implement in matlab this operation? thanks Gianluca
댓글 수: 2
채택된 답변
Jan
2012년 3월 15일
%define depth range and intervals [m]
z = (0:100:10000)'; % No addition [ and ] around vectors
%define variables
% k = zeros(size(z)); % No pre-allocation required
% A = zeros(size(z)); % No pre-allocation required
Q = zeros(size(z));
T = zeros(size(z));
To = 18; %surface temperature [°C]
Qo = 0.07; %surface heat flow [W/m2]
k = 2 + 0.00005 .* z; % Spaces around operators increase readability
A = 2.5e-6 .* exp(-0.0001 .* z); % 2.5e-6 is faster than 2.5*10^-6
diffz = diff(z);
Q(1) = Qo; % Once outside the loop
for i = 1:(length(z)-1)
Q(i+1) = Q(i) - A(i) .* diffz(i);
end
% Faster, but needs more memory:
% Q = cumsum([Qo; -A(1:end-1) .* diffz])
T(1) = To; % Once outside the loop
for i = 1:(length(z)-1)
T(i+1) = T(i) + (Q(i) .* diffz(i)) ./ ...
k(i) - (A(i) .* diffz(i) .^ 2) ./ 2 .* k(i);
end
plot(z,T)
The spaces around the operators are not required, but this can help to avoid ambiguities, compare:
2.*3
2. *3
2 .* 3
추가 답변 (1개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Heat and Mass Transfer에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!