├── README.md
├── imgs
└── opt_matlab.jpg
├── 第10章
├── 例10.1
│ ├── Busacker.m
│ └── 例10.1.txt
├── 例10.10
│ ├── Postman.m
│ └── 例10.10.txt
├── 例10.11
│ ├── graphTSP.m
│ └── 例10.11.txt
├── 例10.12
│ └── 例10.12.txt
├── 例10.13
│ ├── colorcodf.asv
│ ├── colorcodf.m
│ ├── graphpts.m
│ └── 例10.13.txt
├── 例10.14
│ └── 例10.14.txt
├── 例10.2
│ ├── Ford.m
│ └── 例10.2.txt
├── 例10.3
│ └── 例10.3.txt
├── 例10.4
│ ├── Maxpath.m
│ ├── Mindist.m
│ ├── pointdist.m
│ └── 例10.4.txt
├── 例10.5
│ └── 例10.5.txt
├── 例10.6
│ └── 例10.6.txt
├── 例10.7
│ └── 例10.7.txt
├── 例10.8
│ └── 例10.8.txt
└── 例10.9
│ ├── mintree.m
│ └── 例10.9.txt
├── 第11章
├── 例11.1
│ ├── myga.m
│ ├── optifun14.m
│ ├── optifun16.m
│ └── 例11.1.txt
├── 例11.10
│ ├── optifun24.asv
│ ├── optifun24.m
│ └── 例11.10.txt
├── 例11.11
│ ├── boundtest.m
│ ├── gaDE.m
│ ├── optifun25.m
│ └── 例11.11.txt
├── 例11.12
│ ├── gaDE1.m
│ ├── optifun26.m
│ └── 例11.12.txt
├── 例11.13
│ ├── memetic.m
│ ├── optifun27.m
│ └── 例11.13.txt
├── 例11.14
│ ├── city2d.m
│ ├── memeticTSP.m
│ ├── value.m
│ └── 例11.14.txt
├── 例11.15
│ └── 例11.14.txt
├── 例11.2
│ ├── myga1.m
│ ├── optifun15.m
│ └── 例11.2.txt
├── 例11.3
│ ├── gaexhause.m
│ ├── optifun20.m
│ └── 例11.3.txt
├── 例11.4
│ ├── optifun18.m
│ └── 例11.4.txt
├── 例11.5
│ ├── optifun19.m
│ ├── press.m
│ └── 例11.5.txt
├── 例11.6
│ ├── GAJSP.m
│ └── 例11.6.txt
├── 例11.7
│ ├── gaEP.m
│ ├── optifun21.m
│ └── 例11.7.txt
├── 例11.8
│ ├── gaEP1.m
│ ├── optifun22.m
│ └── 例11.8.txt
└── 例11.9
│ ├── gaES.m
│ ├── optifun23.m
│ └── 例11.9.txt
├── 第12章
├── 例12.1
│ ├── MainAnealTSP.m
│ ├── TSPplot.m
│ ├── exchange.m
│ ├── matrixinsert.m
│ └── 例12.1.txt
├── 例12.2
│ ├── MainAneal.m
│ ├── optifun28.m
│ └── 例12.2.txt
├── 例12.3
│ ├── optifun29.m
│ └── 例12.3.txt
└── 例12.4
│ ├── cluster_dis.m
│ ├── fy.m
│ ├── guiyi_range.m
│ ├── myclass.m
│ ├── optifun33.m
│ └── 例12.4.txt
├── 第13章
├── 例13.1
│ ├── TSOATSP.m
│ └── 例13.1.txt
├── 例13.2
│ ├── TSOA.m
│ ├── optifun13.m
│ ├── selectCandidate.m
│ └── 例13.2.txt
└── 例13.3
│ ├── TSOA1.m
│ ├── cluster_center.m
│ ├── cluster_dis.m
│ ├── correct.m
│ ├── crossvalindtest.m
│ ├── guiyi.m
│ ├── optifun40.m
│ └── 例13.3.txt
├── 第14章
├── 例14.1
│ ├── antTSP.m
│ └── 例14.1.txt
├── 例14.2
│ ├── antmin.m
│ ├── optifun31.m
│ ├── optifun32.m
│ └── 例14.2.txt
└── 例14.3
│ ├── antcluster.m
│ ├── center_dis.m
│ ├── cluster_center.m
│ ├── cluster_dis.m
│ ├── guiyi.m
│ └── 例14.3.txt
├── 第15章
├── 例15.1
│ ├── mypso.m
│ ├── optifun35.m
│ └── 例15.1.txt
├── 例15.2
│ ├── mypsoTSP.m
│ └── 例15.2.txt
├── 例15.3
│ ├── optifun37.m
│ └── 例15.3.txt
├── 例15.4
│ ├── COApso.m
│ ├── createCOA.m
│ ├── optifun38.m
│ └── 例15.4.txt
└── 例15.5
│ └── 例15.5.txt
├── 第16章
├── 例16.1
│ ├── fish.m
│ ├── optifun41.m
│ └── 例16.1.txt
├── 例16.2
│ ├── fishdstc.m
│ ├── fishevaluate.m
│ ├── fishfollow.m
│ ├── fishmove.m
│ ├── fishprey.m
│ ├── fishswarm.m
│ ├── newfish.m
│ ├── optifun42.m
│ └── 例16.2.txt
├── 例16.3
│ ├── fishTSP.m
│ └── 例16.3.txt
├── 例16.4
│ └── 例16.4.txt
├── 例16.5
│ ├── Dec.m
│ ├── binfish.m
│ ├── fishevaluate3_1.m
│ ├── fishfollow3_1.m
│ ├── fishmove3_1.m
│ ├── fishprey3_1.m
│ ├── fishswarm3_1.m
│ ├── optifun15_1.m
│ └── 例16.5.txt
└── 例16.6
│ ├── optifun45.m
│ └── 例16.6.txt
├── 第17章
├── 例17.1
│ ├── SFLA.m
│ ├── optifun46.m
│ └── 例17.1.txt
├── 例17.2
│ ├── SFLATSP.m
│ └── 例17.2.txt
├── 例17.3
│ ├── SFLAcluster.m
│ ├── optifun33.m
│ └── 例17.3.txt
└── 例17.4
│ ├── bitSFLA.m
│ ├── optifun47.m
│ └── 例17.4.txt
├── 第18章
├── 例18.1
│ ├── Dec1.m
│ ├── qGA.m
│ └── 例18.1.txt
├── 例18.2
│ ├── niching.m
│ ├── optifun49.m
│ ├── qGA1.m
│ ├── rotationq.m
│ ├── trimatrix.m
│ └── 例18.2.txt
├── 例18.3
│ ├── isin_TSP.m
│ ├── qGATSP.m
│ └── 例18.3.txt
└── 例18.4
│ ├── optifun50.m
│ ├── qGA3.m
│ └── 例18.4.txt
├── 第19章
├── 例19.1
│ ├── ABC.m
│ ├── optifun51.m
│ ├── sum1.m
│ └── 例19.1.txt
├── 例19.2
│ ├── newABC.m
│ ├── optifun52.m
│ └── 例19.2.txt
├── 例19.3
│ ├── optifun53.m
│ └── 例19.3.txt
├── 例19.4
│ ├── optifun54.m
│ └── 例19.4.txt
├── 例19.5
│ ├── optifun55.m
│ ├── realbit.m
│ └── 例19.5.txt
└── 例19.6
│ ├── TSP_opt.m
│ ├── TSPop.m
│ ├── bitABC.m
│ ├── greed.m
│ ├── init_ABC.m
│ ├── isin_TSP.m
│ ├── matrixinsert.m
│ └── 例19.6.txt
├── 第20章
├── 例20.1
│ ├── chaos.m
│ ├── optifun56.m
│ ├── optifun57.m
│ └── 例20.1.txt
├── 例20.2
│ ├── chaosTSP.m
│ └── 例20.2.txt
├── 例20.3
│ ├── delsample.m
│ ├── newchoas.m
│ ├── optifun58.m
│ └── 例20.3.txt
└── 例20.4
│ ├── chaos_serch.m
│ ├── gachaos.m
│ ├── optifun59.m
│ └── 例20.4.txt
├── 第21章
├── 例21.1
│ ├── IA.m
│ ├── optifun64.m
│ └── 例21.1.txt
├── 例21.2
│ ├── dyIA.m
│ ├── optifun70.m
│ └── 例21.2.txt
├── 例21.3
│ ├── IAGA.m
│ ├── ICA_bacterin.m
│ ├── ICA_caldensity.m
│ ├── ICA_calpd.m
│ ├── ICA_calpf.m
│ ├── ICA_densitysort.m
│ ├── ICA_fitsort.m
│ ├── ICA_operator.m
│ ├── ICA_select.m
│ ├── gacrossover.m
│ ├── gamutation.m
│ ├── optifun71.m
│ └── 例21.3.txt
├── 例21.4
│ ├── ICA_TSP.m
│ ├── ICA_operator_TSP.m
│ ├── gacrossover_TSP.m
│ ├── gamutation_TSP.m
│ ├── my_delrow.m
│ └── 例21.4.txt
├── 例21.5
│ ├── IAEP.m
│ ├── gaussmution.m
│ ├── optifun72.m
│ └── 例21.5.txt
├── 例21.6
│ ├── IAES.m
│ ├── IAES_mutation.m
│ ├── IAES_recombination1.m
│ ├── IAES_select1.m
│ ├── optifun73.m
│ └── 例21.6.txt
├── 例21.7
│ ├── IAClone.m
│ ├── clone.m
│ ├── clonemutation.m
│ ├── cloneselection.m
│ ├── optifun74.m
│ └── 例21.7.txt
├── 例21.8
│ ├── IAClone_bit.m
│ ├── ICA_operator_bit.m
│ ├── clonemutation_bit.m
│ ├── optifun75.m
│ └── 例21.8.txt
└── 例21.9
│ ├── IA_cluster.m
│ ├── cluster_center.m
│ ├── dis2.m
│ ├── dyICA_bacterin.m
│ ├── dyICA_operator.m
│ ├── gacrossover_dy.m
│ ├── gamutation_dy.m
│ ├── optifun76.m
│ └── 例21.9.txt
├── 第22章
├── 例22.1
│ ├── BFO.m
│ ├── optifun63.m
│ └── 例22.1.txt
├── 例22.2
│ ├── BFO1.m
│ ├── mutation_DE.m
│ ├── my_delrow.m
│ ├── optifun65.m
│ └── 例22.2.txt
├── 例22.3
│ ├── optifun66.m
│ ├── psoBFO.m
│ └── 例22.3.txt
├── 例22.4
│ ├── optifun67.m
│ └── 例22.4.txt
├── 例22.5
│ ├── BFOTSP.m
│ ├── greedycross.m
│ └── 例22.5.txt
└── 例22.6
│ ├── BFO1cluster.m
│ ├── lack_iter.m
│ ├── mutation_DE1.m
│ ├── mymykmeans.m
│ ├── optifun68.m
│ └── 例22.6.txt
├── 第23章
├── 例23.1
│ ├── CAT.m
│ ├── optifun60.m
│ └── 例23.1.txt
├── 例23.2
│ ├── cat1.m
│ ├── optifun61.m
│ └── 例23.2.txt
├── 例23.3
│ ├── optifun62.m
│ └── 例23.3.txt
└── 例23.4
│ ├── catTSP.m
│ ├── isin.m
│ └── 例23.4.txt
├── 第24章
├── 例24.1
│ ├── GABP.m
│ └── 例24.1.txt
├── 例24.2
│ └── 例24.2.txt
└── 例24.3
│ ├── hopfieldTSP.m
│ └── 例24.3.txt
├── 第25章
├── 例25.1
│ ├── FA.m
│ ├── optifun77.m
│ └── 例25.1.txt
├── 例25.10
│ ├── APOA.m
│ ├── optifun87.m
│ └── 例25.10.txt
├── 例25.11
│ ├── ECA.m
│ ├── optifun88.m
│ └── 例25.11.txt
├── 例25.12
│ ├── CA.m
│ ├── optifun89.m
│ └── 例25.12.txt
├── 例25.13
│ ├── CRO.m
│ ├── findpos2.m
│ └── 例25.13.txt
├── 例25.14
│ ├── FWA.m
│ ├── optifun96.m
│ └── 例25.14.txt
├── 例25.2
│ ├── BA.m
│ ├── optifun78.m
│ └── 例25.2.txt
├── 例25.3
│ ├── FOA.m
│ ├── optifun79.m
│ ├── optifun79_1.m
│ └── 例25.3.txt
├── 例25.4
│ ├── BBO.m
│ ├── optifun84.m
│ └── 例25.4.txt
├── 例25.5
│ ├── IWO.m
│ ├── optifun82.m
│ └── 例25.5.txt
├── 例25.6
│ ├── GSA.m
│ ├── optifun80.m
│ └── 例25.6.txt
├── 例25.7
│ ├── HS.m
│ ├── optifun83.m
│ └── 例25.7.txt
├── 例25.8
│ ├── GWO.m
│ ├── optifun85.m
│ └── 例25.8.txt
└── 例25.9
│ ├── CS.m
│ ├── levy.m
│ ├── optifun86.m
│ └── 例25.9.txt
├── 第26章
├── 例26.1
│ ├── SSO.m
│ ├── optifun90.m
│ └── 例26.1.txt
├── 例26.10
│ ├── gradnewton.m
│ └── 例26.10.txt
├── 例26.2
│ ├── GAPSO_TSP.m
│ └── 例26.2.txt
├── 例26.3
│ ├── SAPSO.m
│ ├── optifun91.m
│ └── 例26.3.txt
├── 例26.4
│ ├── FCMCluster.m
│ ├── GASAA.m
│ └── 例26.4.txt
├── 例26.5
│ ├── GAACOA_TSP.m
│ └── 例26.5.txt
├── 例26.6
│ ├── SMSA.m
│ ├── optifun92.m
│ └── 例26.6.txt
├── 例26.7
│ ├── CAFSA.m
│ ├── optifun93.m
│ └── 例26.7.txt
├── 例26.8
│ ├── HS1.m
│ ├── optifun94.m
│ └── 例26.8.txt
└── 例26.9
│ ├── MA.m
│ ├── optifun95.m
│ └── 例26.9.txt
├── 第2章
├── 例2.1
│ ├── interval1.m
│ ├── opfun1.m
│ ├── opfun1_1.m
│ └── 例2.1.txt
├── 例2.10
│ ├── hooke1.m
│ ├── mycomplex1.m
│ ├── opfun9.m
│ ├── powell1.m
│ ├── redu.m
│ └── 例2.10.txt
├── 例2.11
│ ├── optifun5.m
│ └── 例2.11.txt
├── 例2.2
│ ├── myfzeros.m
│ ├── myjacobian1.m
│ ├── mymultifun1.m
│ └── 例2.2.txt
├── 例2.3
│ ├── goldcut1.m
│ ├── interpolation1.m
│ ├── myDF1.m
│ ├── mydiff1.m
│ ├── mynewton11.m
│ ├── myparabola1.m
│ ├── mysucfail1.m
│ ├── opfun2.m
│ └── 例2.3.txt
├── 例2.4
│ ├── mymin.m
│ ├── mysearch1.m
│ ├── opfun3.m
│ └── 例2.4.txt
├── 例2.5
│ ├── opfun4.m
│ └── 例2.5.txt
├── 例2.6
│ ├── mygrad1.m
│ ├── mynewton21.m
│ ├── opfun5.m
│ └── 例2.6.txt
├── 例2.7
│ ├── myconju1.m
│ ├── opfun6.m
│ └── 例2.7.txt
├── 例2.8
│ ├── coord1.m
│ ├── opfun7.m
│ └── 例2.8.txt
└── 例2.9
│ ├── BFGS1.m
│ ├── DFP1.m
│ ├── mybroyden1.m
│ ├── mynnewtown1.m
│ ├── opfun8.m
│ └── 例2.9.txt
├── 第3章
├── 例3.1
│ ├── sumt1.m
│ └── 例3.1.txt
├── 例3.2
│ ├── PHR1.m
│ ├── dlag1.m
│ ├── lag1.m
│ ├── mybfgs1.m
│ ├── opfun11.m
│ ├── opgfun1.m
│ ├── ophfun1.m
│ └── 例3.2.txt
├── 例3.3
│ ├── findzeros.m
│ ├── myJT1.m
│ ├── mygoldcut1.m
│ ├── zoutendijk1.m
│ └── 例3.3.txt
├── 例3.4
│ ├── rosen1.m
│ └── 例3.4.txt
├── 例3.5
│ ├── mycompare1.m
│ ├── wolfe1.m
│ └── 例3.5.txt
├── 例3.6
│ ├── dlg11.m
│ ├── lghess1.m
│ ├── lgmatrix1.m
│ ├── myhessian1.m
│ ├── newlag1.m
│ └── 例3.6.txt
├── 例3.7
│ ├── BB.m
│ ├── sqp1.m
│ └── 例3.7.txt
├── 例3.8
│ ├── newquad.m
│ ├── newsqp1.m
│ └── 例3.8.txt
└── 例3.9
│ ├── mycon1.m
│ ├── optifun7.m
│ └── 例3.9.txt
├── 第4章
├── 例4.1
│ ├── myls.m
│ └── 例4.1.txt
├── 例4.2
│ ├── mylm.m
│ └── 例4.2.txt
├── 例4.3
│ ├── mylm1.m
│ └── 例4.3.txt
├── 例4.4
│ ├── newls1.m
│ └── 例4.4.txt
├── 例4.5
│ ├── orthfun.m
│ ├── simplify.m
│ └── 例4.5.txt
└── 例4.6
│ ├── optifun8.m
│ ├── optifun9.m
│ └── 例4.6.txt
├── 第5章
├── 例5.1
│ ├── dualsimplex.m
│ ├── findeye.m
│ ├── findzeros.m
│ ├── mycompare.m
│ ├── mycompare1.m
│ ├── mysimplex.m
│ └── 例5.1.txt
├── 例5.2
│ ├── simplex1.m
│ └── 例5.2.txt
├── 例5.3
│ └── 例5.3.txt
├── 例5.4
│ └── 例5.4.txt
├── 例5.5
│ └── 例5.5.txt
├── 例5.6
│ ├── progturn.m
│ └── 例5.6.txt
└── 例5.7
│ └── 例5.7.txt
├── 第6章
├── 例6.1
│ ├── decisfun1.m
│ ├── dyprog.m
│ ├── exhaus.m
│ ├── findletter.m
│ ├── road.m
│ ├── simplex.m
│ ├── simplexphaseone.m
│ ├── simplexphasetwo.m
│ ├── simplexpiecewise.m
│ ├── simplexpostsolve.m
│ ├── simplexpresolve.m
│ ├── subfun1.m
│ ├── trafun1.m
│ └── 例6.1.txt
├── 例6.2
│ ├── decisfun2.m
│ ├── intprog.m
│ ├── myinteger.m
│ ├── subfun2.m
│ ├── trafun2.m
│ └── 例6.2.txt
├── 例6.3
│ ├── decisfun3.m
│ ├── decisfun4.m
│ ├── subfun3.m
│ ├── trafun3.m
│ └── 例6.3.txt
├── 例6.4
│ ├── decisfun6.m
│ ├── dyprog2.m
│ ├── subfun6.m
│ ├── trafun6.m
│ └── 例6.4.txt
├── 例6.5
│ ├── decisfun5.m
│ ├── subfun5.m
│ ├── trafun5.m
│ └── 例6.5.txt
├── 例6.6
│ ├── decisfun7.m
│ ├── subfun7.m
│ ├── trafun7.m
│ └── 例6.6.txt
├── 例6.7
│ ├── decisfun8.m
│ ├── objfun8.m
│ ├── subfun8.m
│ ├── trafun8.m
│ └── 例6.7.txt
├── 例6.8
│ ├── decisfun9.m
│ ├── optifun10.m
│ ├── optifun11.m
│ ├── subfun9.m
│ ├── trafun9.m
│ └── 例6.8.txt
└── 例6.9
│ ├── dyprogTSP.m
│ ├── findpos1.m
│ └── 例6.9.txt
├── 第7章
├── 例7.1
│ ├── greedy.m
│ └── 例7.1.txt
├── 例7.2
│ ├── findeye.m
│ ├── gomory.m
│ ├── mydec.m
│ └── 例7.2.txt
├── 例7.3
│ └── 例7.3.txt
├── 例7.4
│ └── 例7.4.txt
├── 例7.5
│ └── 例7.5.txt
├── 例7.6
│ ├── mybintprog.m
│ ├── mydec2bin.m
│ └── 例7.6.txt
├── 例7.7
│ ├── Hungarian.m
│ ├── findcount.m
│ ├── lattice.m
│ └── 例7.7.txt
├── 例7.8
│ └── 例7.8.txt
└── 例7.9
│ └── 例7.9.txt
├── 第8章
├── 例8.1
│ ├── myquad.asv
│ ├── myquad.m
│ └── 例8.1.txt
├── 例8.2
│ ├── myquad1.m
│ └── 例8.2.txt
├── 例8.3
│ ├── newquad.m
│ └── 例8.3.txt
└── 例8.4
│ └── 例8.4.txt
└── 第9章
├── 例9.1
└── 例9.1.txt
├── 例9.2
└── 例9.2.txt
├── 例9.3
└── 例9.3.txt
├── 例9.4
└── 例9.4.txt
├── 例9.5
└── 例9.5.txt
├── 例9.6
├── findeye.m
├── multgoal.m
├── progturn.m
└── 例9.6.txt
└── 例9.7
└── 例9.7.txt
/README.md:
--------------------------------------------------------------------------------
1 | # 最优化方法及其MATLAB实现
2 |
3 | 5124-2716-7 《最优化方法及其MATLAB实现》 程序包新 习题
4 |
5 | 论坛:https://www.ilovematlab.cn/forum-268-1.html
6 |
7 |
f_max
11 | f_max=f;
12 | max_i=i;
13 | end
14 | end
15 | end
16 | if (f_max/n>parameter.delta*fun(afish0))
17 | afish=afish0;
18 | m=find((afish1(max_i,:)-afish0)~=0);
19 | n=randperm(length(m));
20 | if length(m)>parameter.step
21 | n=n(1:parameter.step);
22 | end
23 | afish(m(n))=afish1(max_i,m(n));
24 | return
25 | else
26 | afish=fishprey3_1(fun,afish0,parameter);
27 | end
28 |
--------------------------------------------------------------------------------
/第16章/例16.5/fishmove3_1.m:
--------------------------------------------------------------------------------
1 | function afish=fishmove3_1(afish0,parameter)
2 | NC=length(afish0);
3 | afish=afish0;
4 | if rand<0.8
5 | m=ceil(NC*rand(1,parameter.step));
6 | afish(m)=abs(afish0(m)-1);
7 | else
8 | afish=afish0;
9 | end
--------------------------------------------------------------------------------
/第16章/例16.5/fishprey3_1.m:
--------------------------------------------------------------------------------
1 | function afish=fishprey3_1(fun,afish0,parameter)
2 | NC=length(afish0);
3 | for i=1:parameter.try_number
4 | afish1=afish0;
5 | afish=afish0;
6 | n=randperm(NC);
7 | n=n(1:parameter.visual);
8 | afish1(n)=abs(afish0(n)-1);
9 | m=randperm(parameter.visual);
10 | if length(m)>parameter.step
11 | m=m(1:parameter.step);
12 | end
13 | y1=fun(afish1);
14 | y2=fun(afish0);
15 | if y1>y2
16 | afish(n(m))=afish1(n(m));
17 | return
18 | end
19 | end
20 | afish=fishmove3_1(afish0,parameter);
--------------------------------------------------------------------------------
/第16章/例16.5/fishswarm3_1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第16章/例16.5/fishswarm3_1.m
--------------------------------------------------------------------------------
/第16章/例16.5/optifun15_1.m:
--------------------------------------------------------------------------------
1 | function y=optifun15_1(x,LB,UB,CodeLen)
2 | temp=Dec(LB,UB,x,CodeLen);
3 | y=sin(temp(1))*sin(temp(2))/temp(1)/temp(2);
--------------------------------------------------------------------------------
/第16章/例16.5/例16.5.txt:
--------------------------------------------------------------------------------
1 | LB=[-10;-10];UB=[10;10];
2 | eps1=1e-8;nvar=2;
3 | CodeLen=nvar*max(ceil(log2((UB-LB)./eps1 + 1)));
4 | [best_x,fval]=binfish(@(x)optifun15_1(x,LB,UB,CodeLen),30,[-10;-10],[10;10],2,1000,8,4,10,3)
5 |
6 |
--------------------------------------------------------------------------------
/第16章/例16.6/optifun45.m:
--------------------------------------------------------------------------------
1 | function y=optifun45(x)
2 | I=[0.10 0.30 0.50 1
3 | 0.17 0.33 0.50 1
4 | 0.32 0.48 0.48 1
5 | 0.12 0.30 0.50 1
6 | 0.10 0.30 0.50 1];
7 | PI0=[0.2564 0.3509 0.4803 0.900];
8 | for i=1:4
9 | y1=0;
10 | for j=1:5
11 | y1=y1+I(j,i);
12 | end
13 | y1=y1/5;
14 | y=(PI0(i)-x(1)*y1^x(2))^2;
15 | end
16 | y=-y;
17 |
18 |
--------------------------------------------------------------------------------
/第16章/例16.6/例16.6.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=newfish(@optifun45,30,1000,[0;0],[1;1],10,30,0.1)
--------------------------------------------------------------------------------
/第17章/例17.1/SFLA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第17章/例17.1/SFLA.m
--------------------------------------------------------------------------------
/第17章/例17.1/optifun46.m:
--------------------------------------------------------------------------------
1 | function y=optifun46(x)
2 | y=4*x(1)^2-2.1*x(1)^4+x(1)^6/3+x(1)*x(2)-4*x(2)^2+4*x(2)^4;
--------------------------------------------------------------------------------
/第17章/例17.1/例17.1.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=SFLA(@optifun46,[-5;-5],[5;5],40,4,2000,30)
--------------------------------------------------------------------------------
/第17章/例17.2/SFLATSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第17章/例17.2/SFLATSP.m
--------------------------------------------------------------------------------
/第17章/例17.2/例17.2.txt:
--------------------------------------------------------------------------------
1 | city =[16.4700 96.1000
2 | 16.4700 94.4400
3 | 20.0900 92.5400
4 | 22.3900 93.3700
5 | 25.2300 97.2400
6 | 22.0000 96.0500
7 | 20.4700 97.0200
8 | 17.2000 96.2900
9 | 16.3000 97.3800
10 | 14.0500 98.1200
11 | 16.3500 97.3800
12 | 21.5200 95.5900
13 | 19.4100 97.1300
14 | 20.0900 94.5500];
15 | [best_x,fval]=SFLATSP(city,40,5,200,30,0.02)
--------------------------------------------------------------------------------
/第17章/例17.3/SFLAcluster.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第17章/例17.3/SFLAcluster.m
--------------------------------------------------------------------------------
/第17章/例17.3/optifun33.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第17章/例17.3/optifun33.m
--------------------------------------------------------------------------------
/第17章/例17.3/例17.3.txt:
--------------------------------------------------------------------------------
1 | x=[-0.5370 -0.0669 -0.7694 -0.1289
2 | -0.5513 -0.3345 0.2463 0.5991
3 | 1.1903 -0.0372 1.5112 1.0693
4 | 0.2798 1.6874 0.8073 -2.1613
5 | -1.7413 -0.7508 -0.6960 0.4474
6 | -0.6296 -0.8994 -0.4760 1.2209
7 | 1.7647 0.7656 -1.0077 -0.9783
8 | 0.0998 2.0793 1.8412 -0.6294
9 | -0.9102 -0.8697 -0.1754 0.9479
10 | -0.5370 -0.8102 -1.3744 -0.8569
11 | 0.7245 -0.5724 -0.3844 0.1289
12 | 0.8473 -0.1858 0.4773 0.3413];
13 | data=guiyi_range(x,[0 1]);
14 | LB=[0 0 0 0;0 0 0 0;0 0 0 0;0 0 0 0];UB=[1 1 1 1;1 1 1 1;1 1 1 1;1 1 1 1];
15 | [class,fval]=SFLAcluster(@(x)optifun33(x,data),100,10,500,30,LB,UB,data)
--------------------------------------------------------------------------------
/第17章/例17.4/bitSFLA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第17章/例17.4/bitSFLA.m
--------------------------------------------------------------------------------
/第17章/例17.4/optifun47.m:
--------------------------------------------------------------------------------
1 | function y=optifun47(x)
2 | %V=878;
3 | %V=700;
4 | %weight=[44 46 90 72 91 40 75 35 8 54 78 40 77 15 61 17 75 29 75 63];
5 | %weight=[56 20 54 42 15];
6 | %weight=[13 18 21 29 11 28 19];
7 | %profit=[92 4 43 83 84 68 92 82 6 44 32 18 56 83 25 96 70 48 14 58];
8 | %profit=[7 5 9 6 3];
9 | %profit=[21 25 27 37 19 33 25];
10 | %y=-profit*x'+8000*((min(0,V-weight*x'))^2+(min(0,2-x(1)-x(2)-x(3)))^2+(min(0,x(4)+x(5)-1))^2+(min(0,x(6)+x(7)-1))^2);
11 | y=3*x(1)^5+4*x(1)*x(3)+2*x(2)^3-7*x(4)*x(5)*x(6)+2*x(4)^2+5*x(5)^3+...
12 | 8*x(6)^2-4*x(1)*x(2)-3*x(1)*x(3)+8000*((min(0,4*x(1)+3*x(2)+2*x(3)+3*x(4)+4*x(5)+6*x(6)-14))^2+...
13 | (min(0,3*x(1)+2*x(2)+3*x(3)+4*x(4)+2*x(5)+3*x(6)-10))^2);
14 |
15 |
16 |
--------------------------------------------------------------------------------
/第17章/例17.4/例17.4.txt:
--------------------------------------------------------------------------------
1 | [bestx,fval]=bitSFLA(@optifun47,100,20,500,50,6)
--------------------------------------------------------------------------------
/第18章/例18.1/Dec1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.1/Dec1.m
--------------------------------------------------------------------------------
/第18章/例18.1/qGA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.1/qGA.m
--------------------------------------------------------------------------------
/第18章/例18.1/例18.1.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=qGA(@optifun48)
--------------------------------------------------------------------------------
/第18章/例18.2/niching.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.2/niching.m
--------------------------------------------------------------------------------
/第18章/例18.2/optifun49.m:
--------------------------------------------------------------------------------
1 | function y=optifun49(x)
2 | y=(x(2)-5.1*x(1)^2/(4*pi^2)+5*x(1)/pi-6)^2+10*(1-1/(8*pi))*cos(x(1))+10;
--------------------------------------------------------------------------------
/第18章/例18.2/qGA1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.2/qGA1.m
--------------------------------------------------------------------------------
/第18章/例18.2/rotationq.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.2/rotationq.m
--------------------------------------------------------------------------------
/第18章/例18.2/trimatrix.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.2/trimatrix.m
--------------------------------------------------------------------------------
/第18章/例18.2/例18.2.txt:
--------------------------------------------------------------------------------
1 | [cbest1,cbest2]=qGA1(@optifun49)
--------------------------------------------------------------------------------
/第18章/例18.3/isin_TSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.3/isin_TSP.m
--------------------------------------------------------------------------------
/第18章/例18.3/qGATSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.3/qGATSP.m
--------------------------------------------------------------------------------
/第18章/例18.3/例18.3.txt:
--------------------------------------------------------------------------------
1 | city =[16.4700 96.1000
2 | 16.4700 94.4400
3 | 20.0900 92.5400
4 | 22.3900 93.3700
5 | 25.2300 97.2400
6 | 22.0000 96.0500
7 | 20.4700 97.0200
8 | 17.2000 96.2900
9 | 16.3000 97.3800
10 | 14.0500 98.1200
11 | 16.3500 97.3800
12 | 21.5200 95.5900
13 | 19.4100 97.1300
14 | 20.0900 94.5500];
15 | [route,f]=qGATSP(city)
--------------------------------------------------------------------------------
/第18章/例18.4/optifun50.m:
--------------------------------------------------------------------------------
1 | function y=optifun50(x)
2 | %y=abs(sin(30*x))*(1-x/2);
3 | y=sin(sum(abs(x-5)))/sum(abs(x-5));
--------------------------------------------------------------------------------
/第18章/例18.4/qGA3.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第18章/例18.4/qGA3.m
--------------------------------------------------------------------------------
/第18章/例18.4/例18.4.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=qGA3(@optifun50)
--------------------------------------------------------------------------------
/第19章/例19.1/ABC.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.1/ABC.m
--------------------------------------------------------------------------------
/第19章/例19.1/optifun51.m:
--------------------------------------------------------------------------------
1 | function y=optifun51(x)
2 | y=-sum1(x);
3 |
--------------------------------------------------------------------------------
/第19章/例19.1/sum1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.1/sum1.m
--------------------------------------------------------------------------------
/第19章/例19.1/例19.1.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=ABC(@optifun51,200,3000,-100.*ones(10,1),100.*ones(10,1),20)
--------------------------------------------------------------------------------
/第19章/例19.2/newABC.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.2/newABC.m
--------------------------------------------------------------------------------
/第19章/例19.2/optifun52.m:
--------------------------------------------------------------------------------
1 | function y=optifun52(x)
2 | NC=length(x);
3 | y1=0;
4 | y=1;
5 | for i=1:NC
6 | y1=y1+abs(x(i));
7 | y=y*abs(x(i));
8 | end
9 | y=-y-y1;
--------------------------------------------------------------------------------
/第19章/例19.2/例19.2.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=newABC(@optifun52,100,500,-10.*ones(30,1),10.*ones(30,1),100)
--------------------------------------------------------------------------------
/第19章/例19.3/optifun53.m:
--------------------------------------------------------------------------------
1 | function y=optifun53(x,net)
2 | y=-sim(net,x');
--------------------------------------------------------------------------------
/第19章/例19.3/例19.3.txt:
--------------------------------------------------------------------------------
1 | LB=[-5;-5];UB=[5;5];
2 | for i=1:4000
3 | x(i,:)=LB'+(UB-LB)'.*rand(1,2);
4 | y(i,1)=x(i,1)^2+x(i,2)^2;
5 | end
6 | k1=randperm(4000);
7 | input_train=x(k1(1:3900),:)';
8 | output_train=y(k1(1:3900),1)';
9 | net=newff(input_train,output_train,5);
10 | net.trainParam.epochs=100;
11 | net.trainParam.lr=0.1;
12 | net.trainParam.goal=1e-7;
13 | net=train(net,input_train,output_train);
14 | [best_x,fval]=newABC(@(x)optifun53(x,net),50,500,-5.*ones(2,1),5.*ones(2,1),100)
15 |
16 |
--------------------------------------------------------------------------------
/第19章/例19.4/optifun54.m:
--------------------------------------------------------------------------------
1 | function y=optifun54(x)
2 | y1=[37.831 45.191 52.551 58.912 66.172 74.632 81.993 89.353
3 | 40.684 45.075 51.032 58.298 65.885 72.541 77.537 85.896
4 | 43.785 46.181 49.065 54.487 61.503 71.830 81.674 89.248
5 | 43.785 44.221 50.073 56.116 64.201 72.789 82.807 93.749
6 | 44.015 46.179 50.134 55.380 62.387 72.292 84.821 95.659];
7 | y2=[43.785 45.646 50.209 55.758 62.882 72.520 83.301 94.633];
8 | y=sum((y2-x*y1).^2)+5000*(sum(x)-1)^2;
9 | if y<0
10 | y=1+abs(y);
11 | else
12 | y=1/(1+y);
13 | end
--------------------------------------------------------------------------------
/第19章/例19.4/例19.4.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=newABC(@optifun54,100,3000,zeros(5,1),ones(5,1),300)
--------------------------------------------------------------------------------
/第19章/例19.5/optifun55.m:
--------------------------------------------------------------------------------
1 | function y=optifun55(x)
2 | x=realbit(x);
3 | y1=3*x(1)*x(2)*x(4)+2*x(2)*x(3)*x(4)+9*x(2)*x(4)+5*x(1)-2*x(2)+7*x(4)-17;
4 | y2=x(1)*x(2)*x(3)*x(4)+2*x(2)*x(3)*x(4)+x(2)*x(4)+6*x(1)-2*x(2)+6*x(4)-6;
5 | y3=x(1)*x(2)*x(3)*x(4)+2*x(2)*x(3)*x(4)+x(2)*x(4)+7*x(1)-2*x(2)+7*x(4)-7;
6 | y=y1+5000*(y2^2+y3^2);
7 | if y>0
8 | y=1/(1+y);
9 | else
10 | y=1+abs(y);
11 | end
12 |
--------------------------------------------------------------------------------
/第19章/例19.5/realbit.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.5/realbit.m
--------------------------------------------------------------------------------
/第19章/例19.5/例19.5.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=newABC(@optifun55,100,500,-5.*ones(4,1),5.*ones(4,1),300);
2 | realbit(best_x)
--------------------------------------------------------------------------------
/第19章/例19.6/TSP_opt.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/TSP_opt.m
--------------------------------------------------------------------------------
/第19章/例19.6/TSPop.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/TSPop.m
--------------------------------------------------------------------------------
/第19章/例19.6/bitABC.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/bitABC.m
--------------------------------------------------------------------------------
/第19章/例19.6/greed.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/greed.m
--------------------------------------------------------------------------------
/第19章/例19.6/init_ABC.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/init_ABC.m
--------------------------------------------------------------------------------
/第19章/例19.6/isin_TSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/isin_TSP.m
--------------------------------------------------------------------------------
/第19章/例19.6/matrixinsert.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第19章/例19.6/matrixinsert.m
--------------------------------------------------------------------------------
/第19章/例19.6/例19.6.txt:
--------------------------------------------------------------------------------
1 | city =[16.4700 96.1000
2 | 16.4700 94.4400
3 | 20.0900 92.5400
4 | 22.3900 93.3700
5 | 25.2300 97.2400
6 | 22.0000 96.0500
7 | 20.4700 97.0200
8 | 17.2000 96.2900
9 | 16.3000 97.3800
10 | 14.0500 98.1200
11 | 16.3500 97.3800
12 | 21.5200 95.5900
13 | 19.4100 97.1300
14 | 20.0900 94.5500];
15 | [best_x,fval]=bitABC(30,500,10,city,'tsp')
--------------------------------------------------------------------------------
/第20章/例20.1/chaos.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.1/chaos.m
--------------------------------------------------------------------------------
/第20章/例20.1/optifun56.m:
--------------------------------------------------------------------------------
1 | function y=optifun56(x)
2 | y=4+4.5*x(1)-4*x(2)+x(1)^2+2*x(2)^2-2*x(1)*x(2)+x(1)^4-2*x(1)^2*x(2);
3 |
4 |
--------------------------------------------------------------------------------
/第20章/例20.1/optifun57.m:
--------------------------------------------------------------------------------
1 | function y=optifun57(x)
2 | y1=(1+(x(1)+x(2)+1)^2*(19-14*x(1)+3*x(1)^2-14*x(2)+6*x(1)*x(2)+3*x(2)^2));
3 | y2=(30+(2*x(1)-3*x(2))^2*(18-32*x(1)+12*x(1)^2+48*x(2)-36*x(1)*x(2)+27*x(2)^2));
4 | y=y1*y2;
--------------------------------------------------------------------------------
/第20章/例20.1/例20.1.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=chaos(@optifun56,[-8;-8],[8;8],10000,500,1)
2 |
3 | [best_x,fval]=chaos(@optifun57,[-2;-2],[2;2],10000,30,500,2)
--------------------------------------------------------------------------------
/第20章/例20.2/chaosTSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.2/chaosTSP.m
--------------------------------------------------------------------------------
/第20章/例20.2/例20.2.txt:
--------------------------------------------------------------------------------
1 | city =[16.4700 96.1000
2 | 16.4700 94.4400
3 | 20.0900 92.5400
4 | 22.3900 93.3700
5 | 25.2300 97.2400
6 | 22.0000 96.0500
7 | 20.4700 97.0200
8 | 17.2000 96.2900
9 | 16.3000 97.3800
10 | 14.0500 98.1200
11 | 16.3500 97.3800
12 | 21.5200 95.5900
13 | 19.4100 97.1300
14 | 20.0900 94.5500];
15 | [best_route,fval]=chaosTSP(city,5000,0.3,0.8,1.01)
--------------------------------------------------------------------------------
/第20章/例20.3/delsample.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.3/delsample.m
--------------------------------------------------------------------------------
/第20章/例20.3/newchoas.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.3/newchoas.m
--------------------------------------------------------------------------------
/第20章/例20.3/optifun58.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.3/optifun58.m
--------------------------------------------------------------------------------
/第20章/例20.3/例20.3.txt:
--------------------------------------------------------------------------------
1 | xmin=newchoas(@optifun58,[-1 1],[-2;-2],[2;2],50,500,1e-6)
--------------------------------------------------------------------------------
/第20章/例20.4/chaos_serch.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.4/chaos_serch.m
--------------------------------------------------------------------------------
/第20章/例20.4/gachaos.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第20章/例20.4/gachaos.m
--------------------------------------------------------------------------------
/第20章/例20.4/optifun59.m:
--------------------------------------------------------------------------------
1 | function y=optifun59(x)
2 | y=sin(x(1))*sin(x(2))/(x(1)*x(2));
3 |
--------------------------------------------------------------------------------
/第20章/例20.4/例20.4.txt:
--------------------------------------------------------------------------------
1 | cbest=gachaos(@optifun59,30,500,0.1,0.9,-10.*ones(2,1),10.*ones(2,1))
--------------------------------------------------------------------------------
/第21章/例21.1/IA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.1/IA.m
--------------------------------------------------------------------------------
/第21章/例21.1/optifun64.m:
--------------------------------------------------------------------------------
1 | function y=optifun64(x)
2 | p=[0.1312 0.1696 0.5569 0.0124 0.8283 0.5886
3 | 0.2329 0.4135 0.8307 0.3736 0.1004 0.9991
4 | 0.2348 0.1415 0.3522 0.2883 0.3047 0.6650
5 | 0.4047 0.8828 0.8732 0.5743 0.1091 0.0381];
6 | c=[1 1.2 3 3.2];
7 | a=[10 3 17 3.5 1.7 8
8 | 0.05 10 17 0.1 8 14
9 | 3 3.5 1.7 10 17 8
10 | 17 8 0.05 10 0.1 14];
11 | y=0;
12 | for i=1:4
13 | b=0;
14 | for j=1:6
15 | b=b+a(i,j)*(x(j)-p(i,j))^2;
16 | end
17 | y=y+c(i)*exp(-b);
18 | end
19 | y=-y;
20 |
21 |
--------------------------------------------------------------------------------
/第21章/例21.1/例21.1.txt:
--------------------------------------------------------------------------------
1 | [bestx,f]=IA(@optifun64,50,3000,0.2,0.9,0.9,[0;0;0;0;0;0],[1;1;1;1;1;1])
--------------------------------------------------------------------------------
/第21章/例21.2/dyIA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.2/dyIA.m
--------------------------------------------------------------------------------
/第21章/例21.2/optifun70.m:
--------------------------------------------------------------------------------
1 | function [y,y1,g1,g2]=optifun70(x)
2 | a1=(max(0,((x(1)-0.05)^2+(x(2)-2.5)^2-4.84)))^2;
3 | a2=(max(0,(-x(1)^2-(x(2)-2.5)^2+4.84)))^2;
4 | y1=(x(1)^2+x(2)-11)^2+(x(1)+x(2)^2-7)^2;
5 | y=(x(1)^2+x(2)-11)^2+(x(1)+x(2)^2-7)^2+10000*(a1+a2);
6 | g1=4.84-(x(1)-0.05)^2+(x(2)-2.5)^2;
7 | g2=x(1)^2+(x(2)-2.5)^2-4.84;
8 |
9 |
--------------------------------------------------------------------------------
/第21章/例21.2/例21.2.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=dyIA(@optifun70,100,1000,0.9,[0;0],[6;6])
2 | [y,y1,g1,g2]=optifun70(best_x);
--------------------------------------------------------------------------------
/第21章/例21.3/IAGA.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/IAGA.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_bacterin.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_bacterin.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_caldensity.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_caldensity.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_calpd.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_calpd.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_calpf.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_calpf.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_densitysort.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_densitysort.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_fitsort.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_fitsort.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_operator.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.3/ICA_operator.m
--------------------------------------------------------------------------------
/第21章/例21.3/ICA_select.m:
--------------------------------------------------------------------------------
1 | function m_antibody=ICA_select(m_antibody)
2 | antibodynum=size(m_antibody,2);
3 | a=0.7;
4 | P=zeros(1,antibodynum);
5 | for i=1:antibodynum
6 | P(i)=a*m_antibody(i).pf+(1-a)*m_antibody(i).pd;
7 | end
8 | c=zeros(1,antibodynum);
9 | for i=1:antibodynum
10 | if i==1
11 | c(i)=P(i);
12 | else
13 | c(i)=c(i-1)+P(i);
14 | end
15 | end
16 | c=c/c(antibodynum);
17 | for i=1:antibodynum
18 | p=rand;
19 | index=1;
20 | while c(index)0.5
23 | pop(i).x(j)=pop(i).x(j)+v1*fg;
24 | else
25 | pop(i).x(j)=pop(i).x(j)+v2*fg;
26 | end
27 | pop(i).x(j)=boundtest(pop(i).x(j),LB(j),UB(j));
28 | end
29 | end
30 | end
31 | end
--------------------------------------------------------------------------------
/第21章/例21.3/optifun71.m:
--------------------------------------------------------------------------------
1 | function y=optifun71(x)
2 | fa=1+(x(1)+x(2)+1)^2*(19-14*x(1)+3*x(1)^2-14*x(2)+6*x(1)*x(2)+3*x(2)^2);
3 | fa=1/fa;
4 | fb=30+(2*x(1)-3*x(2))^2*(18-32*x(1)+12*x(1)^2+48*x(2)-36*x(1)*x(2)+27*x(2)^2);
5 | fb=1/fb;
6 | y=fa*fb;
7 |
--------------------------------------------------------------------------------
/第21章/例21.3/例21.3.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=IAGA(@optifun71,100,500,0.9,0.2,[-2;-2],[2;2])
--------------------------------------------------------------------------------
/第21章/例21.4/ICA_TSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.4/ICA_TSP.m
--------------------------------------------------------------------------------
/第21章/例21.4/ICA_operator_TSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.4/ICA_operator_TSP.m
--------------------------------------------------------------------------------
/第21章/例21.4/gacrossover_TSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.4/gacrossover_TSP.m
--------------------------------------------------------------------------------
/第21章/例21.4/gamutation_TSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.4/gamutation_TSP.m
--------------------------------------------------------------------------------
/第21章/例21.4/my_delrow.m:
--------------------------------------------------------------------------------
1 | function y=my_delrow(y,x)
2 | for i=1:length(x)
3 | y(find(y==x(i)))=[];
4 | end
--------------------------------------------------------------------------------
/第21章/例21.4/例21.4.txt:
--------------------------------------------------------------------------------
1 | city =[16.4700 96.1000
2 | 16.4700 94.4400
3 | 20.0900 92.5400
4 | 22.3900 93.3700
5 | 25.2300 97.2400
6 | 22.0000 96.0500
7 | 20.4700 97.0200
8 | 17.2000 96.2900
9 | 16.3000 97.3800
10 | 14.0500 98.1200
11 | 16.3500 97.3800
12 | 21.5200 95.5900
13 | 19.4100 97.1300
14 | 20.0900 94.5500];
15 | [best_route,fval]=ICA_TSP(city,50,500,0.9,0.1)
--------------------------------------------------------------------------------
/第21章/例21.5/IAEP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.5/IAEP.m
--------------------------------------------------------------------------------
/第21章/例21.5/gaussmution.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.5/gaussmution.m
--------------------------------------------------------------------------------
/第21章/例21.5/optifun72.m:
--------------------------------------------------------------------------------
1 | function y=optifun72(x)
2 | y=-cos(x(1))*cos(x(2))*exp(-(x(1)-pi)^2-(x(2)-pi)^2);
3 | y=-y;
--------------------------------------------------------------------------------
/第21章/例21.5/例21.5.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=IAEP(@optifun72,50,500,[-100;-100],[100;100],3)
--------------------------------------------------------------------------------
/第21章/例21.6/IAES.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.6/IAES.m
--------------------------------------------------------------------------------
/第21章/例21.6/IAES_mutation.m:
--------------------------------------------------------------------------------
1 | function [oldchome,newsigma]=IAES_mutation(oldchome,oldsigma,LB,UB)
2 | popsize=size(oldchome,2);
3 | nvar=length(oldchome(1).x);
4 | for j=1:popsize
5 | a=randn;
6 | for k=1:nvar
7 | newsigma(j,k)=oldsigma(j,k)*exp(a+randn);
8 | oldchome(j).x(k)=oldchome(j).x(k)+normrnd(0,newsigma(j,k),1,1);
9 | oldchome(j).x(k)=boundtest(oldchome(j).x(k),LB(k),UB(k));
10 | end
11 | end
--------------------------------------------------------------------------------
/第21章/例21.6/IAES_recombination1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.6/IAES_recombination1.m
--------------------------------------------------------------------------------
/第21章/例21.6/IAES_select1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.6/IAES_select1.m
--------------------------------------------------------------------------------
/第21章/例21.6/optifun73.m:
--------------------------------------------------------------------------------
1 | function y=optifun73(x)
2 | %y=sin(sqrt(x(1)^2+x(2)^2))-cos(sqrt(abs(x(1)^2-x(2)^2)))-0.02*(x(2)-4.96)^2-0.02*(x(1)-5.87)^2;
3 | y=exp(-(x(1)-0.1)^2)*(sin(5*pi*x(1)^(3/4)))^6;
--------------------------------------------------------------------------------
/第21章/例21.6/例21.6.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=IAES(@optifun73,50,500,0,2)
--------------------------------------------------------------------------------
/第21章/例21.7/IAClone.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.7/IAClone.m
--------------------------------------------------------------------------------
/第21章/例21.7/clone.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.7/clone.m
--------------------------------------------------------------------------------
/第21章/例21.7/clonemutation.m:
--------------------------------------------------------------------------------
1 | function cloneantibody=clonemutation(cloneantibody,iterm,iterm_max,pm,LB,UB)
2 | cloneantibodynum=size(cloneantibody,2);
3 | NC=length(cloneantibody(1).x);
4 | for i=1:cloneantibodynum
5 | for j=1:NC
6 | p=rand;
7 | if p0.5
12 | cloneantibody(i).x(j)=cloneantibody(i).x(j)+v1*fg;
13 | else
14 | cloneantibody(i).x(j)=cloneantibody(i).x(j)+v2*fg;
15 | end
16 | cloneantibody(i).x(j)=boundtest(cloneantibody(i).x(j),LB(j),UB(j));
17 | end
18 | end
19 | end
20 |
--------------------------------------------------------------------------------
/第21章/例21.7/cloneselection.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.7/cloneselection.m
--------------------------------------------------------------------------------
/第21章/例21.7/optifun74.m:
--------------------------------------------------------------------------------
1 | function y=optifun74(x)
2 | y=x(1)^2-0.4*cos(3*pi*x(1))+2*x(2)^2-0.6*cos(4*pi*x(2))-1;
3 | y=-y;
--------------------------------------------------------------------------------
/第21章/例21.7/例21.7.txt:
--------------------------------------------------------------------------------
1 | [best_x,fval]=IAClone(@optifun74,50,3000,0.3,[-10;-10],[10;10])
--------------------------------------------------------------------------------
/第21章/例21.8/IAClone_bit.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.8/IAClone_bit.m
--------------------------------------------------------------------------------
/第21章/例21.8/ICA_operator_bit.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第21章/例21.8/ICA_operator_bit.m
--------------------------------------------------------------------------------
/第21章/例21.8/clonemutation_bit.m:
--------------------------------------------------------------------------------
1 | function cloneantibody=clonemutation_bit(cloneantibody,pm)
2 | cloneantibodynum=size(cloneantibody,2);
3 | NC=length(cloneantibody(1).x);
4 | for i=1:cloneantibodynum
5 | for j=1:NC
6 | p=rand;
7 | if p0);
9 | k=0;
10 | while k<500
11 | I1=redu(1:n,I,'c');
12 | xB=x0(I);xN=redu(x0,I,'c');
13 | B=A(:,I);N=redu(A,I,'c');
14 | g0=eval(subs(z,x_syms,x0))';
15 | gB=g0(I,:);gN=redu(g0,I,'r');
16 | r=gN-(B^-1*N)'*gB;
17 | for i=1:n-m
18 | if r(i)>0
19 | dN(i,1)=-xN(i)*r(i);
20 | else
21 | dN(i,1)=-r(i);
22 | end
23 | end
24 | dB=-B^-1*N*dN;
25 | dk(I,1)=dB;dk(I1,1)=dN;
26 | if norm(dk)0);
32 | if ~isempty(a1)
33 | b2=min(-xB(a1)'./dB(a1));
34 | else
35 | b2=inf;
36 | end
37 | if ~isempty(a2)
38 | b3=max(-xB(a2)'./dB(a2));
39 | else
40 | b3=inf;
41 | end
42 | L1=min(b2,b3);
43 | id1=find(dB<0);id2=find(dN<0);
44 | dkj=[];xkj=[];
45 | if ~isempty(id1)
46 | dkj=[dkj dB(id1)'];
47 | xkj=[xkj xB(id1)];
48 | end
49 | if ~isempty(id2)
50 | dkj=[dkj dN(id2)'];
51 | xkj=[xkj xN(id2)];
52 | end
53 | alpha_av=min(-xkj./dkj);
54 | alpha=mygoldcut1(fun,x0,dk,0,alpha_av,x_syms);
55 | xk=x0+alpha*dk';
56 | if abs(alpha-L1)<1e-6
57 | a3=findzeros(xk,0);
58 | y3=mycompare1(a3,I);
59 | y4=[];
60 | for i=1:length(y3)
61 | y4=[y4 find(I==y3(i))];
62 | end
63 | I=redu(I,y4,'c');
64 | [a4,b4]=max(xk(I1));
65 | I=sort([I b4]);
66 | end
67 | x0=xk;
68 | k=k+1;
69 | end
70 | end
71 |
72 |
73 |
74 |
75 |
--------------------------------------------------------------------------------
/第3章/例3.5/例3.5.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms x y t u
3 | fun=2*x^2+2*y^2-2*x*y-4*x-6*y;
4 | A=[1 1 1 0 ;1 5 0 1];b=[2 5];
5 | x0=[0 0 2 5];esp=0.0001;
6 | x_syms=[sym(x) sym(y) sym(t) sym(u)];
7 | [xmin,minf]=wolfe1(fun,A,x0,x_syms,esp);
8 |
9 |
--------------------------------------------------------------------------------
/第3章/例3.6/dlg11.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.6/dlg11.m
--------------------------------------------------------------------------------
/第3章/例3.6/lghess1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.6/lghess1.m
--------------------------------------------------------------------------------
/第3章/例3.6/lgmatrix1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.6/lgmatrix1.m
--------------------------------------------------------------------------------
/第3章/例3.6/myhessian1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.6/myhessian1.m
--------------------------------------------------------------------------------
/第3章/例3.6/newlag1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.6/newlag1.m
--------------------------------------------------------------------------------
/第3章/例3.6/例3.6.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms x y
3 | fun=1-x^2+exp(-x-y)+y^2-2*x*y+exp(x)-3*y;
4 | hfun=[x^2+y^2-5];
5 | x0=[1 1];x_syms=[sym(x) sym(y)];esp=0.0001;
6 | [xmin,minf]=newlag1(fun,hfun,x0,x_syms,esp);
--------------------------------------------------------------------------------
/第3章/例3.7/BB.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.7/BB.m
--------------------------------------------------------------------------------
/第3章/例3.7/sqp1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.7/sqp1.m
--------------------------------------------------------------------------------
/第3章/例3.7/例3.7.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms x y z
3 | fun=(x^2+y^2+z^2)/2;
4 | hfun=[x+2*y-z-4;x-y+z+2];
5 | x0=[0 0 0];esp=0.0001;
6 | x_syms=[sym(x) sym(y) sym(z)];
7 | [xmin,minf]=sqp1(fun,hfun,x0,x_syms,esp);
8 |
--------------------------------------------------------------------------------
/第3章/例3.8/newquad.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.8/newquad.m
--------------------------------------------------------------------------------
/第3章/例3.8/newsqp1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第3章/例3.8/newsqp1.m
--------------------------------------------------------------------------------
/第3章/例3.8/例3.8.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms x1 x2 x3 x4 x5
3 | fun=exp(x1*x2*x3*x4*x5)-(x1^3+x2^3+1)^2/2;
4 | hfun=[x1^2+x2^2+x3^2+x4^2+x5^2-10;x2*x3-5*x4*x5;x1^3+x2^3+1];
5 | gfun=[];
6 | x_syms=[sym(x1) sym(x2) sym(x3) sym(x4) sym(x5)];
7 | x0=[-1.7 1.5 1.8 -.6 -0.6];
8 | mu=[0 0 0]';
9 | lam=[];
10 | [xmin1,minf,mu,lam]=newsqp1(fun,hfun,gfun,x0,x_syms);
11 |
12 | clear
13 | syms x1 x2
14 | fun=exp(-x1-x2)+x1^2+2*x1*x2+x2^2+2*x1+6*x2;
15 | gfun=[2-x1-x2;x1;x2];
16 | hfun=[];
17 | x_syms=[sym(x1) sym(x2)];
18 | x0=[1 1];
19 | [xmin2,minf,mu,lam]=newsqp1(fun,hfun,gfun,x0,x_syms);
--------------------------------------------------------------------------------
/第3章/例3.9/mycon1.m:
--------------------------------------------------------------------------------
1 | function [c,ceq]=mycon1(x)
2 | ceq=x(2)*x(3)+x(1)*x(2)+x(1)*x(3)-75;
3 | c=[];
--------------------------------------------------------------------------------
/第3章/例3.9/optifun7.m:
--------------------------------------------------------------------------------
1 | function y=optifun7(x)
2 | y=-x(1)*x(2)*x(3);
--------------------------------------------------------------------------------
/第3章/例3.9/例3.9.txt:
--------------------------------------------------------------------------------
1 | clear
2 | options = optimset('Algorithm','sqp');
3 | [x,val]=fmincon(@optifun7,[1 2 3],[],[],[],[],zeros(3,1),[inf;inf;inf],@mycon1,options);
--------------------------------------------------------------------------------
/第4章/例4.1/myls.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第4章/例4.1/myls.m
--------------------------------------------------------------------------------
/第4章/例4.1/例4.1.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[136.5 215;136.5 250;136.5 180;138.5 250;138.5 180;
3 | 138.5 215;138.5 215;138.5 215;140.5 180;140.5 215;140.5 250];
4 | b=[6.2 7.5 4.8 5.1 4.6 4.6 4.9 4.1 2.8 3.1 4.3]';
5 | [x,r]=myls(A,b);
--------------------------------------------------------------------------------
/第4章/例4.2/mylm.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第4章/例4.2/mylm.m
--------------------------------------------------------------------------------
/第4章/例4.2/例4.2.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms k0 k1 x b
3 | fun=k0*exp(k1*x)-b;
4 | x_syms=[sym(x) sym(b)];b_syms=[sym(k0) sym(k1)];x0=[1.4 -1.0];
5 | x=[0.1 0.2 0.3 0.4 0.5]';b=[1.22 1.00 0.82 0.67 0.55]';
6 | [xmin,minf]=mylm(fun,x0,x_syms,x,b,b_syms);
--------------------------------------------------------------------------------
/第4章/例4.3/mylm1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第4章/例4.3/mylm1.m
--------------------------------------------------------------------------------
/第4章/例4.3/例4.3.txt:
--------------------------------------------------------------------------------
1 | clear
2 | x0=3.*ones(100,1);
3 | [xmin,minf]=mylm1(x0);
--------------------------------------------------------------------------------
/第4章/例4.4/newls1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第4章/例4.4/newls1.m
--------------------------------------------------------------------------------
/第4章/例4.4/例4.4.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms k0 k1 x b
3 | fun=k0-k1/x-b;
4 | x_syms=[sym(x) sym(b)];b_syms=[sym(k0) sym(k1)];
5 | x0=[10 100]; esp=1e-6;
6 | x1=[2:16]';b0=[6.42 8.2 9.58 9.5 9.7 10 9.93 9.99 10.49 10.59 10.6 10.8 10.6 10.9 10.76]';
7 | [beta,minf,stats]=newls1(fun,x1,b0,x0,x_syms,b_syms,1,esp);
8 | [beta1,minf1,stats1]=newls1(fun,x1,b0,x0,x_syms,b_syms,2,esp);
9 |
--------------------------------------------------------------------------------
/第4章/例4.5/orthfun.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第4章/例4.5/orthfun.m
--------------------------------------------------------------------------------
/第4章/例4.5/simplify.m:
--------------------------------------------------------------------------------
1 | function r = simplify(s,varargin)
2 | %SIMPLIFY Symbolic simplification.
3 | % SIMPLIFY(S) simplifies each element of the symbolic matrix S.
4 | %
5 | % SIMPLIFY(S,N) or, equivalently, SIMPLIFY(S,'Steps',N),
6 | % searches for a simplification in N steps. The default value of N is 1.
7 | %
8 | % SIMPLIFY(S,'Seconds',T) aborts the search for a simpler version
9 | % at the next end of a simplification step after T seconds. The results
10 | % will depend on the speed and system load of your computer and may
11 | % not be reproducible.
12 | %
13 | % SIMPLIFY(S,'IgnoreAnalyticConstraints',VAL) controls the level of
14 | % mathematical rigor to use on the analytical constraints while simplifying
15 | % (branch cuts, division by zero, etc). The options for VAL are TRUE or
16 | % FALSE. Specify TRUE to relax the level of mathematical rigor
17 | % in the rewriting process. The default is FALSE.
18 | %
19 | % SIMPLIFY(S, 'Criterion', 'preferReal')
20 | % discourages simplify from returning results
21 | % containing complex numbers.
22 | %
23 | % Examples:
24 | % simplify(sin(x)^2 + cos(x)^2) returns 1.
25 | % simplify(exp(c*log(sqrt(alpha+beta)))) returns (alpha + beta)^(c/2).
26 | % simplify(sqrt(x^2)) returns sqrt(x^2),
27 | % simplify(sqrt(x^2),'IgnoreAnalyticConstraints',true) returns x.
28 | %
29 | % See also SYM/FACTOR, SYM/EXPAND, SYM/COLLECT.
30 |
31 | % Copyright 1993-2014 The MathWorks, Inc.
32 |
33 | if builtin('numel',s) ~= 1, s = normalizesym(s); end
34 |
35 | posintvalidator = @(value) isnumeric(value) && 0 <= value && round(value) == value;
36 |
37 | p = inputParser;
38 | p.addOptional('Steps', 1, posintvalidator);
39 | p.addParameter('Seconds', sym(inf), @(value) isnumeric(value) && 0 <= value);
40 | p.addParameter('Criterion', 'default');
41 | p.addParameter('IgnoreAnalyticConstraints', false);
42 | p.parse(varargin{:});
43 |
44 | steps = sym(p.Results.Steps);
45 | seconds = sym(p.Results.Seconds);
46 | criterion = validatestring(p.Results.Criterion, {'default', 'preferReal'});
47 | if strcmp(criterion, 'preferReal')
48 | criterion = evalin(symengine, 'Simplify::preferReal');
49 | else
50 | criterion = evalin(symengine, 'Simplify::defaultValuation');
51 | end
52 | if sym.checkIgnoreAnalyticConstraintsValue(p.Results.IgnoreAnalyticConstraints)
53 | IAC = 'TRUE';
54 | else
55 | IAC = 'FALSE';
56 | end
57 |
58 | rSym = feval(symengine, 'simplify', s,...
59 | evalin(symengine, ['IgnoreAnalyticConstraints =', IAC]),...
60 | sym('Steps') == steps,...
61 | sym('Seconds') == seconds,...
62 | sym('Criterion') == criterion,...
63 | evalin(symengine, 'OutputType = "Best"') ...
64 | );
65 | r = privResolveOutput(rSym, s);
66 |
--------------------------------------------------------------------------------
/第4章/例4.5/例4.5.txt:
--------------------------------------------------------------------------------
1 | clear
2 | x1=[0.50 1.00 1.50 2.00 2.5 3.0];
3 | b=[1.01 1.08 1.16 1.25 1.29 1.30];
4 | m=2;
5 | [fun,res]=orthfun(x1,b,2);
--------------------------------------------------------------------------------
/第4章/例4.6/optifun8.m:
--------------------------------------------------------------------------------
1 | function y=optifun8(x,x1)
2 | y=x(1)+x(2)*exp(-0.02*x(3)*x1);
3 |
--------------------------------------------------------------------------------
/第4章/例4.6/optifun9.m:
--------------------------------------------------------------------------------
1 | function y=optifun9(x)
2 | x1=1:10;
3 | y1=[3.5 3.0 2.6 2.3 2.1 1.9 1.7 1.6 1.5 1.4];
4 | y=y1-(x(1)+x(2)*exp(-0.02*x(3)*x1));
5 |
--------------------------------------------------------------------------------
/第4章/例4.6/例4.6.txt:
--------------------------------------------------------------------------------
1 | clear
2 | x1=1:10;y1=[3.5 3.0 2.6 2.3 2.1 1.9 1.7 1.6 1.5 1.4];
3 | x0=[1 1 1];
4 | options=optimset('display','off');
5 | k1=lsqcurvefit(@optifun8,x0,x1,y1,[],[],options);
6 | k2=lsqnonlin(@optifun9,x0,[],[],options);
--------------------------------------------------------------------------------
/第5章/例5.1/dualsimplex.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.1/dualsimplex.m
--------------------------------------------------------------------------------
/第5章/例5.1/findeye.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.1/findeye.m
--------------------------------------------------------------------------------
/第5章/例5.1/findzeros.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.1/findzeros.m
--------------------------------------------------------------------------------
/第5章/例5.1/mycompare.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.1/mycompare.m
--------------------------------------------------------------------------------
/第5章/例5.1/mycompare1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.1/mycompare1.m
--------------------------------------------------------------------------------
/第5章/例5.1/mysimplex.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.1/mysimplex.m
--------------------------------------------------------------------------------
/第5章/例5.1/例5.1.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[2 2 1 0 0;1 2 0 1 0;4 0 0 0 1];b=[12;8;16];c=[-2 -3 0 0 0];
3 | [minx1,minf2,A2,s]=mysimplex(A,b,c);
4 |
5 | clear
6 | A=[1 0 1 0 0;0 1 0 1 0;1 2 0 0 1];b=[4;3;8];c=[-1 -2 0 0 0];
7 | [minx2,minf2,A2,s]=mysimplex(A,b,c);
8 |
9 | clear
10 | A=[1 0 0 1/4 -8 -1 9;0 1 0 1/2 -12 -1/2 3;0 0 1 0 0 1 0];
11 | b=[0;0;1];c=[0 0 0 -3/4 20 -1/2 6];
12 | [minx3,minf3,A2,s]=mysimplex(A,b,c);
13 |
14 |
15 | clear
16 | A=[1 -2 1 1 0;4 -1 -2 0 1;-2 0 1 0 0];b=[11;-3;1];c=[-3 1 1 0 0];
17 | [minx4,minf4,A2,s]=mysimplex(A,b,c);
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/第5章/例5.2/simplex1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.2/simplex1.m
--------------------------------------------------------------------------------
/第5章/例5.2/例5.2.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[2 1 1 1 0 0;1 2 3 0 1 0;2 2 1 0 0 1];
3 | b=[2;5;6];c=[-3 -1 -3 0 0 0];
4 | minx=simplex1(A,b,c);
--------------------------------------------------------------------------------
/第5章/例5.3/例5.3.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[1 2 1 1;1 2 3 0 ;2 1 5 0];b=[10;15;20];c=[-1 -2 -3 1];
3 | minx=simplex1(A,b,c);
4 |
--------------------------------------------------------------------------------
/第5章/例5.4/例5.4.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[-1 -2 1 0 0;1 0 0 1 0;-3 -1 0 0 1];b=[-4;5;-6];c=[1 2 0 0 0];
3 | minx=dualsimplex(A,b,c);
--------------------------------------------------------------------------------
/第5章/例5.5/例5.5.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[1 1 1 0 0;2 3 0 1 0;3 2 0 0 1];b=[150;240;300];c=[-2.4 -1.8 0 0 0];
3 | [minx,minf,A2,s]=mysimplex(A,b,c);
4 |
--------------------------------------------------------------------------------
/第5章/例5.6/progturn.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.6/progturn.m
--------------------------------------------------------------------------------
/第5章/例5.6/例5.6.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | A=[1 1 1 1 0;1 4 7 0 1];b=[3;9];c=[-2 -3 -1 0 0];
3 | [minx,minf,A2,s]=mysimplex(A,b,c);
4 |
5 |
6 | A=[1 0 -1 4/3 -1/3;0 1 2 -1/3 1/3];b=[1;2];sigma=[0 0 2 -5/3 -1/3];f0=-8;
7 | y=progturn(A,b,sigma,f0,2,3);
8 |
9 | A=[1 0 -1 4/3 -1/3;0 1 2 -1/3 1/3];b=[1;2];
10 | sigma=[0 0 -5 1 -1];f0=-6;
11 | y=progturn(A,b,sigma,f0,1,4);
12 |
13 |
14 | y=progturn(A,[-1/3;10/3],[0 0 -3 -5/3 -1/3],-28/3,1,5);
15 |
16 |
17 |
--------------------------------------------------------------------------------
/第5章/例5.7/例5.7.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第5章/例5.7/例5.7.txt
--------------------------------------------------------------------------------
/第6章/例6.1/decisfun1.m:
--------------------------------------------------------------------------------
1 | function u=decisfun1(k,x)
2 | if x==1
3 | u=[2;3;4];
4 | elseif (x==2)||(x==3)||(x==4)
5 | u=[5;6;7];
6 | elseif (x==5)||(x==6)||(x==7)
7 | u=[8;9];
8 | elseif (x==8)||(x==9)
9 | u=10;
10 | elseif x==10
11 | u=10;
12 | end
--------------------------------------------------------------------------------
/第6章/例6.1/dyprog.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.1/dyprog.m
--------------------------------------------------------------------------------
/第6章/例6.1/exhaus.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.1/exhaus.m
--------------------------------------------------------------------------------
/第6章/例6.1/findletter.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.1/findletter.m
--------------------------------------------------------------------------------
/第6章/例6.1/road.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.1/road.m
--------------------------------------------------------------------------------
/第6章/例6.1/simplex.m:
--------------------------------------------------------------------------------
1 | function [xsol, fval, lambda, exitflag, output, basicVarIdx, nonbasicVarIdx, delrows] = simplex(c, Ale, ble, ...
2 | Aeq, beq, lb, ub, options, defaultopt, computeLambda)
3 | %SIMPLEX Simplex method for general linear programming problem.
4 | % min c' * x
5 | % subject to Ale * x <= ble;
6 | % Aeq * x = beq;
7 | % lb <= x <= ub.
8 | %
9 | % XSOL = SIMPLEX(c,A,b,Aeq,beq) solves the problem above while
10 | % additionally satisfying the equality constraints Aeq * xsol = beq.
11 | %
12 | % XSOL = SIMPLEX(c,A,b,Aeq,beq,LB,UB) defines a set of lower and upper
13 | % bounds on the design variables, XSOL, so that the solution XSOL is always in the
14 | % range LB <= XSOL <= UB. If LB is [] or if any of the entries in LB are
15 | % -Inf, that is taken to mean the corresponding variable is not bounded below.
16 | % If UB is [] or if any of the entries in UB are Inf, that is taken to mean
17 | % the corresponding variable is not bounded above.
18 | %
19 | % XSOL = SIMPLEX(c,A,b,Aeq,beq,LB,UB,OPTIONS) minimizes with the default
20 | % optimization parameters replaced by values in the structure OPTIONS, an
21 | % argument created with the OPTIMSET function. See OPTIMSET for details.
22 | % Used options are Display, TolFun, LargeScale, MaxIter. Use OPTIONS = [] as
23 | % a place holder if no options are set.
24 | %
25 | % [XSOL,FVAL] = SIMPLEX(c,A,b) returns the value of the objective
26 | % function at XSOL: FVAL = c' * XSOL.
27 | %
28 | % [XSOL,FVAL,LAMBDA] = SIMPLEX(c,A,b) returns the set of Lagrange multipliers,
29 | % LAMBDA, at the solution, XSOL.
30 | % LAMBDA.ineqlin are the Lagrange multipliers for the inequalities.
31 | % LAMBDA.eqlin are the Lagrange multipliers for the equalities.
32 | % LAMBDA.lb the Lagrange multipliers for the lower bounds.
33 | % LAMBDA.ub are the Lagrange multipliers for the upper bounds.
34 | %
35 | % [XSOL,FVAL,LAMBDA,EXITFLAG] = SIMPLEX(c,A,b) describes the exit conditions:
36 | % If EXITFLAG is:
37 | % > 0 then SIMPLEX converged with a solution XSOL.
38 | % = 0 then SIMPLEX did not converge within the maximum number of iterations.
39 | % < 0 then the problem was infeasible or unbounded.
40 | %
41 | % [XSOL,FVAL,LAMBDA,EXITFLAG,OUTPUT] = SIMPLEX(c,A,b) returns a structure:
42 | % OUTPUT.iterations: number of iterations.
43 | % OUTPUT.cgiterations: [].
44 |
45 | % Copyright 1990-2015 The MathWorks, Inc.
46 |
47 | % Handle missing arguments
48 | if nargin < 10
49 | computeLambda = false;
50 | end
51 |
52 | if nargin < 8, options = [];
53 | if nargin < 7, ub = [];
54 | if nargin < 6, lb = [];
55 | if nargin < 5, beq = [];
56 | if nargin < 4, Aeq = [];
57 | end, end, end, end, end
58 |
59 | if nargout > 5
60 | restoreBasis = true;
61 | else
62 | restoreBasis = false;
63 | end
64 |
65 | % Set the default output fields
66 | output.iterations = 0;
67 | output.algorithm = 'simplex';
68 | output.cgiterations = [];
69 | exitflag = 1;
70 | basicVarIdx = []; % indices of basic variables
71 | nonbasicVarIdx = []; % indices of nonbasic variables
72 | delrows = []; % logical vector indicating deleted rows
73 |
74 | % Options setup: tol and verbosity
75 | tol = optimget(options,'TolFun',defaultopt,'fast');
76 | switch optimget(options,'Display',defaultopt,'fast')
77 | case {'none','off'}
78 | verbosity = 0; % error only
79 | case 'iter'
80 | verbosity = 2; % iter and final
81 | case 'final'
82 | verbosity = 1;
83 | case 'testing'
84 | verbosity = 4; % all
85 | otherwise
86 | verbosity = 1; % final message
87 | end
88 |
89 | % Check the input data
90 | [c, Ale, ble, Aeq, beq, lb, ub, exitflagDatacheck] = datacheck(c, Ale, ble, Aeq, beq, lb, ub, verbosity);
91 | n_orig = length(c);
92 | nslacks = length(ble);
93 | meq = length(beq);
94 |
95 | maxiter = optimget(options,'MaxIter',defaultopt,'fast');
96 | if ischar(maxiter)
97 | if isequal(lower(maxiter),'100*numberofvariables')
98 | maxiter = 100*n_orig;
99 | else
100 | error(message('optim:simplex:InvalidMaxIter'))
101 | end
102 | end
103 |
104 | % Final output messages:
105 | presolveTermMsg = sprintf('Optimization terminated during preprocessing phase.');
106 | presolveOptMsg = sprintf('Optimization terminated during preprocessing phase.');
107 | presolveInfsMsg = sprintf('Exiting: The constraints are overly stringent; no feasible point exists.');
108 | unboundedMsg = sprintf('Exiting: The problem is unbounded; the constraints are not restrictive enough.');
109 | excdMaxiterPhase1Msg = sprintf(['Exiting: Maximum number of iterations exceeded in Phase 1;' ...
110 | '\n' ' increase options.MaxIterations.']);
111 | phaseoneInfsMsg = sprintf('Exiting: The constraints are overly stringent; no feasible starting point found.');
112 | excdMaxiterPhase2Msg = sprintf('Exiting: Maximum number of iterations exceeded; increase options.MaxIterations.');
113 | optMsg = sprintf('Optimization terminated.');
114 |
115 | % Preprocessing the problem.
116 | % First transform into the standard LP form with equality constraints and bounds by adding slack variables.
117 | % The variable ndel represents the number of original variables deleted from the presolve procedure.
118 | [c0, cc, AA, bb, lbb, ubb, ndel, resolveSol, lambda, lamindx, exitflagp, MarkVars, MarkConstr] = ...
119 | simplexpresolve(c, Ale, ble, Aeq, beq, lb, ub, verbosity, computeLambda, restoreBasis);
120 |
121 | if exitflagp < 0
122 | exitflag = exitflagp;
123 | if exitflag == -1 % This value will be remapped to -2 in linprog.m
124 | msg = sprintf([presolveTermMsg '\n' presolveInfsMsg]);
125 | elseif exitflag == -2 % This value will be remapped to -3 in linprog.m
126 | msg = sprintf([presolveTermMsg '\n' unboundedMsg]);
127 | else
128 | error(message('optim:simplex:WrongStatus'))
129 | end
130 | if verbosity > 0
131 | disp(msg)
132 | end
133 | % At presolve stage, nothing to return to output yet.
134 | xsol = [];
135 | fval = [];
136 | lambda.ineqlin = [];
137 | lambda.eqlin = [];
138 | lambda.lower = [];
139 | lambda.upper = [];
140 | output.message = msg;
141 | return;
142 | elseif exitflagp == 0
143 | % Constraint matrix is empty, all variables are fixed, singleton, etc -
144 | % no more variables left to solve for (presolve solves the problem
145 | % already); call postsolve to restore the solution and the lambda to
146 | % the original system.
147 | xs = zeros(0,1);
148 | fv = 0.0;
149 | dualvars = struct('y', [], 'z', [], 'w', []);
150 | caseflag1 = 1; % Empty constraint matrix
151 | [xsol, fval, lambda, exitflagps, basicVarIdx, nonbasicVarIdx, delrows] = simplexpostsolve(xs, fv, c0, c, resolveSol, verbosity, ...
152 | lambda, lamindx, dualvars, Ale, Aeq, computeLambda, caseflag1, MarkVars, basicVarIdx, nonbasicVarIdx, restoreBasis, MarkConstr, []);
153 | exitflag = exitflagps;
154 |
155 | if (exitflag == 1)
156 | msg = sprintf(['Solution determined by the constraints.\n' presolveOptMsg]);
157 | elseif (exitflag == -1) % This value will be remapped to -2 in linprog.m
158 | msg = sprintf([presolveTermMsg '\n' presolveInfsMsg]);
159 | else
160 | error(message('optim:simplex:WrongStatus'));
161 | end
162 | % Display the final statement
163 | if verbosity > 0
164 | disp(msg)
165 | end
166 | output.message = msg;
167 | return;
168 | end
169 |
170 | %Step 3. phase 1 to find the first feasible basis by solving an auxiliary piecewise linear problem
171 | [c1, A, b, lbs, ubs, basicVarIdx, nonbasicVarIdx, x1opt, exitflagPhase1, lamindx, delrows1] = ...
172 | simplexphaseone(cc, AA, bb, lbb, ubb, n_orig, ndel, nslacks, maxiter, tol, verbosity, lamindx, computeLambda);
173 | exitflag = exitflagPhase1;
174 | % exitflagPhase1 = 1, feasible;
175 | % exitflagPhase1 = 0, exceed the maximum iteration;
176 | % exitflagPhase1 = -1, infeasible;
177 | % exitflagPhase1 = -2, unbounded.
178 |
179 | % Note that empty objective coefficients is recasted as zeros(n_orig, 1) in linprog.
180 | if (exitflagPhase1 == 1) && all(c == 0)
181 | computeLambda = false;
182 | if (verbosity >=2)
183 | disp(getString(message('optim:simplex:SkipPhase2')));
184 | end
185 | end
186 |
187 | % Step 4. phase 2 is the main iterations to achieve optimality
188 | if exitflagPhase1 == 1 && any(c ~= 0)
189 | [xs, fv, dualvars, exitflagPhase2, niters, basicVarIdx, nonbasicVarIdx] = simplexphasetwo(c1, A, b, lbs, ubs, basicVarIdx, nonbasicVarIdx, x1opt, maxiter, tol, verbosity, computeLambda);
190 | output.iterations = niters;
191 | exitflag = exitflagPhase2;
192 | % exitflagPhase2 = 1, optimal; exitflagPhase2 =0, maxiter is exceeded in Phase 2;
193 | % exitflagPhase2 = -1, infeasible; exitflagPhase2 = -2, unbounded.
194 | else
195 | xs = x1opt;
196 | fv = c1' * x1opt;
197 | dualvars = struct('y', [], 'z', [], 'w', []);
198 | end
199 |
200 | % Step 5. postsolve restores the solution and the lambda (if applicable) to the original system
201 | caseflag2 = 2; % Nonempty constraint matrix
202 | if exitflag <= 0
203 | computeLambda = false;
204 | restoreBasis = false;
205 | end
206 | [xsol, fval, lambda, exitflagps, basicVarIdx, nonbasicVarIdx, delrows] = simplexpostsolve(xs, fv, c0, c, resolveSol, verbosity, ...
207 | lambda, lamindx, dualvars, Ale, Aeq, computeLambda, caseflag2, MarkVars, basicVarIdx, nonbasicVarIdx, restoreBasis, MarkConstr, delrows1);
208 | if exitflag == 1
209 | exitflag = exitflagps;
210 | end
211 |
212 | % Make sure output vector is full.
213 | xsol = full(xsol);
214 |
215 | % The values -1 and -2 of exitflag will be remapped to -2 and -3,
216 | % respectively, in linprog.m
217 | if exitflag == 1
218 | msg = optMsg;
219 | elseif exitflagPhase1 == 0 % Note exitflag == 0.
220 | msg = excdMaxiterPhase1Msg;
221 | elseif exitflag == 0
222 | msg = excdMaxiterPhase2Msg;
223 | elseif exitflagPhase1 == -1 % Note exitflag == -1.
224 | msg = phaseoneInfsMsg;
225 | elseif exitflag == -1
226 | msg = presolveInfsMsg;
227 | elseif exitflag == -2
228 | msg = unboundedMsg;
229 | else
230 | error(message('optim:simplex:WrongStatus'));
231 | end
232 | % Display the final statement
233 | if verbosity > 0
234 | disp(msg)
235 | end
236 | output.message = msg;
237 |
238 | %--------------------------------------------------------------------------
239 | %-----------------------SIMPLEX Subfunctions----------------------------
240 | %--------------------------------------------------------------------------
241 | function [c, Ale, ble, Aeq, beq, lb, ub, exitflagDatacheck] = ...
242 | datacheck(c, Ale, ble, Aeq, beq, lb, ub, verbosity)
243 | % DATACHECK Check input data on the consistency of dimensions and boundary conditions.
244 |
245 | exitflagDatacheck = 1;
246 | % Check input data
247 | if (nargin < 3), ble = [];
248 | if (nargin < 2), Ale = [];
249 | if (nargin < 1)
250 | error(message('optim:simplex:NotEnoughInputs'));
251 | end, end, end
252 |
253 | [mle, nle] = size(Ale);
254 | [meq, neq] = size(Aeq);
255 | nvars = max( [length(c), length(ub), length(lb), neq, nle] );
256 |
257 | if isempty(ub)
258 | ub = inf(nvars, 1);
259 | if (verbosity >= 4)
260 | disp(' Assuming all variables are unbounded above.');
261 | end
262 | end
263 |
264 | if isempty(lb)
265 | lb = -inf(nvars, 1);
266 | if (verbosity >= 4)
267 | disp(' Assuming all variables are unbounded below.');
268 | end
269 | end
270 |
271 | if isempty(c), c=zeros(nvars,1); end
272 | if isempty(Ale), Ale=zeros(0,nvars); end
273 | if isempty(ble), ble=zeros(0,1); end
274 | if isempty(Aeq), Aeq=zeros(0,nvars); end
275 | if isempty(beq), beq=zeros(0,1); end
276 |
277 | c = c(:);
278 | lb = lb(:);
279 | ub = ub(:);
280 | ble = ble(:);
281 | beq = beq(:);
282 |
283 | if (size(c,2) ~= 1)
284 | error(message('optim:simplex:InvalidFirstInput'))
285 | end
286 |
287 | if any(isnan([c; lb; ub])) || any(isnan([ble;beq])) || any(any(isnan([Ale; Aeq])))
288 | exitflagDatacheck = -1;
289 | error(message('optim:simplex:NaNInput'));
290 | end
291 |
292 | if any(any(isinf([c'; Ale; Aeq]))) || any(isinf([ble;beq]))
293 | exitflagDatacheck = -1;
294 | error(message('optim:simplex:InfInput'));
295 | end
296 |
297 | %--------------------------------------------------------------------------
298 | %-------------END of SIMPLEX and its subfunctions-----------------------
299 | %--------------------------------------------------------------------------
300 |
--------------------------------------------------------------------------------
/第6章/例6.1/subfun1.m:
--------------------------------------------------------------------------------
1 | function v=subfun1(k,x,u,d)
2 | xz=[x==1 & u==2,x==1 & u==3,x==1 & u==4,...
3 | x==2 & u==5,x==2 & u==6,x==2 & u==7,...
4 | x==3 & u==5,x==3 & u==6,x==3 & u==7,...
5 | x==4 & u==5,x==4 & u==6,x==4 & u==7,...
6 | x==5 & u==8,x==5 & u==9,...
7 | x==6 & u==8,x==6 & u==9,...
8 | x==7 & u==8,x==7 & u==9,...
9 | x==8 & u==10,...
10 | x==9 & u==10];
11 | v=xz*d;
--------------------------------------------------------------------------------
/第6章/例6.1/trafun1.m:
--------------------------------------------------------------------------------
1 | function w=trafun1(k,x,u)
2 | w=u;
--------------------------------------------------------------------------------
/第6章/例6.1/例6.1.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | x={[1];[2 3 4];[5 6 7];[8 9];[10]};
3 | d={[2 4 3];[7 4 6;3 2 4;4 1 5];[1 4;6 3;3 3];[3;4]};
4 | str={'A';'B1,B2,B3';'C1,C2,C3';'D1,D2';'E'};
5 | [y,rd2]=road(x,d,str);
6 |
7 |
8 | clear;
9 | x=[1 2 5 8 10;NaN 3 6 9 NaN;NaN 4 7 NaN NaN];
10 | str={'A';'B1,B2,B3';'C1,C2,C3';'D1,D2';'E'};
11 | d=[2 4 3 7 4 6 3 2 4 4 1 5 1 4 6 3 3 3 3 4]';
12 | [y,fval,rd2]=dyprog(x,d,@decisfun1,@subfun1,@trafun1,[],str);
13 |
14 | clear
15 | b=[1;0;0;0;0;0;0;0;0;1];f=[2 4 3 7 4 6 3 2 4 4 1 5 1 4 6 3 3 3 3 4];
16 | A=[1 1 1 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0;1 0 0 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0 0 0 0
17 | 0 1 0 0 0 0 -1 -1 -1 0 0 0 0 0 0 0 0 0 0 0;0 0 1 0 0 0 0 0 0 -1 -1 -1 0 0 0 0 0 0 0 0
18 | 0 0 0 1 0 0 1 0 0 1 0 0 -1 -1 0 0 0 0 0 0;0 0 0 0 1 0 0 1 0 0 1 0 0 0 -1 -1 0 0 0 0
19 | 0 0 0 0 0 1 0 0 1 0 0 1 0 0 0 0 -1 -1 0 0;0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 -1 0
20 | 0 0 0 0 0 0 0 0 0 0 0 1 0 1 0 1 0 0 0 -1;0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1];
21 | [x,fval]=bintprog(f,[],[],A,b);
22 |
23 |
24 |
--------------------------------------------------------------------------------
/第6章/例6.2/decisfun2.m:
--------------------------------------------------------------------------------
1 | function u=decisfun2(k,x)
2 | if k==4
3 | u=x;
4 | else
5 | u=0:x;
6 | end
--------------------------------------------------------------------------------
/第6章/例6.2/intprog.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.2/intprog.m
--------------------------------------------------------------------------------
/第6章/例6.2/myinteger.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.2/myinteger.m
--------------------------------------------------------------------------------
/第6章/例6.2/subfun2.m:
--------------------------------------------------------------------------------
1 | function v=subfun2(k,x,u,c)
2 | v=([0,10,20,30,40,50,60]==u)*c(:,k);
--------------------------------------------------------------------------------
/第6章/例6.2/trafun2.m:
--------------------------------------------------------------------------------
1 | function w=trafun2(k,x,u)
2 | w=x-u;
--------------------------------------------------------------------------------
/第6章/例6.2/例6.2.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | c=[0,0,0,0;20,20,25,25;50,40,60,40;65,50,85,50;80,55,100,60;85,60,110,65;85,65,115,70];
3 | x=[ 0 0 0 0;10 10 10 10; 20 20 20 20; 30 30 30 30
4 | 40 40 40 40; 50 50 50 50;60 60 60 60];
5 | [y,fval]=dyprog(x,-c,@decisfun2,@subfun2,@trafun2);
6 |
7 |
8 | clear
9 | f=-[0 20 50 65 80 85 85 0 20 40 50 55 60 65 0 25 60 85 100 110 115 0 25 40 50 60 65 70 0 0 0 0];
10 | Aeq=[ones(1,7) zeros(1,25);zeros(1,7) ones(1,7) zeros(1,18);
11 | zeros(1,14) ones(1,7) zeros(1,11);zeros(1,21) ones(1,7) zeros(1,4)
12 | 0 10 20 30 40 50 60 zeros(1,21) -1 0 0 0
13 | zeros(1,7) 0 10 20 30 40 50 60 zeros(1,14) 0 -1 0 0
14 | zeros(1,14) 0 10 20 30 40 50 60 zeros(1,7) 0 0 -1 0
15 | zeros(1,21) 0 10 20 30 40 50 60 0 0 0 -1;zeros(1,28) 1 1 1 1];
16 | Beq=[1 1 1 1 0 0 0 0 60];LB=zeros(32,1);UB = [ones(1,28) 60 60 60 60]';
17 | [x,val,stats]=intprog(f,[],[],1:32,Aeq,Beq,LB,UB);
18 |
19 |
--------------------------------------------------------------------------------
/第6章/例6.3/decisfun3.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.3/decisfun3.m
--------------------------------------------------------------------------------
/第6章/例6.3/decisfun4.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.3/decisfun4.m
--------------------------------------------------------------------------------
/第6章/例6.3/subfun3.m:
--------------------------------------------------------------------------------
1 | function v=subfun3(k,x,u,c)
2 | v=c(k)*u;
3 | v=-v;
--------------------------------------------------------------------------------
/第6章/例6.3/trafun3.m:
--------------------------------------------------------------------------------
1 | function w=trafun3(k,x,u)
2 | ww=[3,4,2,5];
3 | w=x-ww(k)*u;
--------------------------------------------------------------------------------
/第6章/例6.3/例6.3.txt:
--------------------------------------------------------------------------------
1 | clear
2 | c=[4,5,3,6];T=12;
3 | x=nan*ones(T+1,4);
4 | x(:,1)=(0:T);
5 | x(:,2)=(0:T)';
6 | x(:,3)=(0:T)';
7 | x(:,4)=(0:T)';
8 | [y,fval]=dyprog(x,c,@decisfun3,@subfun3,@trafun3);
9 |
10 |
11 | clear
12 | T=12;x=nan*ones(T+1,4);
13 | x(1:T-6,1)=(7:T);
14 | x(1:T-3,2) = (4:T)';
15 | x(:,3)=(0:T)';
16 | x(:,4)=(0:T)';
17 | c=[4,5,3,6];
18 | [y,fval]=dyprog(x,c,@decisfun4,@subfun3,@trafun3);
19 |
--------------------------------------------------------------------------------
/第6章/例6.4/decisfun6.m:
--------------------------------------------------------------------------------
1 | function [u1,u2]=decisfun6(k,x1,x2)
2 | w=[3 4 5];v=[8 6 4];
3 | u1=0:1:min(x1/w(k),x2/v(k));
4 | u2=1;
5 |
--------------------------------------------------------------------------------
/第6章/例6.4/dyprog2.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.4/dyprog2.m
--------------------------------------------------------------------------------
/第6章/例6.4/subfun6.m:
--------------------------------------------------------------------------------
1 | function f=subfun6(k,x1,x2,u1,u2)
2 | c=[4 5 6];
3 | f=-c(k)*u1;
4 |
--------------------------------------------------------------------------------
/第6章/例6.4/trafun6.m:
--------------------------------------------------------------------------------
1 | function s=trafun6(k,x1,x2,u1,u2)
2 | w=[3 4 5];v=[8 6 4];
3 | s(1)=x1-u1*w(k);
4 | s(2)=x2-u1*v(k);
5 |
6 |
--------------------------------------------------------------------------------
/第6章/例6.4/例6.4.txt:
--------------------------------------------------------------------------------
1 | a1=0:10;b1=0:22;s1=nan*ones(11,1);s1(1)=10;s2=nan*ones(23,1);s2(1)= 22;
2 | x1=[s1 a1' a1'];x2=[s2 b1' b1'];
3 | [y,fval]=dyprog2(x1,x2,@decisfun6,@subfun6,@trafun6);
4 |
--------------------------------------------------------------------------------
/第6章/例6.5/decisfun5.m:
--------------------------------------------------------------------------------
1 | function [u1,u2]=decisfun5(k,x1,x2)
2 | u1=0:1:x1;u2=0:1:x2;
3 |
--------------------------------------------------------------------------------
/第6章/例6.5/subfun5.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.5/subfun5.m
--------------------------------------------------------------------------------
/第6章/例6.5/trafun5.m:
--------------------------------------------------------------------------------
1 | function s=trafun5(k,x1,x2,u1,u2)
2 | s(1)=x1-u1;s(2)=x2-u2;
3 |
--------------------------------------------------------------------------------
/第6章/例6.5/例6.5.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | a1=0:3;b1=0:3;s1=nan*ones(4,1);s1(1)=3;s2=nan*ones(4,1);s2(1)=3;
3 | x1=[s1 a1' a1'];x2=[s2 b1' b1'];
4 | [y,fval]=dyprog2(x1,x2,@decisfun5,@subfun5,@trafun5);
5 |
--------------------------------------------------------------------------------
/第6章/例6.6/decisfun7.m:
--------------------------------------------------------------------------------
1 | function u=decisfun7(k,x)
2 | q=10*[6 7 12 6];
3 | if q(k)-x<0
4 | u=0:100;
5 | else
6 | u=q(k)-x:100;
7 | end
8 | u=u(:);
--------------------------------------------------------------------------------
/第6章/例6.6/subfun7.m:
--------------------------------------------------------------------------------
1 | function v=subfun7(k,x,u,c)
2 | v=c(k)*u+2*x;
--------------------------------------------------------------------------------
/第6章/例6.6/trafun7.m:
--------------------------------------------------------------------------------
1 | function y=trafun7(k,x,u)
2 | q=10*[6 7 12 6];
3 | y=x+u-q(k);
--------------------------------------------------------------------------------
/第6章/例6.6/例6.6.txt:
--------------------------------------------------------------------------------
1 | clear
2 | x=nan*ones(14,4);c=[70 72 80 76];
3 | x(1:7,1)=10*(0:6)';x(1:11,2)=10*(0:10)';x(1:12,3)=10*(2:13)';x(1:7,4)=10*(0:6)';
4 | [y,fval]=dyprog(x,c,@decisfun7,@subfun7,@trafun7);
5 |
6 | clear;
7 | Aeq=[1 zeros(1,8) -10 0 0 0;0 1 zeros(1, 7) 0 -10 0 0; 0 0 1 zeros(1,6) 0 0 -10 0;
8 | 0 0 0 1 zeros(1,5) 0 0 0 -10;zeros(1,4) 1 zeros(1,8);1 0 0 0 1 -1 zeros(1,7);
9 | 0 1 0 0 0 1 -1 zeros(1,6);0 0 1 0 0 0 1 -1 zeros(1,5);0 0 0 1 0 0 0 1 -1 zeros(1,4);
10 | 0 0 0 0 0 0 0 0 1 0 0 0 0];
11 | LB=[0 0 0 0 0 0 0 0 0 0 0 0 0]';
12 | UB=[100 100 100 100 100 100 100 100 0 10 10 10 10]';
13 | f=[70 72 80 76 2*ones(1,5) 0 0 0 0];Beq=[0;0;0;0;20;60;70;120;60;0];
14 | [x,val]=intprog(f,[],[],[10 11 12 13],Aeq,Beq,LB,UB);
15 |
16 |
--------------------------------------------------------------------------------
/第6章/例6.7/decisfun8.m:
--------------------------------------------------------------------------------
1 | function u=decisfun8(k,x)
2 | u=0:x;
--------------------------------------------------------------------------------
/第6章/例6.7/objfun8.m:
--------------------------------------------------------------------------------
1 | function y=objfun8(v,f)
2 | y=max(v,f);
--------------------------------------------------------------------------------
/第6章/例6.7/subfun8.m:
--------------------------------------------------------------------------------
1 | function v=subfun8(k,x,u,t)
2 | if k==5
3 | v=0;
4 | else
5 | v=u*t(k);
6 | end
7 |
--------------------------------------------------------------------------------
/第6章/例6.7/trafun8.m:
--------------------------------------------------------------------------------
1 | function y=trafun8(k,x,u)
2 | y=x-u;
3 |
--------------------------------------------------------------------------------
/第6章/例6.7/例6.7.txt:
--------------------------------------------------------------------------------
1 | clear
2 | n=500;x1=[n;nan*ones(n,1)];x2=0:n;x3=[0;nan*ones(n,1)];
3 | x=[x1 x2' x2' x2' x3]; t=[0.5;0.1;0.2;0.05];
4 | [y,fval]=dyprog(x,t,@decisfun8,@subfun8,@trafun8,@objfun8);
5 |
--------------------------------------------------------------------------------
/第6章/例6.8/decisfun9.m:
--------------------------------------------------------------------------------
1 | function u=decisfun9(k,x)
2 | if k==5
3 | u=x;
4 | else
5 | u=1:x-1;
6 | end
7 | u=u(:);
--------------------------------------------------------------------------------
/第6章/例6.8/optifun10.m:
--------------------------------------------------------------------------------
1 | function f=optifun10(x)
2 | f=-prod(x(6:10));
--------------------------------------------------------------------------------
/第6章/例6.8/optifun11.m:
--------------------------------------------------------------------------------
1 | function [C,Ceq]=optifun11(x)
2 | C=[];
3 | Ceq=[1-0.1^x(1)-x(6);1-0.2^x(2)-x(7);1-0.5^x(3)-x(8);1-0.3^x(4)-x(9);1-0.4^x(5)-x(10)];
--------------------------------------------------------------------------------
/第6章/例6.8/subfun9.m:
--------------------------------------------------------------------------------
1 | function v=subfun9(k,x,u,c)
2 | v=1-(1-c(k)).^u;
3 | v=-v;
--------------------------------------------------------------------------------
/第6章/例6.8/trafun9.m:
--------------------------------------------------------------------------------
1 | function y=trafun9(k,x,u)
2 | y=x-u;
--------------------------------------------------------------------------------
/第6章/例6.8/例6.8.txt:
--------------------------------------------------------------------------------
1 | clear
2 | n=15; x1=[n;nan*ones(n-1,1)];x2=1:n;x2=x2';x=[x1 x2 x2 x2 x2];c=[0.9 0.8 0.5 0.7 0.6];
3 | [y,fval]=dyprog(x,c,@decisfun9,@subfun9,@trafun9,@objfun9);
4 |
5 |
6 | x1=[3*ones(1,5) 0.5*ones(1,5)]';
7 | Aeq=[ones(1,5) zeros(1,5)];Beq=15;
8 | LB=[ones(1,5) 0.5*ones(1,5)];UB=[10*ones(1,5) ones(1,5)];
9 | options=optimset('Algorithm','sqp','display','off');
10 | [x,fval]=fmincon(@optifun10,x1,[],[],Aeq,Beq,LB,UB,@optifun11,options);
11 | for i=1:5;x(i)=round(x(i));end
12 | x(6)=1-0.1^x(1);x(7)=1-0.2^x(2);x(8)=1-0.5^x(3);x(9)=1-0.3^x(4);x(10)=1-0.4^x(5);
13 | f=x(6)*x(7)*x(8)*x(9)*x(10);
14 |
--------------------------------------------------------------------------------
/第6章/例6.9/dyprogTSP.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.9/dyprogTSP.m
--------------------------------------------------------------------------------
/第6章/例6.9/findpos1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第6章/例6.9/findpos1.m
--------------------------------------------------------------------------------
/第6章/例6.9/例6.9.txt:
--------------------------------------------------------------------------------
1 | clear
2 | d=[0 8 5 6;6 0 8 5;7 9 0 5;9 7 8 0];
3 | [road,f]=dyprogTSP(d);
4 |
--------------------------------------------------------------------------------
/第7章/例7.1/greedy.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.1/greedy.m
--------------------------------------------------------------------------------
/第7章/例7.1/例7.1.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[2 3 4 5];f=[3 4 5 7];b=9;
3 | y=greedy(f,A,b);
4 |
--------------------------------------------------------------------------------
/第7章/例7.2/findeye.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.2/findeye.m
--------------------------------------------------------------------------------
/第7章/例7.2/gomory.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.2/gomory.m
--------------------------------------------------------------------------------
/第7章/例7.2/mydec.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.2/mydec.m
--------------------------------------------------------------------------------
/第7章/例7.2/例7.2.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[-1 1 1 0;24 4 0 1];b=[1;25];c=[-1 -27 0 0];
3 | [x,val]=gomory(A,b,c);
4 |
--------------------------------------------------------------------------------
/第7章/例7.3/例7.3.txt:
--------------------------------------------------------------------------------
1 | clear
2 | f=[-3 -2];A=[2 3;4 2];b=[14;18];Aeq=[];Beq=[];lb=[0;0];ub=[inf;inf];I=[1 2];
3 | [x,val]=intprog(f,A,b,I,Aeq,Beq,lb,ub);
4 |
--------------------------------------------------------------------------------
/第7章/例7.4/例7.4.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | f=[-5 -6 -7 0 0 0 0]; b=[2;0;0;0;60;180];I=[1 2 3 4 5 6 7];
3 | lb=[0;0;0;0;0;0;0];ub=[inf;inf;inf;1;1;1;1];
4 | A=[0 0 0 1 1 1 0;1 0 0 -14 0 0 0;0 1 0 0 -10 0 0;
5 | 0 0 1 0 0 -18 0;3 4 2 0 0 0 -100;4 6 2 0 0 0 100];
6 | [x,val]=intprog(f,A,b,I,[],[],lb,ub);
7 |
--------------------------------------------------------------------------------
/第7章/例7.5/例7.5.txt:
--------------------------------------------------------------------------------
1 | f=[-1.5 -1]; A=[0.3 0.5;0.7 0.2];b=[36;40];I=1;
2 | [x,val,stats]=intprog(f,A,b,I,[],[],[],[]);
3 |
--------------------------------------------------------------------------------
/第7章/例7.6/mybintprog.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.6/mybintprog.m
--------------------------------------------------------------------------------
/第7章/例7.6/mydec2bin.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.6/mydec2bin.m
--------------------------------------------------------------------------------
/第7章/例7.6/例7.6.txt:
--------------------------------------------------------------------------------
1 | clear
2 | f=[-21 -25 -27 -37 -19 -33 -25];
3 | A=[13 18 21 29 11 28 19;1 1 1 0 0 0 0;0 0 0 -1 -1 0 0;0 0 0 0 0 -1 -1];
4 | b=[700;2;-1;-1];
5 | [xmin,val]=mybintprog(f,A,b);
6 |
--------------------------------------------------------------------------------
/第7章/例7.7/Hungarian.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.7/Hungarian.m
--------------------------------------------------------------------------------
/第7章/例7.7/findcount.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.7/findcount.m
--------------------------------------------------------------------------------
/第7章/例7.7/lattice.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第7章/例7.7/lattice.m
--------------------------------------------------------------------------------
/第7章/例7.7/例7.7.txt:
--------------------------------------------------------------------------------
1 | clear
2 | C=[2 15 13 4;10 4 14 15;9 14 16 13;7 8 11 9];
3 | [x,val,C]=Hungarian(C);
4 |
--------------------------------------------------------------------------------
/第7章/例7.8/例7.8.txt:
--------------------------------------------------------------------------------
1 | C=[7 5 9 8 11;9 12 7 11 9;8 5 4 6 9;7 3 6 9 6;4 6 7 5 11];
2 | [x,val,C]=Hungarian(C);
3 |
--------------------------------------------------------------------------------
/第7章/例7.9/例7.9.txt:
--------------------------------------------------------------------------------
1 | clear
2 | f=[7 5 6 8 9];A=[-3 1 -1 -1 2;-1 -3 1 2 -1;1 1 -3 -1 -1];b=[-2;0;1];
3 | [x,val]=bintprog(f,A,b);
4 |
--------------------------------------------------------------------------------
/第8章/例8.1/myquad.asv:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第8章/例8.1/myquad.asv
--------------------------------------------------------------------------------
/第8章/例8.1/myquad.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第8章/例8.1/myquad.m
--------------------------------------------------------------------------------
/第8章/例8.1/例8.1.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | H=[3 -1 0;-1 2 -1;0 -1 1];
3 | c=[1;1;1];
4 | A=[1 2 1];
5 | b=4;
6 | [x,lamda,minf]=myquad(H,c,A,b)
--------------------------------------------------------------------------------
/第8章/例8.2/myquad1.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第8章/例8.2/myquad1.m
--------------------------------------------------------------------------------
/第8章/例8.2/例8.2.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第8章/例8.2/例8.2.txt
--------------------------------------------------------------------------------
/第8章/例8.3/newquad.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第8章/例8.3/newquad.m
--------------------------------------------------------------------------------
/第8章/例8.3/例8.3.txt:
--------------------------------------------------------------------------------
1 | clear
2 | c=[-2 0 0 0]';
3 | H=[2 -2 0 0;-2 2 0 0;0 0 0 0;0 0 0 0];
4 | Ae=[1 1 1 0;1 5 0 1];
5 | be=[3 6]';
6 | Ai=eye(4);
7 | bi=[0 0 0 0];
8 | [xmin,minf,mu,lm]=newquad(H,c,Ae,be,Ai,bi);
9 |
--------------------------------------------------------------------------------
/第8章/例8.4/例8.4.txt:
--------------------------------------------------------------------------------
1 | H=[1 -1;-1 2];f=[-2;-6];A=[1 1;-1 2;2 1];b=[2;2;3];lb=zeros(2,1);
2 | options=optimset('Largescale','off');
3 | [x,fval]=quadprog(H,f,A,b,[],[],lb,[],[],options);
4 |
--------------------------------------------------------------------------------
/第9章/例9.1/例9.1.txt:
--------------------------------------------------------------------------------
1 | clear
2 | syms x1 x2
3 | x_syms=[sym(x1) sym(x2)];
4 | fun=0.3*x1*x2+0.7*x1^2+0.7*x2^2;
5 | gfun=[2.5-x1;x1-x2;x1;x2;x1^2*x2-1;4*x2-x1];hfun=[];x0=[1 1];
6 | [xmin,minf]=newsqp1(fun,hfun,gfun,x0,x_syms);
7 |
--------------------------------------------------------------------------------
/第9章/例9.2/例9.2.txt:
--------------------------------------------------------------------------------
1 | clear;
2 | syms x1 x2 x3
3 | fun=x1+x2+x3-208;
4 | gfun=[240-3*x1;250-2*x2;420-4*x3;x1+x2+x3-208;x1;x2;x3];
5 | hfun=[];x0=[1 1 1];x_syms=[sym(x1) sym(x2) sym(x3)];
6 | [xmin1,minf1]=newsqp1(fun,hfun,gfun,x0,x_syms);
7 |
8 | fun=-15*x1-14*x2-12*x3;
9 | [xmin2,minf2]=newsqp1(fun,hfun,gfun,x0,x_syms);
10 |
11 | fun=-3*x1;
12 | [xmin3,minf3]=newsqp1(fun,hfun,gfun,x0,x_syms);
13 |
14 | A=[0.1 0.1 0.1 -1;-15*0.8 -14*0.8 -12*0.8 -1;-0.3 0 0 -1;3 0 0 0;0 2 0 0;0 0 4 0;-1 -1 -1 0];
15 | B=[20.8;-4210*0.8;-24;240;250;420;-208];f=[0 0 0 1];LB=[0;0;0;0];
16 | [x,val]=linprog(f,A,B,[],[],LB,[]);
17 |
18 |
--------------------------------------------------------------------------------
/第9章/例9.3/例9.3.txt:
--------------------------------------------------------------------------------
1 | A=[320 350 390;0 0 -130];b=[3410;-156];Aeq=[1 1 1];beq=10;
2 | options=optimset('Algorithm','sqp','display','off');
3 | [x,fval]=fmincon(@(x)-34*x(1)-32*x(2)-34*x(3),[1 1 1],A,b,Aeq,beq,[0;0;0],[],[],options);
4 |
5 | A=[320 350 390;0 0 -130;-34 -32 -34];
6 | b=[3410;-156;-340];
7 | [x,fval]=fmincon(@(x) 50*x(1)+48*x(2)+40*x(3),[1 1 1],A,b,Aeq,beq,[0;0;0],[],[],options);
8 |
9 |
--------------------------------------------------------------------------------
/第9章/例9.4/例9.4.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第9章/例9.4/例9.4.txt
--------------------------------------------------------------------------------
/第9章/例9.5/例9.5.txt:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第9章/例9.5/例9.5.txt
--------------------------------------------------------------------------------
/第9章/例9.6/findeye.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第9章/例9.6/findeye.m
--------------------------------------------------------------------------------
/第9章/例9.6/multgoal.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第9章/例9.6/multgoal.m
--------------------------------------------------------------------------------
/第9章/例9.6/progturn.m:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cggos/opt_matlab/4989cbf2e93c9b577235dee61c9d6ca2a947d490/第9章/例9.6/progturn.m
--------------------------------------------------------------------------------
/第9章/例9.6/例9.6.txt:
--------------------------------------------------------------------------------
1 | clear
2 | A=[4 5 -1 1 0 0 0 0 0 0;4 2 0 0 -1 1 0 0 0 0;80 100 0 0 0 0 -1 1 0 0;1 1 0 0 0 0 0 0 -1 1];
3 | b=[80;48;800;7];
4 | f=[0 0 1 0 1 0 0 0 0 0;0 0 0 0 0 0 0 1 0 0;0 0 0 0 0 0 0 0 0 1];
5 | minx=multgoal(f,A,b);
6 |
--------------------------------------------------------------------------------
/第9章/例9.7/例9.7.txt:
--------------------------------------------------------------------------------
1 | clear
2 | goal=[200 -100 -50];weight=[2040 -100 50];x0=[60 60];
3 | A=[2 1;-1 -1;-1 0];b=[200 -100 -50];lb=zeros(2,1);
4 | [x,fval]=fgoalattain(@optifun12,x0,goal,weight,A,b,[],[],lb,[]);
5 |
--------------------------------------------------------------------------------