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 :)

댓글 수: 7

darova
darova 2019년 12월 7일
1.PNG
hasan damaj
hasan damaj 2019년 12월 7일
im dividing the value of h(i,j-1)/4 whats wrong?
darova
darova 2019년 12월 7일
Aha, ok
hasan damaj
hasan damaj 2019년 12월 11일
sir,
i need to get to the specified answer plz..
i have a problem if u can just give me advice
thank you
darova
darova 2019년 12월 11일
Did you try to divide all elements? NOt only last one
h(i,j) = ( h(i-1,j) + h(i+1,j) + h(i,j-1) + h(i,j+1))/4 ;
hasan damaj
hasan damaj 2019년 12월 11일
the equation is correct sir..
hasan damaj
hasan damaj 2019년 12월 11일
the while condition is not working with me

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

답변 (3개)

Image Analyst
Image Analyst 2019년 12월 7일

0 개 추천

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.

댓글 수: 7

hasan damaj
hasan damaj 2019년 12월 11일
but the i need to replace the 0 by the values of the h(i,j) equation..
Image Analyst
Image Analyst 2019년 12월 11일
What is your input matrix supposed to look like? From your code it looks like you were attempting to set only the outer edges of the matrix. And then your code would do something to set the interior of the matrix (I didn't delve into the algorithm you used for the loop).
hasan damaj
hasan damaj 2019년 12월 11일
im setting the outer edges..i need from the while loop to run throught the equation for differenet vallues of i and j in the euqation h(i,j) ..
attached is the original code form different programCode.JPG
Image Analyst
Image Analyst 2019년 12월 11일
It looks like the first index for H is the column, and second is the row - the opposite as MATLAB. Is that how you understand it?
Code.jpeg
hasan damaj
hasan damaj 2019년 12월 11일
correct sir i know about this :)
hasan damaj
hasan damaj 2019년 12월 11일
but the values of inner index are zeros after running the code..
hasan damaj
hasan damaj 2019년 12월 12일
how do i edit it to reach my results and thank you

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

Hassan Abdullah Saleem
Hassan Abdullah Saleem 2020년 10월 12일

0 개 추천

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

카테고리

도움말 센터File Exchange에서 Matrix Indexing에 대해 자세히 알아보기

제품

릴리스

R2019a

질문:

2019년 12월 7일

답변:

2020년 10월 12일

Community Treasure Hunt

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

Start Hunting!

Translated by