フィルターのクリア

fortran77 to matlab convert

4 ビュー (過去 30 日間)
msh
msh 2014 年 7 月 25 日
コメント済み: msh 2014 年 7 月 25 日
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

採用された回答

David Young
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.
  1 件のコメント
msh
msh 2014 年 7 月 25 日
Thanks, it seems that it works.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeLogical についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by