fortran77 to matlab convert
조회 수: 3 (최근 30일)
이전 댓글 표시
Hi,
i would like to convert this code of F77 to matlab. I am confused on one particular step, the "goto" and more specifically I cannot understand whether there is any update on the loop or not.
Here it is the code
subroutine qgausl(n,x1,x2,x,w)
implicit double precision (a-h,o-z)
double precision x(n),w(n),x1,x2
eps=1.0e-8
m=(n+1)/2
xm=0.5*(x2+x1)
xl=0.5*(x2-x1)
do 12 i=1,m
z = cos(3.141592654*(i-.25)/(n+.5))
1 continue
p1 = 1.0
p2 = 0.0
do 11 j=1,n
p3 = p2
p2 = p1
p1 = ((2.0*j-1.0)*z*p2-(j-1.0)*p3)/j
11 continue
pp = n*(z*p1-p2)/(z*z-1.0)
z1 = z
z = z1-p1/pp
if (dabs(z-z1).gt.eps) go to 1
x(i) = xm-xl*z
x(n+1-i) = xm+xl*z
w(i) = 2.0*xl/((1.0-z*z)*pp*pp)
w(n+1-i) = w(i)
12 continue
return
end
댓글 수: 0
채택된 답변
David Young
2014년 7월 25일
The code from "1 continue" to "go to 1" could be translated into a while loop, something like
z1 = z + 1; % initial value so loop will be executed once
while abs(z-z1) > eps
< ... code ... >
end
You have three nested loops. All of them have updates of variables or arrays inside them. The "go to" loop updates z and z1, and their difference is presumably expected to converge towards zero.
추가 답변 (0개)
참고 항목
카테고리
Help Center 및 File Exchange에서 Loops and Conditional Statements에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!