fortran77 to matlab convert

3 views (last 30 days)
msh
msh on 25 Jul 2014
Commented: msh on 25 Jul 2014
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

Accepted Answer

David Young
David Young on 25 Jul 2014
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.

More Answers (0)

Categories

Find more on Loops and Conditional Statements in Help Center and File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!