资源描述:
《无约束多维优化牛顿法vb编程》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、无约束多维优化牛顿法vb编程Vb编程运行后的界面Vb程序PrivateSubCommand1_Click()Dimm1AsDoubleDimm2AsDoubleDimm3AsDoubleDimm4AsDoubleDimm5AsDoubleDimm6AsDoubleDimxxAsDoubleDimfxxAsDoubleDimyp1AsDoubleDimyp2AsDoubleDimx1AsDoubleDimx2AsDoubleDimεAsDoubleDimε1AsDoubleDimhAsDoubleDimp0AsDoubleDimp1AsDoubleDimp2AsDoubleD
2、imp3AsDoubleDimyp3AsDoubleDimtidu(1,0)AsDoubleDimhaise(1,1)AsDoubleDimhaiseni(1,1)AsDoubleDims1AsDoubleDims2AsDoubleDimxx1AsDoubleDimxx2AsDoubleDimxx3AsDoublem1=Val(InputBox("请输入x1^2的系数m1","输入框",0))m2=Val(InputBox("请输入x2^2的系数m2","输入框",0))m3=Val(InputBox("请输入x1*x2的系数m3","输入框",0))m4=Val(Inpu
3、tBox("请输入x1的系数m4","输入框",0))m5=Val(InputBox("请输入x2的系数m5","输入框",0))m6=Val(InputBox("请输入常数项m6","输入框",0))x1=Val(InputBox("请输入迭代初始点x1","输入框",0))x2=Val(InputBox("请输入迭代初始点x2","输入框",0))ε=Val(InputBox("请输入迭代收敛精度ε","输入框",0))ε1=Val(InputBox("请输入一维搜索的收敛精度ε1","输入框",0))h=Val(InputBox("请输入一维搜索的初始步长h","输入
4、框",0))p0=Val(InputBox("请输入一维搜索的初始点p0","输入框",0))Label1.Caption="目标函数:f(X)="&m1&"x1^2+"&m2&"x2^2+"&m3&"x1x2+"&m4&"x1+"&m5&"x2+"&m6Label2.Caption="迭代初始点x1="&x1&"和x2="&x2&vbLf&"迭代收敛精度ε="&εLabel3.Caption="一维搜索的初始点p0="&p0&vbLf&"一维搜索的初始步长h="&h&vbLf&"一维搜索的收敛精度ε1="&ε1tidu(0,0)=2*m1*x1+m3*x2+m4tidu(
5、1,0)=2*m2*x2+m3*x1+m5haise(0,0)=2*m1haise(0,1)=m3haise(1,0)=m3haise(1,1)=2*m2haiseni(0,0)=2*m2/(4*m1*m2-m3^2)haiseni(0,1)=-m3/(4*m1*m2-m3^2)haiseni(1,0)=-m3/(4*m1*m2-m3^2)haiseni(1,1)=2*m1/(4*m1*m2-m3^2)DoWhile(tidu(0,0))^2+(tidu(1,0))^2>εs1=-(haiseni(0,0)*tidu(0,0)+haiseni(0,1)*tidu(1,0))
6、s2=-(haiseni(1,0)*tidu(0,0)+haiseni(1,1)*tidu(1,0))p1=p0xx1=x1+p1*s1:xx2=x2+p1*s2yp1=m1*xx1^2+m2*xx2^2+m3*xx1*xx2+m4*xx1+m5*xx2+m6p2=p0+hxx1=x1+p2*s1:xx2=x2+p2*s2yp2=m1*xx1^2+m2*xx2^2+m3*xx1*xx2+m4*xx1+m5*xx2+m6Ifyp1>yp2Thenh=2*hElseh=-0.25*hp3=p1:yp3=yp1p1=p2:yp1=yp2p2=p3:yp2=yp3EndIfp3=p
7、0+hxx1=x1+p3*s1:xx2=x2+p3*s2yp3=m1*xx1^2+m2*xx2^2+m3*xx1*xx2+m4*xx1+m5*xx2+m6DoWhileyp2>=yp3h=2*hp1=p2:yp1=yp2p2=p3:yp2=yp3p3=p0+hxx1=x1+p3*s1:xx2=x2+p3*s2yp3=m1*xx1^2+m2*xx2^2+m3*xx1*xx2+m4*xx1+m5*xx2+m6LoopIfh>0Thena=p1:ypa=yp1b=p3:ypb=yp3Elsea=p3:ypa=yp3b=p