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

1 visualización (últimos 30 días)
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

Respuestas (2)

J Chen
J Chen el 4 de Mayo de 2021
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)

VBBV
VBBV el 26 de Sept. de 2022
L = 30;
n = 10;
T0=500;
T1s=300;
T2s=400;
dx=L/n;
alpha=0.000085;
t_final=4800;
dt=300; % use a coarse timestep for faster loop execuetion
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)
hold on % use a hold on command
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)
end
xlabel('distance(n)'); ylabel('Temperature(\circC)')
Use a hold on command at the beginning of first for loop. Assume a coarser time step for faster loop execution.

Categorías

Más información sobre 2-D and 3-D Plots en Help Center y File Exchange.

Etiquetas

Community Treasure Hunt

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

Start Hunting!

Translated by