From: Abe Devinko on
Hi all, I worked on this code:
n=6; Fo=0.375; Bi=0.073; dt=0.3; dx=.002; L=0.01; x = [0:dx:L];
%Initial conditions, temperature profile T(x) at t=0
T5 = Tinf + (qdot1*L)/h; %Convection boundary at t=0
Told = (qdot1*L^2)/(2*k)*(1-(x.^2/L^2))+T5;
fprintf('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n',Told)
%Transient conditions
for t = 0:dt:310
for i = 2:n-1
Tnew(1)=Fo*(2*Told(2)+(qdot2*dx^2)/k)+(1-2*Fo)*Told(1);
Tnew(i)=Fo*(Told(i+1)+Told(i-1)+(qdot2*dx^2)/k)+(1-2*Fo)*Told(i);
Tnew(n)=2*Fo*(Told(n-2)+Bi*Tinf+(qdot2*dx^2)/(2*k))+(1-2*Fo-2*Bi*Fo)*Told(n);
end
Told=Tnew;
fprintf('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n',Told)
end

I have only given partial code. I get the answer, which is Told, a six-column matrix which runs through 0:dt:310.
I am trying to plot each column of Told vs. time, and also trying to plot x vs. Told for few dt's.
I tried, for example, putting plot(t,Told(:,3)) in the second for loop above right below Told=Tnew, but am not getting anything.
I would appreciate any help. I am learning slowly.
From: Ross W on
"Abe Devinko" <abe_cooldude(a)yahoo.com> wrote in message <i2u3vi$bcr$1(a)fred.mathworks.com>...
> Hi all, I worked on this code:
> n=6; Fo=0.375; Bi=0.073; dt=0.3; dx=.002; L=0.01; x = [0:dx:L];
> %Initial conditions, temperature profile T(x) at t=0
> T5 = Tinf + (qdot1*L)/h; %Convection boundary at t=0
> Told = (qdot1*L^2)/(2*k)*(1-(x.^2/L^2))+T5;
> fprintf('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n',Told)
> %Transient conditions
> for t = 0:dt:310
> for i = 2:n-1
> Tnew(1)=Fo*(2*Told(2)+(qdot2*dx^2)/k)+(1-2*Fo)*Told(1);
> Tnew(i)=Fo*(Told(i+1)+Told(i-1)+(qdot2*dx^2)/k)+(1-2*Fo)*Told(i);
> Tnew(n)=2*Fo*(Told(n-2)+Bi*Tinf+(qdot2*dx^2)/(2*k))+(1-2*Fo-2*Bi*Fo)*Told(n);
> end
> Told=Tnew;
> fprintf('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n',Told)
> end
>
> I have only given partial code. I get the answer, which is Told, a six-column matrix which runs through 0:dt:310.
> I am trying to plot each column of Told vs. time, and also trying to plot x vs. Told for few dt's.
> I tried, for example, putting plot(t,Told(:,3)) in the second for loop above right below Told=Tnew, but am not getting anything.
> I would appreciate any help. I am learning slowly.

Hi

It looks like Told is a 1-by-6 matrix. So when you give the command
plot(t,Told(:,3))
you are telling Matlab to draw a line whose start and end point are BOTH at the same point (t,Told(:,3)). That will make an tiny little 1-pixel dot on your graph.

If you want a marker drawn there, try
plot(t,Told(3),'*')
If Told is really 1-by-6 or 6-by-1, then Told(3) is the same as Told(:,3)

And if you want to see that * before it gets erased by the next plot when it next goes through the loop, use
hold on

and if you want to see the points get added one at a time, use
pause
just after the plot

Cheers,
Ross
From: Abe Devinko on
"Ross W" <rosswoodskiwi(a)hotmail.com> wrote in message <i2ueb7$5q0$1(a)fred.mathworks.com>...
> "Abe Devinko" <abe_cooldude(a)yahoo.com> wrote in message <i2u3vi$bcr$1(a)fred.mathworks.com>...
> > Hi all, I worked on this code:
> > n=6; Fo=0.375; Bi=0.073; dt=0.3; dx=.002; L=0.01; x = [0:dx:L];
> > %Initial conditions, temperature profile T(x) at t=0
> > T5 = Tinf + (qdot1*L)/h; %Convection boundary at t=0
> > Told = (qdot1*L^2)/(2*k)*(1-(x.^2/L^2))+T5;
> > fprintf('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n',Told)
> > %Transient conditions
> > for t = 0:dt:310
> > for i = 2:n-1
> > Tnew(1)=Fo*(2*Told(2)+(qdot2*dx^2)/k)+(1-2*Fo)*Told(1);
> > Tnew(i)=Fo*(Told(i+1)+Told(i-1)+(qdot2*dx^2)/k)+(1-2*Fo)*Told(i);
> > Tnew(n)=2*Fo*(Told(n-2)+Bi*Tinf+(qdot2*dx^2)/(2*k))+(1-2*Fo-2*Bi*Fo)*Told(n);
> > end
> > Told=Tnew;
> > fprintf('%6.2f %6.2f %6.2f %6.2f %6.2f %6.2f \n',Told)
> > end
> >
> > I have only given partial code. I get the answer, which is Told, a six-column matrix which runs through 0:dt:310.
> > I am trying to plot each column of Told vs. time, and also trying to plot x vs. Told for few dt's.
> > I tried, for example, putting plot(t,Told(:,3)) in the second for loop above right below Told=Tnew, but am not getting anything.
> > I would appreciate any help. I am learning slowly.
>
> Hi
>
> It looks like Told is a 1-by-6 matrix. So when you give the command
> plot(t,Told(:,3))
> you are telling Matlab to draw a line whose start and end point are BOTH at the same point (t,Told(:,3)). That will make an tiny little 1-pixel dot on your graph.
>
> If you want a marker drawn there, try
> plot(t,Told(3),'*')
> If Told is really 1-by-6 or 6-by-1, then Told(3) is the same as Told(:,3)
>
> And if you want to see that * before it gets erased by the next plot when it next goes through the loop, use
> hold on
>
> and if you want to see the points get added one at a time, use
> pause
> just after the plot
>
> Cheers,
> Ross

Thank you Ross, hold on did the trick! I have one more question.
How would I go about graphing Temperature (Told) as a function of L (x) for various dt.
For example, i want a Temp vs. position curve for first dt.
then on the same graph, i want temp vs. position for, say, 2dt
and so on for specified number of dt's.

My initial thought is that i need to define a vector with different dt that I want a curve for, so something like this:
since I have x = [0:dx:L];
I would define vec = [0 50 100 150 200 250 300];
and then, say, k =1;
somehow I would need a loop that will go through each vec, so
if t==vec(k)
plot(x,Told(3)), hold on
k = k+1;
end

However, I tried, that but doesn't work. Any ideas?