{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

CE 311K Lab10

# CE 311K Lab10 - 110 Format(3x'time(h 6x'flux(mg/h...

This preview shows pages 1–4. Sign up to view the full content.

Sheet1 Page 1 ! CE311K Introduction to Computer Methods ! Lab10 - Least Square Method ! 3/25/08 Program leastsquare Implicit none ! Declaration of variables Real time(100), flux(100),x(100),y(100) Real r2,height,v,syx,a0,a1 Integer n, i ! Open I/O files Open(unit=5, file='input.txt', status='old') Open(unit=6, file='out.dat', status='unknown') Read (5, *) n print*,n Write (6,110) Write (6,100) ! Initialize the arrays Do i=1, n Read (5,*) time(i),flux(i) x(i) = log (time(i)) y(i) = log (flux(i)) Write (6,*) time(i),flux(i),x(i),y(i) Enddo close(5) Call LSquares(x, y, n,a0,a1,r2,syx) y(n+1)=exp(a0+a1*(log(5.))) y(n+2)=exp(a0+a1*(log(50.))) y(n+3)=exp(a0+a1*(log(500.))) write(6,*) 'flux at 5hrs', y(n+1) write(6,*) 'flux @ 50hrs', y(n+1) write(6,*) 'flux @ 500hrs', y(n+3) 100 Format('====================================================')

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: 110 Format(3x, 'time(h)', 6x, 'flux(mg/h)', 6x, 'ln(Time(h))', 4x, 'ln(Flux(mg/h))') End E Subroutine LSquares(x, y, n,a0,a1,r2,syx) Implicit none Sheet1 Page 2 Real x(100), y(100) Real a0, a1, r2 Real sumx, sumy, sumxy, sumx2, xm, ym,syx Real sr, st Integer i, n sumx=0 sumy=0 sumxy=0 Do i=1,n sumx=sumx+x(i) sumy=sumy+y(i) sumxy=sumxy+x(i)*y(i) sumx2=sumx2+x(i)**2 End Do xm=sumx/n ym=sumy/n a1=((n*sumxy)-(sumx*sumy))/((n*sumx2)-(sumx**2)) a0=ym-(a1*xm) a Do i=1,n Sr=Sr+(y(i)-a0-a1*x(i))**2 St=St+(y(i)-ym)**2 End do r2=(St-Sr)/St syx=SQRT(sr/(n-2)) s write(6,*) 'a0=', a0, 'a1=', a1, 'r2=', r2, 'sr=', sr, 'st=', st Return End Sheet1 Page 3 Sheet1 Page 4 sumx2=0 xm=0 ym=0 Sr=0 St=0...
View Full Document

{[ snackBarMessage ]}

### Page1 / 4

CE 311K Lab10 - 110 Format(3x'time(h 6x'flux(mg/h...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online