MATLAB优化工具.docx

上传人:b****5 文档编号:8050414 上传时间:2023-01-28 格式:DOCX 页数:17 大小:32.96KB
下载 相关 举报
MATLAB优化工具.docx_第1页
第1页 / 共17页
MATLAB优化工具.docx_第2页
第2页 / 共17页
MATLAB优化工具.docx_第3页
第3页 / 共17页
MATLAB优化工具.docx_第4页
第4页 / 共17页
MATLAB优化工具.docx_第5页
第5页 / 共17页
点击查看更多>>
下载资源
资源描述

MATLAB优化工具.docx

《MATLAB优化工具.docx》由会员分享,可在线阅读,更多相关《MATLAB优化工具.docx(17页珍藏版)》请在冰豆网上搜索。

MATLAB优化工具.docx

MATLAB优化工具

Findminimumofconstrainednonlinearmultivariablefunction

EquationFindstheminimumofaproblemspecifiedby

bandbeqarevectors,AandAeqarematrices,c(x)andceq(x)arefunctionsthatreturnvectors,andf(x)isafunctionthatreturnsascalar.f(x),c(x),andceq(x)canbenonlinearfunctions

.x,lb,andubcanbepassedasvectorsormatrices;seeMatrixArguments.

Syntax

x=fmincon(fun,x0,A,b)

x=fmincon(fun,x0,A,b,Aeq,beq)

x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub)

x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)

x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)

x=fmincon(problem)

[x,fval]=fmincon(...)

[x,fval,exitflag]=fmincon(...)

[x,fval,exitflag,output]=fmincon(...)

[x,fval,exitflag,output,lambda]=fmincon(...)

[x,fval,exitflag,output,lambda,grad]=fmincon(...)

[x,fval,exitflag,output,lambda,grad,hessian]=fmincon(...)

Descriptionfminconattemptstofindaconstrainedminimumofascalarfunctionofseveralvariablesstartingataninitialestimate.Thisisgenerallyreferredtoasconstrainednonlinearoptimizationornonlinearprogramming.

Note:

  

PassingExtraParametersexplainshowtopassextraparameterstotheobjectivefunctionandnonlinearconstraintfunctions,ifnecessary.

x=fmincon(fun,x0,A,b)startsatx0andattemptstofindaminimizerxofthefunctiondescribedinfunsubjecttothelinear

inequalitiesA*x ≤ b.x0can

beascalar,vector,ormatrix.x=fmincon(fun,x0,A,b,Aeq,beq)minimizesfunsubject

tothelinearequalitiesAeq*x = beqandA*x ≤ b.Ifnoinequalities

exist,setA=[]andb=[].x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub)defines

asetoflowerandupperboundsonthedesignvariablesinx,

sothatthesolutionisalwaysintherangelb ≤ x ≤ ub.

Ifnoequalitiesexist,setAeq=[]andbeq

=[].Ifx(i)isunboundedbelow,setlb(i)

=-Inf,andifx(i)isunboundedabove,

setub(i)=Inf.Note:

  

 

Ifthespecifiedinputboundsforaproblemareinconsistent,

theoutputxisx0andtheoutputfvalis[].Componentsofx0thatviolatetheboundslb ≤ x ≤ ubareresettotheinterioroftheboxdefined

bythebounds.Componentsthatrespecttheboundsarenotchanged.SeeIterationsCanViolateConstraints.x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon)subjects

theminimizationtothenonlinearinequalitiesc(x)or

equalitiesceq(x)definedinnonlcon.fminconoptimizes

suchthatc(x) ≤ 0andceq(x) = 0.Ifnoboundsexist,setlb

=[]and/orub=[].x=fmincon(fun,x0,A,b,Aeq,beq,lb,ub,nonlcon,options)minimizes

withtheoptimizationoptionsspecifiedinoptions.

Useoptimoptionstosetthese

options.Iftherearenononlinearinequalityorequalityconstraints,

setnonlcon=[].x=fmincon(problem)findstheminimum

forproblem,whereproblemis

