필터 지우기
필터 지우기

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

조회 수: 3 (최근 30일)
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')

답변 (1개)

Walter Roberson
Walter Roberson 2021년 8월 26일
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
Walter Roberson
Walter Roberson 2021년 8월 26일
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 2021년 8월 26일
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')

댓글을 달려면 로그인하십시오.

카테고리

Help CenterFile Exchange에서 Logical에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by