资源描述:
《无约束优化――阻尼牛顿法vb编程.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库。
1、无约束最优化方法—阻尼牛顿法FunctionY(αAsDouble)AsDoubleDimx1AsDouble,x2AsDouble,s1AsDouble,s2AsDoubleDimm1AsDouble,m2AsDouble,m3AsDouble,m4AsDouble,m5AsDouble,m6AsDoublem1=Val(Text1.Text):m2=Val(Text2.Text)m3=Val(Text3.Text):m4=Val(Text4.Text)m5=Val(Text5.Text):m6=Val(Text6.Text)Y=m1*(x1+α*s1)^2
2、+m2*(x2+α*s2)^2+m3*(x1+α*s1)*(x2+α*s2)+m4*(x1+α*s1)+m5*(x2+α*s2)+m6EndFunctionFunctionyiweisosuo(αAsDouble)AsDoubleDimx1#,x2#,s1#,s2#,ε#,h#,α0#,α1#,α2#,A1#,A2#,A3#,ε1#,a#,b#,yA1#,yA2#,yA3#h=Val(Text11.Text):ε1=Val(Text12.Text)A1=α0:yA1=Y(A1)A2=α0+h:yA2=Y(A2)IfyA2>=yA1Thenh=-1*hA3=A1
3、:yA3=yA1A1=A2:yA1=yA2A2=A3:yA2=yA3Elseh=2*hEndIfA3=α0+h:yA3=Y(A3)DoUntilyA2<=yA3h=2*hA1=A2:yA1=yA2A2=A3:yA2=yA3A3=α0+h:yA3=Y(A3)LoopIfA1>A2Thena=A2:b=A1Elsea=A1:b=A2EndIfα2=a+0.618*(b-a):α1=b-0.618*(b-a)yα1=Y(α1):yα2=Y(α2)DoWhileAbs(b-a)>ε1Ifyα1<=yα2Thenb=α2α2=α1:yα2=yα1α1=b-0.618*(
4、b-a)yα1=Y(α1)Elsea=α1α1=α2:yα1=yα2α2=a+0.618*(b-a):yα2=Y(α2)EndIfLoopα=(a+b)/2yiweisosuo=αEndFunctionPrivateSubCommand1_Click()Dimx1AsDouble,x2AsDoubleDimtidu(1,0)AsDouble,haise(1,1)AsDouble,haiseni(1,1)AsDoubleDims1AsDouble,s2AsDouble,αAsDoublem1=Val(Text1.Text):m2=Val(Text2.Text)m
5、3=Val(Text3.Text):m4=Val(Text4.Text)m5=Val(Text5.Text):m6=Val(Text6.Text)x1=Val(Text7.Text):x2=Val(Text8.Text)ε=Val(Text9.Text)h=Val(Text11.Text):α0=Val(Text10.Text)tidu(0,0)=2*m1*x1+m3*x2+m4tidu(1,0)=2*m2*x2+m3*x1+m5haise(0,0)=2*m1haise(0,1)=m3haise(1,0)=m3haise(1,1)=2*m2haiseni(0,
6、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)DoWhileSqr((tidu(0,0))^2+(tidu(1,0))^2)>εs1=-(haiseni(0,0)*tidu(0,0)+haiseni(0,1)*tidu(1,0))s2=-(haiseni(1,0)*tidu(0,0)+haiseni(1,1)*tidu(1,0))α=yiweisosuo(α)x1=x1+α*s
7、1:x2=x2+α*s2fα=m1*x1^2+m2*x2^2+m3*x1*x2+m4*x1+m5*x2+m6tidu(0,0)=2*m1*x1+m3*x2+m4tidu(1,0)=2*m2*x2+m3*x1+m5LoopText13.Text="x1="&x1Text14.Text="x2="&x2Text15.Text=fαEndSubPrivateSubCommand2_Click()EndEndSub