how do i use contour command for rectangular plate ?

조회 수: 8 (최근 30일)
mehmet salihi
mehmet salihi 2021년 6월 1일
댓글: mehmet salihi 2021년 6월 2일
dear friends,
i have one regtangular plate and when i use contour command i did not obtain the figure i want, could you please see where do i have mistake.
i am sharing also the figure i want to obtain
%%% Point Gauss Seidel (PGS)
close all, clc
format short g
%Defining the constants
L=1; % length
H=2; % Height
deltax=0.05
deltay=0.05
Beta=deltax/deltay
Beta2=Beta^2
jn=H/deltay % Maximum number of grid points along y
im=L/deltax % Maximum number of grid points along x
T1=100; T2=0; T3=0; T4=0; % boundary conditions
y=2:-deltay:0;
x=0:deltax:L;
% initialize T_old to the initial guess values
T_old=zeros(jn+1,im+1);
% set boundary conditions
T_old(1,1:im+1)=T1;
T_old(jn+1,1:im+1)=T3;
T_old(2:jn+1,1)=T2;
T_old(2:jn+1,im+1)=T4;
T_new = T_old;
Error = 0.011; % could be any number that is greater than Errormax
Errormax=0.01;
t=0;
while Error > Errormax
t=t+1;
for i=2:jn
for j=2:im
T_new(i,j)=(1/(2*(1+Beta2)))* (T_new(i-1,j)+T_new(i+1,j)+Beta2*(T_new(i,j+1)+T_new(i,j-1)) ) ;
end
end
Error = sum(sum(abs(T_old-T_new),2)) ;
T_old = T_new;
end
contour(T_new(2:en,:))

채택된 답변

Cris LaPierre
Cris LaPierre 2021년 6월 1일
편집: Cris LaPierre 2021년 6월 1일
Include your x and y vectors when plotting. You'll have to do some manipulation of y since you create it starting at 2 and decrement to 0. You can also specify the number of contour levels if you want that to match.
You'll also want to format the axes so they use the same spacing (axis equal)
%Defining the constants
L=1; % length
H=2; % Height
deltax=0.05;
deltay=0.05;
Beta=deltax/deltay;
Beta2=Beta^2;
jn=H/deltay; % Maximum number of grid points along y
im=L/deltax; % Maximum number of grid points along x
T1=100; T2=0; T3=0; T4=0; % boundary conditions
y=2:-deltay:0;
x=0:deltax:L;
% initialize T_old to the initial guess values
T_old=zeros(jn+1,im+1);
% set boundary conditions
T_old(1,1:im+1)=T1;
T_old(jn+1,1:im+1)=T3;
T_old(2:jn+1,1)=T2;
T_old(2:jn+1,im+1)=T4;
T_new = T_old;
Error = 0.011; % could be any number that is greater than Errormax
Errormax=0.01;
t=0;
while Error > Errormax
t=t+1;
for i=2:jn
for j=2:im
T_new(i,j)=(1/(2*(1+Beta2)))* (T_new(i-1,j)+T_new(i+1,j)+Beta2*(T_new(i,j+1)+T_new(i,j-1)) ) ;
end
end
Error = sum(sum(abs(T_old-T_new),2)) ;
T_old = T_new;
end
%% create contour plot
contour(x,fliplr(y),T_new,17,'k')
xlabel('X')
ylabel('Y')
axis equal
  댓글 수: 3
Cris LaPierre
Cris LaPierre 2021년 6월 2일
Levels is an optional input. When you do not specify the levels, the contour function chooses the levels automatically.
mehmet salihi
mehmet salihi 2021년 6월 2일
thank you very much

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

추가 답변 (0개)

카테고리

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

Community Treasure Hunt

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

Start Hunting!

Translated by