Reading data
- From: "hhu" <hxhu76@xxxxxxxxx>
- Date: 30 Dec 2006 14:42:19 -0800
Hi,
I am new to Fortran. Tried to write an OLS regression using the
following data:
12 39
10 42
6 33
15 43
8 35
13 35
11 33
16 44
12 37
9 34
PROGRAM REGRESSION
PARAMETER (M=10)
INTEGER I, N
REAL Y(M), X(M), ALPHA, BETA
REAL YSUM, XSUM, YXSUM, XXSUM
OPEN (UNIT=6,FILE='EXAMPLE2.CSV')
OPEN (UNIT=7, FILE='OUTPUT.DAT')
N=M
DO 10, I=1,N
READ (6, *) Y(I), X(I)
10 CONTINUE
CALL LSTSQR (Y, X, N, ALPHA, BETA)
WRITE (7, 200), ALPHA, BETA
200 FORMAT(/5X, 'ALPHA IS', F7.3,/
5X, 'BETA IS', F7.3)
STOP
END
SUBROUTINE LSTSQR(Y, X, N, A, B)
PARAMETER (M=10)
INTEGER N, I
REAL Y(M), X(M), A, B
REAL YSUM, XSUM, YXSUM, XXSUM
XSUM=0.0
YSUM=0.0
YXSUM=0.0
XXSUM=0.0
DO 10, I=1, N
XSUM=XSUM+X(I)
YSUM=YSUM+Y(I)
YXSUM=YXSUM+X(I)*Y(I)
XXSUM=XXSUM+X(I)**2
10 CONTINUE
A=(XSUM*YSUM-N*XYSUM)/(XSUM**2-N*XXSUM)
B=(YSUM-A*XSUM)/N
RETURN
END
The error was:
list in: end of file
apparent state: unit 6 named EXAMPLE2.CSV
last format: list io
lately reading direct formatted external IO
Aborted
Anyone can help me out? Thanks.
.
- Follow-Ups:
- Re: Reading data
- From: hhu
- Re: Reading data
- From: mecej4
- Re: Reading data
- From: Richard Maine
- Re: Reading data
- From: Beliavsky
- Re: Reading data
- Prev by Date: Re: generating win32 exe on linux platform
- Next by Date: Re: Reading data
- Previous by thread: Is there any problem with the following program?
- Next by thread: Re: Reading data
- Index(es):
Relevant Pages
|