Hi,
I have been trying to create a code, where I end up with temperature values for different surfaces over a time period and should end up with 5×5 array. However, I only seem to end up getting a 1×5 array and also the calculation is not correct as it does not use the element I want it to. The script is below.
Thank you
clc,clearV = [1;2;3;4;5]ho = 0.6 + 6.64.*sqrt(V)k = [1 2 3 4 5]lamda = [6 7 8 9 10]hi = 2x = (1./ho)y = (1/hi)z = (lamda./k)S = [11 12 13 14 15;]U = x + y + z ma=1ca=2DTM=1deltat=1Tout=5ms=1cs=1index=1:5;SQAmb = zeros(numel(index), numel(S)); %Preallocation of Ambient Load (Surface) matrix
SQAmb_Tot = zeros(size(index)); %Preallocation of Total Ambient Load (Surface) matrix
QAmb = zeros(numel(index), numel(S)); %Preallocation of Ambient Load (Air) matrix
QAmb_Tot = zeros(size(index)); %Preallocation of Total Ambient Load (Air) matrix
SQTot = zeros(size(index)); %Preallocation of Total Surface Heat Load matrix
deltaTs = zeros(size(index)); %Preallocation of deltaTs matrix
Ts = zeros(size(index)); %Preallocation of Surface temperature matrix
QTot = zeros(size(index)); %Preallocation of Total Heat Load matrix
deltaTin = zeros(size(index)); %Preallocation of deltaTin matrix
Tin = zeros(size(index)); %Preallocation of car cabin temperature matrix
for i=indexif (i)==1%Ambient Load (Surface), where 20 is the intial temperature at t=0
SQAmb(i,:) = S*U*(Tout-20)
(the first value of this array should be: the first element of S which is (11) * first element of U* temp diff (-15), this should come out to -1095.2865 but does not)
(if vectorization is used i.e. S.*U.*(Tout-20) then an error to do with "Assignment has more non-singleton rhs dimensions than non-singleton subscripts is produced")
(and if element is selected one at a time by SQAmb(i,:) = S*U(i)*(Tout-20) , the array that is formed for the Temperature at the end is not a 5×5 array)
%Total Ambient Load (Surface) in Array Form
SQAmb_Tot(i) = sum(SQAmb(i,:)) %Ambient Load (Air), where 20 is the intial air and surface temperatures at t=0
QAmb(i,:) = S*U*(20-20);%Total Ambient Load (Air) in Array Form
QAmb_Tot(i) = sum(QAmb(i,:))%Total Surface Heat Transfer Load
SQTot(i) = SQAmb_Tot(i) %change in surface temperature where deltat is timestep
deltaTs(i) = (SQTot(i)/((ms*cs)+DTM))*(deltat)%New surface temperature
Ts(i) = 20 + deltaTs(i) %Total Heat Transfer Load
QTot(i) = QAmb_Tot(i) %change in air cabin temperature where deltat is timestep
deltaTin(i) = (QTot(i)/((ma*ca)+DTM))*(deltat)%New car cabin temperature
Tin(i) = 20 + deltaTin(i)else %Ambient Load (Surface)
SQAmb(i,:) = S*U*(Tout-(2*Ts(i-1))+Tin(i-1)) %Total Ambient Load (Surface) in Array Form SQAmb_Tot(i) = sum(SQAmb(i,:)) %Ambient Load (Air)
QAmb(i,:) = S*U*((Ts(i-1))-Tin(i-1))%Total Ambient Load (Air) in Array Form QAmb_Tot(i) = sum(QAmb(i,:))%Total Surface Heat Transfer Load SQTot(i) = SQAmb_Tot(i) %change in surface temperature where deltat is timestep deltaTs(i) = (SQTot(i)/((ms*cs)+DTM))*(deltat)%New surface temperature Ts(i) = Ts(i-1) + deltaTs(i) %Total Heat Transfer LoadQTot(i) = QAmb_Tot(i) %change in air cabin temperature where deltat is timestepdeltaTin(i) = (QTot(i)/((ma*ca)+DTM))*(deltat)%New car cabin temperature Tin(i) = Tin(i-1)+deltaTin(i)endend
Best Answer