Ask Question

Name:
Title:
Your Question:

Answer Question

Name:
Your Answer:
User Submitted Source Code!


Description:
  aa
Language: FORTRAN
Code:
program Zoloto
real a,b,xmin
read *,a
read *,b
call Z(a,b,xmin)
print *,'tochka minimuma:',xmin
end

subroutine Z(a,b,xmin) 
real e,x(4),xmin
integer i,imin
F(x)=(x*x)-6*x+5
e=0.01
x(1)=a
x(4)=b
x(2)=x(1)+0.382*(x(4)-x(1))
x(3)=x(1)+0.618*(x(4)-x(1))
do while (abs(x(4)-x(1)).gt.e)
imin=1
xmin=x(1)
do i=2,4
if (f(x(i)).lt.f(xmin)) then
xmin=x(i)
imin=i
end if
end do
if ((imin.eq.1) .or. (imin.eq.2)) then
x(4)=x(3)
x(3)=x(2)
x(2)=x(1)+0.382*(x(4)-x(1))
else
x(1)=x(2)
x(2)=x(3)
x(3)=x(1)+0.618*(x(4)-x(1))
end if
end do
return
end
     
          
Comments: