dimension x1(100), x2(100) write(*,*)'Input 1 to read designs from data.inp' write(*,*)'Input 0 to auto-generate designs' read(*,*) input write(*,*)'Seed for random number generation' read(*,*) irand rn = rand(irand) if(input.eq.1) then OPEN(16,File='data.inp') read(16,*) nd read(16,*)(x1(i), x2(i), i=1, nd) else call design(rn, nd, x1, x2) end if np = 3 nx = 2 open(15,file='fit.inp') write(*,*)'Want to inject noise (input 0 for no/ 1 for yes) ?' read(*,*) ny if(ny.eq.1) then write(*,*)'Noise will be RN(0,sigma). Input sigma ?' read (*,*)sigma end if write(*,*)np, nx, nd write(15,*)np, nx, nd write(*,*) ' x1 x2 f error f+error' do i=1, nd fp = 3. + 2.*x1(i) + 1.* x2(i) call norrnd(rn) eps = rn*sigma if(ny.eq.1) f = fp + eps write(*,105) x1(i), x2(i), fp, eps, f write(15,100)x1(i), x2(i), f end do write(15,*) 0 close(15) 100 format(5f12.6) 105 format(5f9.4) stop end subroutine norrnd(y) y= 0. do i=1, 50 y= y+rand() end do y = y/50. - 0.5 y = y/0.04 return end subroutine design(rn, nd, x1, x2) dimension x1(100), x2(100) write(*,101) 101 format('How many data points (give a number less than 100) ? ') read(*,*) nd do i=1, nd x1(i) = 2.* rand() - 1. x2(i) = 2.* rand() - 1. end do return end