Re: Reading data
- From: mecej4 <mecej4@xxxxxxxxxxxxx>
- Date: Sat, 30 Dec 2006 18:32:05 -0600
hhu wrote:
Hi,Your program compiled with g77 and gave:
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.
ALPHA IS-26.168
BETA IS992.508
The output formatting can be improved.
I suggest that you check whether your EXAMPLE2.CSV file has correct line separators for your environment. The "end-of-file" message suggests that the g77 runtime ran through the input file without finding the line separator that it expected.
Slightly OT: for any but small data sets, doing OLS by solving the normal equations is not a good idea because the algorithm is ill-conditioned.
-- mecej4
.
- References:
- Reading data
- From: hhu
- Reading data
- Prev by Date: Re: Reading data
- Next by Date: Re: Reading data
- Previous by thread: Re: Reading data
- Next by thread: Re: Reading data
- Index(es):