Program zuobiao
Implicit none
Real y,y1,y2,x1,x2,x10,x20,a0,e
integer k,i,j
Write(*,*)"请输入初始点坐标x10,x20:"
Read(*,*)x10,x20
Write(*,*)"请输入精度e :"
Read(*,*)e
Write(*,*)"请输入初始步长a0:"
Read(*,*)a0
k=0
x1=x10
x2=x20
y=2*x1**2+x2**2-4*x1-4*x2+6
i=1
j=1
do while(a0>e)
k=k+1
y1=2*(x1+a0)**2+x2**2-4*(x1+a0)-4*x2+6
if (y1
do while(y1
y=y1
i=i+1
x1=x10+i*a0
x2=x20
y1=2*x1**2+x2**2-4*x1-4*x2+6
end do
x1=x10+(i-1)*a0
write(*,*) x1
else
i=-1
x1=x10+i*a0
x2=x20
y1=2*x1**2+x2**2-4*x1-4*x2+6
do while(y1
y=y1
i=i-1
x1=x10+i*a0
x2=x20
y1=2*x1**2+x2**2-4*x1-4*x2+6
end do
end if
x1=1
y=2*x1**2+x2**2-4*x1-4*x2+6
y2=2*x1**2+(x2+a0)**2-4*x1-4*(x2+a0)+6
if(y2
do while(y2
j=j+1
y=y2
x2=x20+j*a0
y2=2*x1**2+x2**2-4*x1-4*x2+6
enddo
x2=x20+(j-1)*a0
else
y2=2*x1**2+(x2-a0)**2-4*x1-4*(x2-a0)+6
do while(y2
j=j-1
y=y2
x2=x20+j*a0
y2=2*x1**2+x2**2-4*x1-4*x2+6
enddo
x2=x20+(j+1)*a0
end if
y=2*x1**2+x2**2-4*x1-4*x2+6
a0=0.5*a0
enddo
write(*,*)"最优解为:x1=",x1,"x2=",x2,"yp=",y,"迭代次数k=",k
Stop
End program
Program zuobiao
Implicit none
Real y,y1,y2,x1,x2,x10,x20,a0,e
integer k,i,j
Write(*,*)"请输入初始点坐标x10,x20:"
Read(*,*)x10,x20
Write(*,*)"请输入精度e :"
Read(*,*)e
Write(*,*)"请输入初始步长a0:"
Read(*,*)a0
k=0
x1=x10
x2=x20
y=2*x1**2+x2**2-4*x1-4*x2+6
i=1
j=1
do while(a0>e)
k=k+1
y1=2*(x1+a0)**2+x2**2-4*(x1+a0)-4*x2+6
if (y1
do while(y1
y=y1
i=i+1
x1=x10+i*a0
x2=x20
y1=2*x1**2+x2**2-4*x1-4*x2+6
end do
x1=x10+(i-1)*a0
write(*,*) x1
else
i=-1
x1=x10+i*a0
x2=x20
y1=2*x1**2+x2**2-4*x1-4*x2+6
do while(y1
y=y1
i=i-1
x1=x10+i*a0
x2=x20
y1=2*x1**2+x2**2-4*x1-4*x2+6
end do
end if
x1=1
y=2*x1**2+x2**2-4*x1-4*x2+6
y2=2*x1**2+(x2+a0)**2-4*x1-4*(x2+a0)+6
if(y2
do while(y2
j=j+1
y=y2
x2=x20+j*a0
y2=2*x1**2+x2**2-4*x1-4*x2+6
enddo
x2=x20+(j-1)*a0
else
y2=2*x1**2+(x2-a0)**2-4*x1-4*(x2-a0)+6
do while(y2
j=j-1
y=y2
x2=x20+j*a0
y2=2*x1**2+x2**2-4*x1-4*x2+6
enddo
x2=x20+(j+1)*a0
end if
y=2*x1**2+x2**2-4*x1-4*x2+6
a0=0.5*a0
enddo
write(*,*)"最优解为:x1=",x1,"x2=",x2,"yp=",y,"迭代次数k=",k
Stop
End program