coverting fortran to matlab

조회 수: 3 (최근 30일)
hasan damaj
hasan damaj 2019년 11월 29일
답변: hasan damaj 2019년 12월 11일
Code.JPG
  댓글 수: 5
hasan damaj
hasan damaj 2019년 11월 29일
ok no problem.
line 22 to line 28.
but i need ur help to continue the code and thank u
hasan damaj
hasan damaj 2019년 11월 29일
please continue this code program for me..knowing i will attach the picture for the results and thank youcode2.JPG

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

답변 (2개)

J Chen
J Chen 2019년 11월 29일
The following statements are wronng
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;
It should be
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 );
Change while amax > 0.01 to
while 1
..
if ( amax > 0.01 )
amax = 0;
else
break
end
end
One end statement has been missing in your code.
  댓글 수: 6
dpb
dpb 2019년 11월 29일
편집: dpb 2019년 11월 29일
Where is the looping structure in the original? That's what you need to emulate.
I don't quite agree with the other poster's suggestion (not that it won't work but it isn't my "cup of tea" in how I'd write it).
I pointed out above the modifications needed to write the while as
amax=1;
while amax>E % set E to desired tolerance value
...
end
Walter Roberson
Walter Roberson 2019년 11월 29일
while 1 .... ???????
.. (what is this)??????
In MATLAB, if and while are considered true provided that all of the values in the condition are non-zero. The constant 1 there will always be non-zero, so this code is expressing an infinite loop.
MATLAB happens to use the numeric value 1 for the logical value true so a directly equivalent way of writing while 1 is while true -- which is a form I am more likely to write.

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


hasan damaj
hasan damaj 2019년 12월 11일
h=zeros(nx,ny);
amax = 0;
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];
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
its giving me zeros in h(2,3) h(3,2) h(3,3) h(2,2)
how can i get to the results same as above

카테고리

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

태그

제품


릴리스

R2016a

Community Treasure Hunt

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

Start Hunting!

Translated by