sinx=0 t=1 do 100 x=0.0,3.2,0.2 if(x.gt.3.2) then go to 999 do 200 n=0,99**99 t=(2n+1)*t s=(-1)**n*x**(2*n+1) k=s/float(t) if(k.lt.10**(-6)) then write(*,10) x,sinx,n 10 format('sin(x=',f6.2,')=',2x,e12.4 go to 50 else sinx=sinx+k 200 contenue 50 100 contenue 999 end
sinx=0 t=1 do 100 x=0.0,3.2,0.2 if(x.gt.3.2) then go to 999 do 200 n=0,99**99 t=(2n+1)*t s=(-1)**n*x**(2*n+1) k=s/float(t) if(k.lt.10**(-6)) then write(*,10) x,sinx,n 10 format('sin(x=',f6.2,')=',2x,e12.4 go to 50 else sinx=sinx+k 200 contenue 50 100 contenue 999 end
Compiling program unit main at line 1: 1027-S: "SOURCE.F90", line 3: Undefined statement label 100 referenced. 1131-S: "SOURCE.F90", line 3, column 7: The program unit contains unmatched nest in DO construct, IF construct, or CASE construct. 3801-W: "SOURCE.F90", line 3, column 14: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 16: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 20: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. ・・・ (以下略)
sinx=0 t=1 do 100 x=0.0,3.2,0.2 if(x.gt.3.2) then go to 999 end if do 200 n=0,100 t=(2n+1)*t s=(-1)**n*x**(2*n+1) k=s/float(t) if(k.lt.10**(-6)) then write(*,10) x,sinx 10 format('sin(x=',f6.2,')=',2x,e12.4) go to 50 else sinx=sinx+k end if 200 continue 50 100 continue 999 end
sinx=0 t=1 do 100 x=0.0,3.2,0.2 if(x.gt.3.2) then go to 999 end if do 200 n=0,100 t=(2*n+1)*t s=(-1)**n*x**(2*n+1) k=s/float(t) if(k.lt.10**(-6)) then write(*,10) x,sinx 10 format('sin(x=',f6.2,')=',2x,e12.4) go to 50 else sinx=sinx+k end if 200 continue 50 continue 100 continue 999 end
3801-W: "SOURCE.F90", line 3, column 15: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 17: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 21: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 25: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 2207-W: "SOURCE.F90", line 10, column 11: Invalid type of actual argument for intrinsic function FLOAT.
となりました。
どうやら3行目の do 100 x=0.0,3.2,0.2 と 10行目の k=s/float(t) が悪いみたいです。
早速「10**(-6)」を「(10**(-6))」と改め、「k=s/float(t)」を「k=s/t」としました。 するとエラーが 3801-W: "SOURCE.F90", line 3, column 15: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 17: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 21: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard. 3801-W: "SOURCE.F90", line 3, column 25: Real and double precision DO variables and DO loop control expressions are features deleted from the Fortran 95 standard.
real sinx sinx=0 t=1 do 100 x=0.0,100,0.2 if(x.gt.3.2) then go to 999 end if do 200 n=0,100 t=(2*n+1)*t s=(-1)**n*x**(2*n+1) k=s/t if(k.lt.(10**(-6))) then write(*,10) x,sinx 10 format('sin(x=',f6.2,')=',2x,e12.4) go to 50 else sinx=sinx+k end if 200 continue 50 continue 100 continue 999 end
PROGRAM TAYLOR IMPLICIT NONE INTEGER*8 N,L,M REAL*8 EPS,X,SINX,TMP,A1,A2 EPS = 1.0E-09 DO X = 0.0, 3.4, 0.2 SINX = 0.0 A1 = 1.0 DO N = 0, 100 A1 = REAL(2*N+1)*A1 A2 = REAL((-1)**N) TMP = (A2*(X**REAL(2*N+1)))/A1 SINX = SINX + TMP C PRINT *,ABS(TMP),TMP,A1,A2 IF (ABS(TMP) .LT. EPS)THEN WRITE(*,600) X,SINX GOTO 1000 END IF END DO 1000 CONTINUE END DO 600 FORMAT('SIN(X=',F6.2,')=',2X,E12.4) END
1さんのために… IMPLICIT NONE:暗黙の型宣言を無効にします。これで、意図しない変数の使われ方が防げます。 INTEGER*8、REAL*8:んで、これで変数の型宣言します。*8は有効桁数を指定する。(8=8桁って意味じゃないよ) DO ~ END DO:これでDOループはいいのよ。 FORMAT文:普通、WRITEの近くではなくプログラム(サブルーチン)の最後にまとめます。
17さんのコードだと、階乗の処理ができておらんです。 階乗をくっつけたらこうかな。 PROGRAM TAYLOR IMPLICIT NONE INTEGER*8 N,AN REAL*8 EPS,X,SINX,TMP,A1,A2 EPS = 1.0E-09 DO X = 0.0, 3.2, 0.2 SINX = 0.0 DO N = 0, 100 A1 = 1.0 DO AN = 1, 2*N+1 A1 = REAL(AN)*A1 END DO A2 = REAL((-1)**N) TMP = (A2*(X**REAL(2*N+1)))/A1 SINX = SINX + TMP ! PRINT *,ABS(TMP),TMP,A1,A2 IF (ABS(TMP) .LT. EPS)THEN WRITE(*,600) X,SINX GOTO 1000 END IF END DO 1000 CONTINUE END DO 600 FORMAT('SIN(X=',F6.2,')=',2X,E12.4) END
DO 200 X=0.,3.201,0.2 F = 0. G = X DO 100 M=2, 100, 2 F = F + G IF (ABS(G) .LE. 1.E-6) GOTO 200 100 G = G * (-1) * (X**2) / (M*(M+1)) 200 WRITE(*,*) 'SIN(',X,') = ', F, ' (', SIN(X) ,')' END