필터 지우기
필터 지우기

To plot 1D temperature distribution plot versus lenght of the channel of the fin

조회 수: 1 (최근 30일)
Hello,
I am using this piece of code to get the temperature distribution across Fin of varying channel length. Kindly help me with changes in code where i can vary the lenght of the fin and see the corresponding changes in temperature.
help me in including the dx parameter inside the loop.
clc
clear all
L=1000;
N=100;
dx=L/(N-1);
T=zeros(N,1);
Tb=300;
k=1;
for j=1;1;k
T(1,1)=Tb;
for i=2:1:N-1
T(i,1)=(T(i+1,1)+T(i-1,1))/2;
end
T(N,1)=T(N-1,1);
end
plot(T);

채택된 답변

Walter Roberson
Walter Roberson 2023년 10월 19일
이동: Walter Roberson 2023년 10월 19일
L=0.1;
n=10;
T0=0;
T1s=40;
T2s=20;
dx=L/n;
alpha=0.0001;
t_final=60;
dt=0.1;
x = dx/2:dx:L-dx/2; %important change
T=ones(n,1)*T0;
dTdt=zeros(n,1);
t=0:dt:t_final;
for j=1:length(t)
for i=2:n-1
dTdt(i)=alpha*(-(T(i)-T(i-1))/dx^2+(T(i+1)-T(i))/dx^2);
end
dTdt(1)=alpha*(-(T(1)-T1s)/dx^2+(T(2)-T(1))/dx^2);
dTdt(n)=alpha*(-(T(n)-T(n-1))/dx^2+(T2s-T(n))/dx^2);
T=T+dTdt*dt;
plot(x,T,'LineWidth',3)
hold on
axis([0 L 0 50])
xlabel('Distance(m)')
ylabel('Temperature(\circC)')
%pause(0.1)
end
hold off
  댓글 수: 3
Walter Roberson
Walter Roberson 2023년 11월 6일
I do not see much change.
L=0.1;
n=10;
T0=0;
T1s=50;
T2s=10;
dx=L/n;
alpha=0.0001;
t_final=60;
dt=0.1;
x = dx/2:dx:L-dx/2; %important change
T=ones(n,1)*T0;
dTdt=zeros(n,1);
t=0:dt:t_final;
for j=1:length(t)
for i=2:n-1
dTdt(i)=alpha*(-(T(i)-T(i-1))/dx^2+(T(i+1)-T(i))/dx^2);
end
dTdt(1)=alpha*(-(T(1)-T1s)/dx^2+(T(2)-T(1))/dx^2);
dTdt(n)=alpha*(-(T(n)-T(n-1))/dx^2+(T2s-T(n))/dx^2);
T=T+dTdt*dt;
plot(x,T,'LineWidth',3)
hold on
axis([0 L 0 50])
xlabel('Distance(m)')
ylabel('Temperature(\circC)')
%pause(0.1)
end
hold off
Ashwini nanjunda
Ashwini nanjunda 2023년 11월 7일
Sorry for the confusion. Try this with this piece of code.
I have taken L=6.3*10^-5; and T1s = 0; and T2s= 608. Now characteristics are coming in Straight lines. I tried changing n value and stepsize. Have a look into the code by changing these parameters and help me with this.

댓글을 달려면 로그인하십시오.

추가 답변 (2개)

Walter Roberson
Walter Roberson 2023년 10월 12일
Lvals = [500, 750, 900, 950, 1000, 1050, 1100, 1500];
numL = numel(Lvals);
N = 100;
dx = L/(N-1);
T = zeros(N,numL);
Tb = 300;
for Lidx = 1 : numL
L = Lvals(Lidx);
for j=1:1:k
T(1,Lidx) = Tb;
for i=2:1:N-1
T(i,Lidx) = (T(i+1,Lidx)+T(i-1,Lidx))/2;
end
T(N,Lidx) = T(N-1,Lidx);
end
end
surf(Lvals, 1:N, T);
xlabel('L');
ylabel('N');
zlabel('T');
However, the only point in the code in which you use L is to calculate dx and you never use dx, so the value of L does not affect the output in any way.
  댓글 수: 2
Ashwini nanjunda
Ashwini nanjunda 2023년 10월 17일
Thank you for the help sir. searching for a conceptual part to vary the lengh of a fin and observe the temperature distribution..This gave an insight to approach the problem.
Walter Roberson
Walter Roberson 2023년 10월 17일
I recommend that you study this pattern for iterating over values that are not consecutive integers (that start with 0 or 1) -- that is:
create a vector holding the values, count how many there were, pre-allocate the output based on the count of values, then loop an index from 1 to the number of values; inside the loop, pull out the "current" value from the list of values into a variable, and do computations based on the variable; store the result of the iteration into the pre-allocated variable indexed by the current loop index.
When you use this pattern, the values to be looped over do not need to be integers, do not need to be consecutive, do not need to be unique.
Do this even if you have something like
for L = 1:.1:5
out((L-.9)*10, :) = something
end
the calculation of the row index based upon current value is likely to go wrong, not producing exact integers for the indices.

댓글을 달려면 로그인하십시오.


Ashwini nanjunda
Ashwini nanjunda 2023년 10월 19일
Hello sir. This piece of code can be used to plot Temperature Vs Length.Help me with this
Finding it difficult to debug error and correct it.
clc
L=0.1;
n=10;
T0=0;
T1s=40;
T2s=20;
dx=L/n;
alpha=0.0001;
t_final=60;
dt=0.1;
x=dx/2;dx;L-dx/2;
T=ones(n,1)*T0;
dTdt=zeros(n,1);
t=0:dt:t_final;
for j=1:length(t)
for i=2:n-1
dTdt(i)=alpha*(-(T(i)-T(i-1))/dx^2+(T(i+1)-T(i))/dx^2);
end
dTdt(1)=alpha*(-(T(1)-T1s)/dx^2+(T(2)-T(1))/dx^2);
dTdt(n)=alpha*(-(T(n)-T(n-1))/dx^2+(T2s-T(n))/dx^2);
T=T+dTdt*dt;
figure(1)
plot(x,T,'LineWidth',3)
axis([0 L 0 50])
xlabel('Distance(m)')
ylabel('Temperature(\circC)')
pause(0.1)
end

카테고리

Help CenterFile Exchange에서 Particle & Nuclear Physics에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by