到目前为止,我的代码工作正常,但我现在收到编译器错误错误,如下所示:
std =std +((x(I) -xbar))**2)
1
Error: Unclassifiable statement at (1)
这是我的代码:
program cardata
implicit none
real, dimension(291) :: x
intEGER I,N
double precision date, odometer, fuel
real :: std=0
real :: xbar=0
open(unit=10, file="car.dat", FOrm="FORMATTED", STATUS="OLD", ACTION="READ")
read(10,*) N
do I=1,N
read(10,*) x(I)
xbar= xbar +x(I)
enddo
xbar = xbar/N
DO I =1,N
std =std +((x(I) -xbar))**2
enddo
std = SQRT((std / (N - 1)))
print*,'mean:',xbar
print*, 'std deviation:',std
close(unit=10)
end program cardata
我对此很新,任何意见都将不胜感激。
答案 0 :(得分:2)
计算括号。
std =std +((x(I) -xbar))**2)
其中有三个:(
其中有四个:)
答案 1 :(得分:1)
由于这可能是一门课程,我将帮助您如何调试。 基本上从一些写陈述开始...检查你的答案......
program cardata
implicit none
...
read(10,*) N
WRITE(*,*)' I read N as ',N
WRITE(*,*)'XBar starts as ', Xbar
do I=1,N
...
! was XBAr ever set to start at 0!
xbar= xbar +x(I)
...
WRITE(*,*)'Syd starts as ',Std
DO I =1,N
std =std +((x(I) -xbar))**2
enddo
WRITE(*,*)'Std starts is now ',Std,' and n =',N
! What do we do if N=1 or is Std is negative?
WRITE(*,*)'SQRT(Std)=', SQRT(Std)
std = SQRT((std / (N - 1)))
...
在某些时候您将确定X是一列,它是第一列。第二栏是什么? Y'