MATLAB Answers

How can I get the value by choosing 't' and 'x'? ,How should I set the graph range?

조회 수: 1(최근 30일)
Seung Ho Kim
Seung Ho Kim 2021년 5월 4일
답변: J Chen 2021년 5월 4일
L = 30;
n = 10;
T0=500;
T1s=300;
T2s=400;
dx=L/n;
alpha=0.000085;
t_final=4800;
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)
xlabel('distance(n)')
ylabel('Temperature(\circC)')
pause(1)
end

답변(1개)

J Chen
J Chen 2021년 5월 4일
Move the plot command outside the loop. Store the calculation at each time step in a buffer. For example:
hist = nan(n,length(t));
for
.
.
hist(:,j) = T;
end
plot(:,400)

태그

Community Treasure Hunt

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

Start Hunting!

Translated by