astructuredescribedinInputArguments.CreatetheproblemstructurebyexportingaproblemfromOptimizationapp,asdescribedinExportingYourWork.

[x,fval]=fmincon(...)returnsthevalueoftheobjectivefunctionfunatthesolutionx.

[x,fval,exitflag]=fmincon(...)returnsavalueexitflagthatdescribestheexitconditionoffmincon.

[x,fval,exitflag,output]=fmincon(...)returnsastructureoutputwithinformationabouttheoptimization.

[x,fval,exitflag,output,lambda]=fmincon(...)returnsastructurelambdawhosefieldscontaintheLagrangemultipliersatthesolutionx.

[x,fval,exitflag,output,lambda,grad]=fmincon(...)returnsthevalueofthegradientoffunatthesolutionx.

[x,fval,exitflag,output,lambda,grad,hessian]=fmincon(...)returnsthevalueoftheHessianatthesolutionx.SeefminconHessian.

InputArguments

FunctionArgumentsdescribestheargumentspassedtofmincon.Optionsprovidesthefunction-specificdetailsfortheoptionsvalues.Thissectionprovidesfunction-specificdetailsforfun,nonlcon,andproblem.

Fun

Thefunctiontobeminimized.funisafunctionthatacceptsavectorxandreturnsascalarf,theobjectivefunctionevaluatedatx.funcanbespecifiedasafunctionhandleforafile:

x=fmincon(@myfun,x0,A,b)wheremyfunisaMATLAB®functionsuchas

functionf=myfun(x)

f=...%Computefunctionvalueatx

funcanalsobeafunctionhandleforananonymous

function:

x=fmincon(@(x)norm(x)^2,x0,A,b);

IfthegradientoffuncanalsobecomputedandtheGradObjoptionis'on',assetby

options=optimoptions('fmincon','GradObj','on')

thenfunmustreturnthegradientvectorg(x)inthesecondoutputargument.IftheHessianmatrixcanalsobecomputedandtheHessianoptionis'on'viaoptions = optimoptions('fmincon','Hessian','user-supplied')andtheAlgorithmoptionistrust-region-reflective,funmustreturntheHessianvalueH(x),asymmetricmatrix,inathirdoutputargument.funcangiveasparseHessian.SeeWritingObjectiveFunctionsfordetails.

IftheHessianmatrixcanbecomputedandtheAlgorithmoptionisinterior-point,thereareseveralwaystopasstheHessiantofmincon.Formoreinformation,seeHessian.

A,b,Aeq,beq

LinearconstraintmatricesAandAeq,andtheircorrespondingvectorsbandbeq,canbesparseordense.Thetrust-region-reflectiveandinterior-pointalgorithmsusesparselinearalgebra.IfAorAeqislarge,withrelativelyfewnonzeroentries,saverunningtimeandmemoryinthetrust-region-reflectiveorinterior-pointalgorithmsbyusingsparsematrices.

Nonlcon

Thefunctionthatcomputesthenonlinearinequalityconstraintsc(x)≤0andthenonlinearequalityconstraintsceq(x)=0.nonlconacceptsavectorxandreturnsthetwovectorscandceq.cisavectorthatcontainsthenonlinearinequalitiesevaluatedatx,andceqisavectorthatcontainsthenonlinearequalitiesevaluatedatx.nonlconshouldbespecifiedasafunctionhandletoafileortoananonymousfunction,suchasmycon:

x=fmincon(@myfun,x0,A,b,Aeq,beq,lb,ub,@mycon)

wheremyconisaMATLABfunctionsuchas

function[c,ceq]=mycon(x)

c=...%Computenonlinearinequalitiesatx.

ceq=...%Computenonlinearequalitiesatx.

IfthegradientsoftheconstraintscanalsobecomputedandtheGradConstroptionis'on',assetbyoptions=optimoptions('fmincon','GradConstr','on')thennonlconmustalsoreturn,inthethirdandfourthoutputarguments,GC,thegradientofc(x),andGCeq,thegradientofceq(x).GCandGCeqcanbesparseordense.IfGCorGCeqislarge,withrelativelyfewnonzeroentries,saverunningtimeandmemoryintheinterior-pointalgorithmbyrepresentingthemassparsematrices.Formoreinformation,seeNonlinearConstraints.

