登录后查看更多精彩内容~
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
program ljp
implicit none
parameter n=17
real x(n),y(n),c(n),d(n),t(n)
real a,b,sx,sxy,sum2,ave2,sum1,ave1,k,l
integer i
open(1,file='f:/4/1.txt')
open(2,file='f:/4/2.txt')
open(3,file='f:/4/3.txt')
open(4,file='f:/4/4.grd',form='binary')
open(5,file='f:/4/5.grd',form='binary')
read(1,*)(x(i),i=1,n)
read(2,*)(y(i),i=1,n)
sum1=0
sum2=0
sx=0
sxy=0
do i=1,n
sum1=sum1+x(i)
sum2=sum2+y(i)
enddo
ave1=sum1/n
ave2=sum2/n
do i=1,n
c(i)=x(i)-ave1
d(i)=y(i)-ave2
enddo
do i=1,n
sx=sx+c(i)**2
sxy=sxy+c(i)*d(i)
enddo
sx=sx/n
sxy=sxy/n
b=sxy/sx
a=ave2-ave1*b
print*,"y=",a,b,"*x"
write(*,'("y=",2f7.3,"*x")')a,b
print*,"please input x:"
read*,k
l=b*k+a
print*,l
write(*,'(f7.3)')l
do i=1,n
t(i)=a+b*(i-1)
enddo
write(3,'(17f7.3)')(t(i),i=1,n)
write(4)(y(i),i=1,n)
write(5)(t(i),i=1,n)
end
|