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

3 views (last 30 days)
T K on 25 Aug 2021
Commented: Rena Berman on 23 Aug 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')
##### 2 CommentsShowHide 1 older comment
Rena Berman on 23 Aug 2022
(Answers Dev) Restored edit

Walter Roberson on 26 Aug 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'
T K on 26 Aug 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')