Hey guys, when I run this code I get an output with every value for Tc and Q. But these values won't plot, I just get a blank plot with no dots or lines. I have tried using both plot and plotyy, none of them work. Please help me.
%Given values:
d=0.35; % (m)
k=14.9; % (W/m.K)
r=d/2;
ro=7900; % (kg/m^3)
cp=0.477; % (kJ/kg.K)
a=3.95*10^-6; % (m^2/s)
Ti=400+273; % (K)
h=60; % (W/m^2.K)
Ts=150+273; % (K)
%Finding biot number:
Bi=(h*r/k);
%Values obtained from table:
l=1.0935; %lambda
A=1.1558;
J=0.4689;
%Finding Qmax:
m=ro*pi*r^2*1;
Qmax=m*cp*(Ti-Ts);
Tc=0;
Q=0;
%Generating temperature and heat transfer numbers
for t=5*60:60:60*60
tau=((t*a)/r^2);
Tc=(Ts+((Ti-Ts)*(A*exp(l^2*(-tau)))))
Q=(Qmax*(1-(2*((Tc-Ts)/(Ti-Ts))*(J/l))))
end
t=[5*60:60:60*60];
%ploting values
[hAx,hLine1,hLine2] = plotyy(t,Tc,t,Q)
xlabel('Time (s)')
ylabel(hAx(1),'Center temperature (K)')
ylabel(hAx(2),'Heat transfer (kJ)')
title('Center temperature and heat transfer as a function of time')

 Réponse acceptée

Roger Stafford
Roger Stafford le 30 Nov 2014
In your for loop you are not placing the successive values of Tc and Q in vectors. Instead they are being overwritten so that only the last pair is available for plotting. Change to:
t=5*60:60:60*60;
for k = 1:length(t);
tau = ...
Tc(k) = ...
Q(k) = ...
etc.

2 commentaires

I changed it to this:
t=[5*60:60:60*60];
for k=1:length(t)
tau(k)=((t*a)/r^2);
Tc(k)=(Ts+((Ti-Ts)*(A*exp(l^2*(-tau)))))
Q(k)=(Qmax*(1-(2*((Tc-Ts)/(Ti-Ts))*(J/l))))
end
but now it gives me this error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in HT461 (line 28) tau(k)=((t*a)/r^2);
Patricia
Patricia le 30 Nov 2014
I figured it out! thanks.

Connectez-vous pour commenter.

Plus de réponses (1)

Patricia
Patricia le 30 Nov 2014
I changed it to this:
t=[5*60:60:60*60];
for k=1:length(t)
tau(k)=((t*a)/r^2);
Tc(k)=(Ts+((Ti-Ts)*(A*exp(l^2*(-tau)))))
Q(k)=(Qmax*(1-(2*((Tc-Ts)/(Ti-Ts))*(J/l))))
end
but now it gives me this error:
In an assignment A(I) = B, the number of elements in B and I must be the same.
Error in HT461 (line 28) tau(k)=((t*a)/r^2);

1 commentaire

Star Strider
Star Strider le 30 Nov 2014
See if subscripting ‘t’ as ‘t(k)’ corrects that.

Connectez-vous pour commenter.

Catégories

En savoir plus sur 2-D and 3-D Plots dans Centre d'aide et File Exchange

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by