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')

 Akzeptierte Antwort

Roger Stafford
Roger Stafford am 30 Nov. 2014

0 Stimmen

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 Kommentare

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 am 30 Nov. 2014
I figured it out! thanks.

Melden Sie sich an, um zu kommentieren.

Weitere Antworten (1)

Patricia
Patricia am 30 Nov. 2014

0 Stimmen

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 Kommentar

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

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Fourier Analysis and Filtering finden Sie in Hilfe-Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by