Note  BecauseOptimizationToolbox™functionsonlyacceptinputsoftypedouble,user-suppliedobjectiveandnonlinearconstraintfunctionsmustreturnoutputsoftypedouble. 

Problem

objectiveObjectivefunction 

x0Initialpointforx 

AineqMatrixforlinearinequalityconstraints 

bineqVectorforlinearinequalityconstraints 

AeqMatrixforlinearequalityconstraints 

beqVectorforlinearequalityconstraints 

lbVectoroflowerbounds 

ubVectorofupperbounds 

nonlconNonlinearconstraintfunction 

solver'fmincon' 

optionsOptionscreatedwithoptimoptions 

OutputArgumentsFunctionArgumentsdescribesargumentsreturnedbyfmincon.Thissectionprovidesfunction-specificdetailsforexitflag,lambda,andoutput:

Exitflag

Integeridentifyingthereasonthealgorithmterminated.Thefollowingliststhevaluesofexitflagandthecorrespondingreasonsthealgorithmterminated.

AllAlgorithms:

1First-orderoptimalitymeasurewaslessthanoptions.TolFun,andmaximumconstraintviolationwaslessthanoptions.TolCon.

0Numberofiterationsexceededoptions.MaxIterornumberoffunctionevaluationsexceededoptions.MaxFunEvals.

-1Stoppedbyanoutputfunctionorplotfunction.

-2Nofeasiblepointwasfound.

trust-region-reflective,interior-point,andsqpalgorithms:

2Changeinxwaslessthanoptions.TolXandmaximumconstraintviolationwaslessthanoptions.TolCon.

trust-region-reflectivealgorithmonly:

3Changeintheobjectivefunctionvaluewaslessthanoptions.TolFunandmaximumconstraintviolationwaslessthanoptions.TolCon.

active-setalgorithmonly:

4Magnitudeofthesearchdirectionwaslessthan2*options.TolXandmaximumconstraintviolationwaslessthanoptions.TolCon.

5Magnitudeofdirectionalderivativeinsearchdirectionwaslessthan2*options.TolFunandmaximumconstraintviolationwaslessthanoptions.TolCon.

interior-pointandsqpalgorithms:

-3Objectivefunctionatcurrentiterationwentbelowoptions.ObjectiveLimitandmaximumconstraintviolationwaslessthanoptions.TolCon.

GradGradientatx 

HessianHessianatx 

LambdaStructurecontainingtheLagrangemultipliersatthesolutionx(separatedbyconstrainttype).Thefieldsofthestructureare:

LowerLowerboundslb

UpperUpperboundsub

IneqlinLinearinequalities

eqlinLinearequalities

ineqnonlinNonlinearinequalities

eqnonlinNonlinearequalities

outputStructurecontaininginformationabouttheoptimization.Thefieldsofthestructureare:

iterationsNumberofiterationstaken

funcCountNumberoffunctionevaluations

lssteplengthSizeoflinesearchsteprelativetosearchdirection(active-setalgorithmonly)

constrviolationMaximumofconstraintfunctions

stepsizeLengthoflastdisplacementinx(active-setandinterior-pointalgorithms)

algorithmOptimizationalgorithmused

cgiterationsTotalnumberofPCGiterations(trust-region-reflectiveandinterior-pointalgorithms)

firstorderoptMeasureoffirst-orderoptimality

messageExitmessage

Hessian

fminconusesaHessianasanoptionalinput.ThisHessianisthesecondderivativesoftheLagrangian(seeEquation 3-1),namely,

ThevariousfminconalgorithmshandleinputHessiansdifferently:

Theactive-setandsqpalgorithmsdonotacceptauser-suppliedHessian.Theycomputeaquasi-Newtonap

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 工作范文 > 行政公文

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1