
Darcy's law
    8 次查看(过去 30 天)
  
       显示 更早的评论
    
clc
clear
% Laplace equation
% Define the length of the grid
L  = 5 ;
% Define the Width of the grid
B = 5 ;
nx = 4 ;
ny = 4 ;
dx = 100;
dy =  100;
h=zeros(nx,ny);
amax = 0;
% boundry conditions
h(1,:)  = [ 8.04 , 7.68 , 7.19 , 6.82 ];
h(nx,:) = [ 8.53 , 8.41 , 8.33 , 8.29 ];
h(:,1)  = [ 8.04 , 8.18 , 8.36 , 8.53 ];
h(:,ny) = [ 6.82 , 7.56 , 7.99 , 8.29 ];
while amax <= 0.01
	for j = 2 : nx-1
		for i = 2 : ny-1
			oldval = h(i,j);
			h(i,j) = ( h(i-1,j) + h(i+1,j) + h(i,j-1) + h(i,j+1)/4) ;
			e = abs(h(i,j)) - oldval;
			if e > amax
				amax = e;
			end
		end
	end
end
h
I NEED TO GET TO THE FOLLOWING RESULT
8.04           8.18          8.36      8.53
7.68           7.93          8.19      8.41
7.19            7.68          8.05      8.33
6.82            7.56          7.99      8.29
Can you suggest for me the correction and thank you :)
回答(3 个)
  Image Analyst
      
      
 2019-12-7
        You're setting up your boundary conditions incorrectly.  You're overwriting the corners with different numbers.  I think maybe you want this:
% Initialize boundary conditions:
h(1,:)  = [ 8.04 , 7.68 , 7.19 , 8.53];
h(end,:) = [6.82 , 7.56 , 7.99 , 8.29 ];
h(2:3,1)  = [7.68;7.19];
h(2:3,end)  = [8.41; 8.33];
h
% Here h should be
% 8.04          8.18    8.36    8.53
% 7.68           0       0      8.41
% 7.19           0       0      8.33
% 6.82          7.56    7.99    8.29
Adapt as needed.
  Hassan Abdullah Saleem
 2020-10-12
        I think I know what is the probelm in your code..you have overlap intry try to inter the boundary by value like this h(1,1) = 8.04
0 个评论
另请参阅
类别
				在 Help Center 和 File Exchange 中查找有关 Matrix Indexing 的更多信息
			
	Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!




