Effacer les filtres
Effacer les filtres

I want to make the figure hanger look like the attached picture. The code is shown below.

3 vues (au cours des 30 derniers jours)
T K
T K le 25 Août 2021
Commenté : Rena Berman le 23 Août 2022
clc
L=3;% L=y fare away the the plate (boundary layer)
T=2;%Final time
maxk=500;%Number of time steps
dt=T/maxk;
n=50;%Number of space steps
dy=L/n;
diff=0.25;
b=diff*dt/(dy*dy);
%b=0.1;
%initial condition of velocity
for i=1:n+1
y(i)=(i-1)*dy;
u(1,1)=0;
end
%Boundary condition
for k=1:maxk+1
u(1,k)=1;
u(n+1,k)=0;
end
for k=1:maxk %time loop
for i=2:n %space loop
u(i,k+1) =u(i,k)+b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
end
end
%Ploting
figure(1)
%plot(y,u(:,1),'-',y,u(:,100),'-',y,u(:,300),'-',y,u(:,600),'-')
plot(y,u(:,50),'-',y,u(:,100),'-',y,u(:,200),'-',y,u(:,250),'-')
%legend('dt=50','dt=100','dt=200','dt=250')
title('Velocity in the boundary layer')
xlabel('y')
ylabel('velocity')

Réponses (1)

Walter Roberson
Walter Roberson le 26 Août 2021
Instead of using plot() use surf(), with 'edgecolor', 'none', and with 'alphadata' set to a constant repeated the same size as u, and with AlphaDataMapping 'none' and with 'FaceAlpha', 'flat'
  3 commentaires
Walter Roberson
Walter Roberson le 26 Août 2021
surf(x, y, u, 'edgecolor', 'none', 'AlphaDataMapping', 'none', 'FaceAlpha', 'flat', 'Alpha', 0.8 * ones(size(u)));
hold on
This would be in a loop in which you changed whatever it is you need to change, creating a new u matrix each time.
T K
T K le 26 Août 2021
Please doctor walter Roberson, when writing the attached code, an error appeared:
Undefined function or variable 'x'.
Error in Untitled (line 24)
surf(x(i), y(i), u(i), 'edgecolor', 'none', 'AlphaDataMapping', 'none', 'FaceAlpha', 'flat', 'Alpha', 0.8 * ones(size(u(i))));
code attached
clc
L=3;
T=2;
maxk=500;
dt=T/maxk;
n=50;%Number of space steps
dy=L/n;
diff=0.25;
b=diff*dt/(dy*dy);
%initial condition
for i=1:n+1
y(i)=(i-1)*dy;
u(1,1)=0;
end
%Boundary condition
for k=1:maxk+1
u(1,k)=1;
u(n+1,k)=0;
end
for k=1:maxk %time loop
for i=2:n %space loop
u(i,k+1) =u(i,k)+b*(u(i-1,k)+u(i+1,k)-2.*u(i,k));
surf(x(i), y(i), u(i), 'edgecolor', 'none', 'AlphaDataMapping', 'none', 'FaceAlpha', 'flat', 'Alpha', 0.8 * ones(size(u(i))));
hold on
end
end
%Ploting
figure(1)
plot(y,u(:,50),'-',y,u(:,100),'-',y,u(:,200),'-',y,u(:,250),'-')
legend('dt=50','dt=100','dt=200','dt=250')
title('Velocity in the boundary layer')
xlabel('y')
ylabel('velocity')

Connectez-vous pour commenter.

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by