Figure 2 not working
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
% Heat diffusion in one dimensional wire within the explicit FTCS method
clear;
% Parameters to define the heat equation and the range in space and time
D = 1*10^-4; % Heat Conductivity parameter in m2/s
K = 1*10^-4; % Heat Conductivity parameter in s^-1
L = 5.; % Total length in m
T = 43200.; % Final Time
% Parameters needed to solve the equation within the explicit method
Nt = 7200; % Number of time steps
Dt = T/Nt; % Time step
Nx = 51; % Number of space steps in m
Dx = L/(Nx-1); % Space step
b = 1-(2*D*Dt/Dx^2)- K*Dt; % beta parameter in the finite- difference implementation
% Remember that the FTCS method is stable for b=<1
disp(b);
% The initial condition: the initial temperature of the pipe
for i = 1:Nx+1
x(i) = (i-1)*Dx; % we also define vector x, due to the space discretization
u(i,1) = sin (pi*x(i));
end
% Boundary conditions: the temperature of the pipe at the boundaries at any time
for k =1:Nt+1
u(1,k) = 1.;
u(Nx+1,k) = 1.;
t(k) = (k-1)*Dt; % we also define vector t, due to the time discretization
end
% Implementation of the explicit FTCS method
for k =1:Nt % Time Loop
for i=2:Nx; % Space Loop
u(i,k+1) =u(i,k) + D*Dt/(Dx)^2*(u(i+1,k)-2*u(i,k)+u(i-1,k)); % Implementation of the FTCS Method
end
end
%Graphical representation of the temperature at different selected times
figure(1)
plot(x,u(:,1),'-b',x,u(:,round(Nt/100)),'--g',x,u(:,round(Nt/10)),':b',x,u(:,Nt),'-.r')
Title('Temperature of the pipe within the explicit FTCS method')
xlabel('X')
ylabel('T')
figure(2)
mesh(t,x,u)
title('temperature of the pipe within the explicit FTCS method')
xlabel('t')
ylabel('x')
I'm not able to get my mesh figure and im not sure what input should i give for this problem
5 Kommentare
Torsten
am 6 Apr. 2022
x = 0:0.1:1;
y = 0:0.05:2;
for i=1:numel(x)
for j =1:numel(y)
z(j,i) = x(i)^2 + y(j)^2;
end
end
[X,Y] = meshgrid(x,y);
size(X)
size(Y)
size(z)
mesh(X,Y,z)
Here you see that "mesh" works if the sizes of X,Y and z match.
Check the inputs in your case for their sizes and you'll see that they don't match.
Antworten (0)
Siehe auch
Kategorien
Mehr zu Geometry and Mesh finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!