fortran77 to matlab convert
3 vues (au cours des 30 derniers jours)
Afficher commentaires plus anciens
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 commentaires
Réponse acceptée
David Young
le 25 Juil 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.
Plus de réponses (0)
Voir également
Catégories
En savoir plus sur Loops and Conditional Statements dans Help Center et File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!