Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- program noisy_data
- implicit none
- integer, parameter:: n=6
- integer:: i, j, k
- real:: x(n), yd(n), f, s, m, p, q, p1, q1
- open(11, file="in.txt")
- do i=1,n
- read(11,*) x(i)
- end do
- do i=1,n
- read(11,*) yd(i)
- end do
- close(11)
- p1=1.0
- q1=-2.0
- s=0.0
- do i=1,n
- s=s+(f(x(i),p1,q1)-yd(i))**2
- end do
- m=s
- do p=1.0,3.0,0.1
- do q=-2.0,-1.0,0.1
- s=0.0
- do i=1,n
- s=s+(f(x(i),p,q)-yd(i))**2
- end do
- if(s<m) then
- m=s
- p1=p
- q1=q
- end if
- end do
- end do
- open(12, file="out.txt")
- write(12,13) m, p1, q1
- 13 format("minimum value is ",f7.3," at p = ",f6.3," and q = ",f6.3)
- close(12)
- end program noisy_data
- function f(x, p, q) result(y)
- real:: x, y, p, q
- y=p+q*x
- end function
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement