数学建模多目标规划函数fgoalattain
Matlab数学规划问题
MATLAB数学规划问题1. 线性规划线性规划问题是目标函数和约束条件均为线性函数的问题,MATLAB6.0解决的线性规划问题的标准形式为:',min n Rf∈xxsub.to:b⋅xA≤A e q=⋅xb e q≤lb≤xub其中f、x、b、beq、lb、ub为向量,A、Aeq为矩阵。
其它形式的线性规划问题都可经过适当变换化为此标准形式。
在MATLAB6.0版中,线性规划问题(Linear Programming)已用函数linprog 取代了MATLAB5.x版中的lp函数。
当然,由于版本的向下兼容性,一般说来,低版本中的函数在6.0版中仍可使用。
函数linprog调用格式:x=linprog(f,A,b)x=linprog(f,A,b,Aeq,beq)x=linprog(f,A,b,Aeq,beq,lb,ub)x=linprog(f,A,b,Aeq,beq,lb,ub,x0)x=linprog(f,A,b,Aeq,beq,lb,ub,x0,options)[x,fval]=linprog(…)[x, fval, exitflag]=linprog(…)[x, fval, exitflag, output]=linprog(…)[x, fval, exitflag, output, lambda]=linprog(…)说明:x=linprog(f, A, b)%求min f ' *x, sub.to bA≤⋅线性规划的最优解。
返回值xx为最优解向量。
x=linprog(f, A, b, Aeq, beq) %含有等式约束beq⋅,若没有不等式约Aeq=x束b⋅,则令A=[ ],b=[ ]。
A≤xx = linprog(f, A, b, Aeq, beq, lb, ub) %指定x的范围ub≤lb≤xx=linprog(f, A, b, Aeq, beq, lb, ub, x0) %设置x0为初值点。
matlab多目标优化模型教程
fgoalattainSolve multiobjective goal attainment problemsEquationFinds the minimum of a problem specified byx, weight, goal, b, beq, lb, and ub are vectors, A and Aeq are matrices, and c(x), ceq(x), and F(x) are functions that return vectors. F(x), c(x), and ceq(x) can be nonlinear functions.Syntaxx = fgoalattain(fun,x0,goal,weight)x = fgoalattain(fun,x0,goal,weight,A,b)x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq)x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub)x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon)x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon,... options)x = fgoalattain(problem)[x,fval] = fgoalattain(...)[x,fval,attainfactor] = fgoalattain(...)[x,fval,attainfactor,exitflag] = fgoalattain(...)[x,fval,attainfactor,exitflag,output] = fgoalattain(...)[x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(...)Descriptionfgoalattain solves the goal attainment problem, which is one formulation for minimizing a multiobjective optimization problem.x = fgoalattain(fun,x0,goal,weight) tries to make the objective functions supplied by fun attain the goals specified by goal by varying x, starting at x0, with weight specified by weight.x = fgoalattain(fun,x0,goal,weight,A,b) solves the goal attainment problem subject to the linear inequalities A*x ≤ b.x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq) solves the goal attainment problem subject to the linear equalities Aeq*x = beq as well. Set A = [] and b = [] if no inequalities exist.x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub) defines a set of lower and upper bounds on the design variables in x, so that the solution is always in the range lb ≤ x ≤ ub.x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon) subjects the goal attainment problem to the nonlinear inequalities c(x) or nonlinear equality constraints ceq(x) defined in nonlcon. fgoalattain optimizes such that c(x) ≤ 0 and ceq(x) = 0. Set lb = [] and/or ub = [] if no bounds exist.x = fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon,... options) minimizes with the optimization options specified in the structure options. Use optimset to set these options.x = fgoalattain(problem) finds the minimum for problem, where problem is a structure described in Input Arguments.Create the structure problem by exporting a problem from Optimization Tool, as described in Exporting to the MATLAB Workspace.[x,fval] = fgoalattain(...) returns the values of the objective functions computed in fun at the solution x.[x,fval,attainfactor] = fgoalattain(...) returns the attainment factor at the solution x.[x,fval,attainfactor,exitflag] = fgoalattain(...) returns a value exitflag that describes the exit condition of fgoalattain.[x,fval,attainfactor,exitflag,output] = fgoalattain(...) returns a structure output that contains information about the optimization.[x,fval,attainfactor,exitflag,output,lambda] = fgoalattain(...) returns a structure lambda whose fields contain the Lagrange multipliers at the solution x.Input ArgumentsFunction Arguments contains general descriptions of arguments passed into fgoalattain. This section provides function-specific details for fun, goal, nonlcon, options, weight, and problem:fun The function to be minimized. fun is a function that acceptsa vector x and returns a vector F, the objective functionsevaluated at x. The function fun can be specified as a functionhandle for a function file:x = fgoalattain(@myfun,x0,goal,weight)where myfun is a MATLAB function such asfunction F = myfun(x)F = ... % Compute function values at x.fun can also be a function handle for an anonymous function.x = fgoalattain(@(x)sin(x.*x),x0,goal,weight);If the user-defined values for x and F are matrices, they areconverted to a vector using linear indexing.To make an objective function as near as possible to a goalvalue, (i.e., neither greater than nor less than) use optimsetto set the GoalsExactAchieve option to the number of objectivesrequired to be in the neighborhood of the goal values. Suchobjectives must be partitioned into the first elements of thevector F returned by fun.If the gradient of the objective function can also be computedand the GradObj option is 'on', as set byoptions = optimset('GradObj','on')then the function fun must return, in the second outputargument, the gradient value G, a matrix, at x. The gradientconsists of the partial derivative dF/dx of each F at the pointx. If F is a vector of length m and x has length n, where n isthe length of x0, then the gradient G of F(x) is an n-by-m matrixwhere G(i,j) is the partial derivative of F(j) with respect tox(i) (i.e., the jth column of G is the gradient of the jthobjective function F(j)).goal Vector of values that the objectives attempt to attain. The vector is the same length as the number of objectives F returnedby fun. fgoalattain attempts to minimize the values in thevector F to attain the goal values given by goal.nonlcon The function that computes the nonlinear inequality constraints c(x) ≤ 0 and the nonlinear equality constraintsceq(x) = 0. The function nonlcon accepts a vector x and returnstwo vectors c and ceq. The vector c contains the nonlinearinequalities evaluated at x, and ceq contains the nonlinearequalities evaluated at x. The function nonlcon can bespecified as a function handle.x = fgoalattain(@myfun,x0,goal,weight,A,b,Aeq,beq,...lb,ub,@mycon)where mycon is a MATLAB function such asfunction [c,ceq] = mycon(x)c = ... % compute nonlinear inequalities at x.ceq = ... % compute nonlinear equalities at x.If the gradients of the constraints can also be computed andthe GradConstr option is 'on', as set byoptions = optimset('GradConstr','on')then the function nonlcon must also return, in the third andfourth output arguments, GC, the gradient of c(x), and GCeq,the gradient of ceq(x). Nonlinear Constraints explains how to"conditionalize" the gradients for use in solvers that do notaccept supplied gradients.If nonlcon returns a vector c of m components and x has lengthn, where n is the length of x0, then the gradient GC of c(x)is an n-by-m matrix, where GC(i,j) is the partial derivativeof c(j) with respect to x(i) (i.e., the jth column of GC is thegradient of the jth inequality constraint c(j)). Likewise, ifceq has p components, the gradient GCeq of ceq(x) is an n-by-pmatrix, where GCeq(i,j) is the partial derivative of ceq(j)with respect to x(i) (i.e., the jth column of GCeq is thegradient of the jth equality constraint ceq(j)).Passing Extra Parameters explains how to parameterize thenonlinear constraint function nonlcon, if necessary.options Options provides the function-specific details for the options values.weight A weighting vector to control the relative underattainment or overattainment of the objectives in fgoalattain. When thevalues of goal are all nonzero, to ensure the same percentageof under- or overattainment of the active objectives, set theweighting function to abs(goal). (The active objectives are theset of objectives that are barriers to further improvement ofthe goals at the solution.)When the weighting function weight is positive, fgoalattainattempts to make the objectives less than the goal values. Tomake the objective functions greater than the goal values, setweight to be negative rather than positive. To make an objectivefunction as near as possible to a goal value, use theGoalsExactAchieve option and put that objective as the firstelement of the vector returned by fun (see the precedingdescription of fun and options).problem objective Vector of objective functionsx0 Initial point for xgoal Goals to attainweight Relative importance factors of goalsAineq Matrix for linear inequality constraintsbineq Vector for linear inequality constraintsAeq Matrix for linear equality constraintsbeq Vector for linear equality constraintslb Vector of lower boundsub Vector of upper boundsnonlcon Nonlinear constraint functionsolver 'fgoalattain'options Options structure created with optimset Output ArgumentsFunction Arguments contains general descriptions of arguments returned by fgoalattain. This section provides function-specific details for attainfactor, exitflag, lambda, and output:attainfactor The amount of over- or underachievement of the goals. If attainfactor is negative, the goals have been overachieved;if attainfactor is positive, the goals have beenunderachieved.attainfactor contains the value of γ at the solution. Anegative value of γindicates overattainment in the goals.exitflag Integer identifying the reason the algorithm terminated.The following lists the values of exitflag and thecorresponding reasons the algorithm terminated.1 Function converged to a solutions x.4 Magnitude of the search direction lessthan the specified tolerance andconstraint violation less thanoptions.TolCon5 Magnitude of directional derivative lessthan the specified tolerance andconstraint violation less thanoptions.TolCon0 Number of iterations exceededoptions.MaxIter or number of functionevaluations exceeded options.FunEvals-1 Algorithm was terminated by the outputfunction.-2 No feasible point was found.lambda Structure containing the Lagrange multipliers at the solution x (separated by constraint type). The fields of thestructure arelower Lower bounds lbupper Upper bounds ubineqlin Linear inequalitieseqlin Linear equalitiesineqnonlin Nonlinear inequalitieseqnonlin Nonlinear equalitiesoutput Structure containing information about the optimization.The fields of the structure areiterations Number of iterations takenfuncCount Number of function evaluationslssteplength Size of line search step relative tosearch directionstepsize Final displacement in xalgorithm Optimization algorithm usedfirstorderopt Measure of first-order optimalityconstrviolation Maximum of constraint functionsmessage Exit messageOptionsOptimization options used by fgoalattain. You can use optimset to set or change the values of these fields in the options structure options. See Optimization Options for detailed information.DerivativeCheck Compare user-supplied derivatives (gradients ofobjective or constraints) to finite-differencingderivatives. The choices are 'on' or the default,'off'.Diagnostics Display diagnostic information about the functionto be minimized or solved. The choices are 'on' orthe default, 'off'.DiffMaxChange Maximum change in variables for finite-differencegradients (a positive scalar). The default is 0.1.DiffMinChange Minimum change in variables for finite-differencegradients (a positive scalar). The default is 1e-8. Display Level of display.∙'off' displays no output.∙'iter' displays output at each iteration, andgives the default exit message.∙'iter-detailed' displays output at eachiteration, and gives the technical exitmessage.∙'notify' displays output only if the functiondoes not converge, and gives the default exitmessage.∙'notify-detailed' displays output only if thefunction does not converge, and gives thetechnical exit message.∙'final' (default) displays just the finaloutput, and gives the default exit message.∙'final-detailed' displays just the finaloutput, and gives the technical exit message.FinDiffType Finite differences, used to estimate gradients, areeither 'forward' (default), or 'central'(centered). 'central' takes twice as many functionevaluations, but should be more accurate.The algorithm is careful to obey bounds whenestimating both types of finite differences. So, forexample, it could take a backward, rather than aforward, difference to avoid evaluating at a pointoutside bounds.FunValCheck Check whether objective function and constraintsvalues are valid. 'on' displays an error when theobjective function or constraints return a valuethat is complex, Inf, or NaN. The default, 'off',displays no error.GoalsExactAchieve Specifies the number of objectives for which it isrequired for the objective fun to equal the goal goal(a nonnegative integer). Such objectives should bepartitioned into the first few elements of F. Thedefault is 0.GradConstr Gradient for nonlinear constraint functions definedby the user. When set to 'on', fgoalattain expectsthe constraint function to have four outputs, asdescribed in nonlcon in the Input Arguments section.When set to the default, 'off', gradients of thenonlinear constraints are estimated by finitedifferences.GradObj Gradient for the objective function defined by theuser. See the preceding description of fun to seehow to define the gradient in fun. Set to 'on' tohave fgoalattain use a user-defined gradient of theobjective function. The default, 'off',causesfgoalattain to estimate gradients usingfinite differences.MaxFunEvals Maximum number of function evaluations allowed (apositive integer). The default is100*numberOfVariables.MaxIter Maximum number of iterations allowed (a positiveinteger). The default is 400.MaxSQPIter Maximum number of SQP iterations allowed (a positiveinteger). The default is 10*max(numberOfVariables,numberOfInequalities + numberOfBounds)MeritFunction Use goal attainment/minimax merit function if setto 'multiobj', the default. Use fmincon meritfunction if set to 'singleobj'.OutputFcn Specify one or more user-defined functions that anoptimization function calls at each iteration,either as a function handle or as a cell array offunction handles. The default is none ([]). SeeOutput Function.PlotFcns Plots various measures of progress while thealgorithm executes, select from predefined plots orwrite your own. Pass a function handle or a cellarray of function handles. The default is none ([]).∙@optimplotx plots the current point∙@optimplotfunccount plots the function count∙@optimplotfval plots the function value∙@optimplotconstrviolation plots the maximumconstraint violation∙@optimplotstepsize plots the step sizeFor information on writing a custom plot function,see Plot Functions.RelLineSrchBnd Relative bound (a real nonnegative scalar value) onthe line search step length such that the totaldisplacement in x satisfies|Δx(i)| ≤relLineSrchBnd· max(|x(i)|,|typicalx(i)|). This option provides control over themagnitude of the displacements in x for cases inwhich the solver takes steps that are considered toolarge. The default is none ([]).RelLineSrchBndDurat ion Number of iterations for which the bound specified in RelLineSrchBnd should be active (default is 1).TolCon Termination tolerance on the constraint violation,a positive scalar. The default is 1e-6.TolConSQP Termination tolerance on inner iteration SQPconstraint violation, a positive scalar. Thedefault is 1e-6.TolFun Termination tolerance on the function value, apositive scalar. The default is 1e-6.TolX Termination tolerance on x, a positive scalar. Thedefault is 1e-6.TypicalX Typical x values. The number of elements in TypicalXis equal to the number of elements in x0, thestarting point. The default value isones(numberofvariables,1). fgoalattain usesTypicalX for scaling finite differences forgradient estimation.UseParallel When 'always', estimate gradients in parallel.Disable by setting to the default, 'never'. ExamplesConsider a linear system of differential equations.An output feedback controller, K, is designed producing a closed loop systemThe eigenvalues of the closed loop system are determined from the matrices A, B, C, and K using the command eig(A+B*K*C). Closed loop eigenvalues must lie on the real axis in the complex plane to the left of the points [-5,-3,-1]. In order not to saturate the inputs, no element in K can be greater than 4 or be less than -4.The system is a two-input, two-output, open loop, unstable system, with state-space matrices.The set of goal values for the closed loop eigenvalues is initialized as goal = [-5,-3,-1];To ensure the same percentage of under- or overattainment in the active objectives at the solution, the weighting matrix, weight, is set to abs(goal).Starting with a controller, K = [-1,-1; -1,-1], first write a function file, eigfun.m.function F = eigfun(K,A,B,C)F = sort(eig(A+B*K*C)); % Evaluate objectivesNext, enter system matrices and invoke an optimization routine.A = [-0.5 0 0; 0 -2 10; 0 1 -2];B = [1 0; -2 2; 0 1];C = [1 0 0; 0 0 1];K0 = [-1 -1; -1 -1]; % Initialize controller matrixgoal = [-5 -3 -1]; % Set goal values for the eigenvalues weight = abs(goal); % Set weight for same percentagelb = -4*ones(size(K0)); % Set lower bounds on the controllerub = 4*ones(size(K0)); % Set upper bounds on the controller options = optimset('Display','iter'); % Set display parameter[K,fval,attainfactor] = fgoalattain(@(K)eigfun(K,A,B,C),...K0,goal,weight,[],[],[],[],lb,ub,[],options)You can run this example by using the demonstration script goaldemo. (From the MATLAB Help browser or the MathWorks™ Web site documentation, you can click the demo name to display the demo.) After about 11 iterations, a solution isActive inequalities (to within options.TolCon = 1e-006):lower upper ineqlinineqnonlin1 12 24K =-4.0000 -0.2564-4.0000 -4.0000fval =-6.9313-4.1588-1.4099attainfactor =-0.3863DiscussionThe attainment factor indicates that each of the objectives has been overachieved by at least 38.63% over the original design goals. The active constraints, in this case constraints 1 and 2, are the objectives that are barriers to further improvement and for which the percentage of overattainment is met exactly. Three of the lower bound constraints are also active.In the preceding design, the optimizer tries to make the objectives less than the goals. For a worst-case problem where the objectives must be as near to the goals as possible, use optimset to set the GoalsExactAchieve option to the number of objectives for which this is required.Consider the preceding problem when you want all the eigenvalues to be equal to the goal values. A solution to this problem is found by invoking fgoalattain with the GoalsExactAchieve option set to 3.options = optimset('GoalsExactAchieve',3);[K,fval,attainfactor] = fgoalattain(...@(K)eigfun(K,A,B,C),K0,goal,weight,[],[],[],[],lb,ub,[],... options)After about seven iterations, a solution isK =-1.5954 1.2040-0.4201 -2.9046fval =-5.0000-3.0000-1.0000attainfactor =1.0859e-20In this case the optimizer has tried to match the objectives to the goals. The attainment factor (of 1.0859e-20) indicates that the goals have been matched almost exactly.NotesThis problem has discontinuities when the eigenvalues become complex; this explains why the convergence is slow. Although the underlying methods assume the functions are continuous, the method is able to make stepstoward the solution because the discontinuities do not occur at the solution point. When the objectives and goals are complex, fgoalattain tries to achieve the goals in a least-squares sense.AlgorithmMultiobjective optimization concerns the minimization of a set of objectives simultaneously. One formulation for this problem, and implemented in fgoalattain, is the goal attainment problem of Gembicki[3]. This entails the construction of a set of goal values for the objective functions. Multiobjective optimization is discussed in Multiobjective Optimization.In this implementation, the slack variable γis used as a dummy argument to minimize the vector of objectives F(x) simultaneously; goal is a set of values that the objectives attain. Generally, prior to the optimization, it is not known whether the objectives will reach the goals (under attainment) or be minimized less than the goals (overattainment). A weighting vector, weight, controls the relative underattainment or overattainment of the objectives.fgoalattain uses a sequential quadratic programming (SQP) method, which is described in Sequential Quadratic Programming (SQP). Modifications are made to the line search and Hessian. In the line search an exact merit function (see [1] and [4]) is used together with the merit function proposed by [5]and [6]. The line search is terminated when either merit function shows improvement. A modified Hessian, which takes advantage of the special structure of the problem, is also used (see [1] and [4]). A full description of the modifications used is found in Goal Attainment Method in "Introduction to Algorithms." Setting the MeritFunction option to 'singleobj' withoptions = optimset(options,'MeritFunction','singleobj')uses the merit function and Hessian used in fmincon.See also SQP Implementation for more details on the algorithm used and the types of procedures displayed under the Procedures heading when the Display option is set to 'iter'.LimitationsThe objectives must be continuous. fgoalattain might give only local solutions.。
数学建模培训多目标规划
例题 某工厂在一个计划期内生产甲、乙两种产品, 各产品都要消耗A,B,C三种不同的资源。每件产品 对资源的单位消耗、各种资源的限量以及各产品的 单位价格、单位利润和所造成的单位污染如下表。 假定产品能全部销售出去,问每期怎样安排生产, 才能使利润和产值都最大,且造成的污染最小?
甲 9 4 3 400 乙 4 5 10 600 资源限量 240 200 300
2.0 2.5
f2
1500 2700
f3
4 3.6
f4
55 65
f5
一般 低
f6
高 一般
2.0
2.2
2000
1800
4.2
4
45
50
高
很高
很高
一般
首先对不同度量单位和不同数量级的指标值进行标准 化处理。先将定性指标定量化:
变换后的指标值矩阵为:
aij A1 f1 1 f2 1 f3 67 f4 50.5 f5 34 f6 50.5
例如,对企业产品的生产管理,既希望达到高利润,又 希望优质和低消耗,还希望减少对环境的污染等。这就 是一个多目标决策的问题。又如选购一个好的计算机系 统,似乎只有一个目标,但由于要从多方面去反映,要用 多个不同的准则来衡量,比如,性能要好,维护要容易,费 用要省。这些准则自然构成了多个目标,故也是一个多 目标决策问题。一般来说,多目标决策问题有两类。一 类是多目标规划问题,其对象是在管理决策过程中求解 使多个目标都达到满意结果的最优方案。另一类是多目 标优选问题,其对象是在管理决策过程中根据多个目标 或多个准则衡量和得出各种备选方案的优先等级与排序。
把上述计算结果列入下表
X X 1* X i* X
p*
综合训练题二:自动泊车
综合训练题二摘要自动泊车是一项非常具有实用性的技术。
自动泊车系统可通过各类传感器获取车位相对汽车的距离,通过控制汽车前轮转角和瞬时速度控制车辆行驶。
本文针对自动泊车系统的研究,参考生活中人工入库的实际情况,对整个倒车过程车辆运动规律进行深入分析之后,运用了几何学相关知识求出了车辆在各段泊车的位置,通过数学建模的方法对泊车策略进行分析,从而实现自动、安全、快速的停车入库。
针对问题一,我们将汽车倒车入库的过程划分为三个阶段,仔细分析汽车倒车入库的过程之后我们考虑这三段过程中可能会发生的接触车库警戒线,列出约束条件,建立数学模型,并采用数形结合的方法对模型进行求解,最终求出汽车能够安全入库的起始点位置范围为下列曲线6.853<y <13.47−2.47<x <5.207y <8.99−0.45x +0.385√(6.442−(x −3.72)2 ;x ∈(−2.47,3.72)(x −2.8)2+(y −9.22)2<2.47;x ∈(3.72,5.207)(x −3.72)2+(y −0.6)2<6.442;x ∈(2.05,3.72)所包络的不规则区域。
针对问题二,我们应该在汽车能够安全倒车入库并停在最恰当位置的前提下寻求满足前轮转角之和最小和后轮行驶距离最短的最佳泊车策略,先针对设任意起始点00(,)x y 分析,对问题一中所构建的模型稍加改动,增加了对最终停车位置的约束条件,并针对前轮转角和后轮行驶距离构建双目标函数,由几何问题转化为多目标非线性规划问题,因为00(,)x y 非具体值,无法通过软件直接求解,通过任意选取多个具体00(,)x y 的值,运用Matlab 软件的fgoalattain 函数对该双目标非线性规划问题求解,得到多个起始点的最佳泊车策略,并进行了比较分析。
关键词:数形结合;Matlab ;多目标函数非线性规划;fgoalattain 函数一、问题重述随着汽车产业及科技的高速发展,智能驾驶汽车成为了国内外公认的未来汽车重要发展方向之一。
数学建模多目标规划函数fgoalattain
MATLAB 中文论坛讲义多目标规划优化问题Matlab 中常用于求解多目标达到问题的函数为fgoalattain.假设多目标函数问题的数学模型为:ubx lb beqx Aeq bx A x ceq x c goalweight x F t s yx ≤≤=≤=≤≤-**0)(0)(*)(..min ,γγ weight 为权值系数向量,用于控制对应的目标函数与用户定义的目标函数值的接近程度; goal 为用户设计的与目标函数相应的目标函数值向量;γ为一个松弛因子标量;F(x)为多目标规划中的目标函数向量。
综上,fgoalattain 的优化过程就是使得F 逼近goal;工程应用中fgoalattain 函数调用格式如下:[x,fval]=fgoalattain (fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon)x0表示初值;fun 表示要优化的目标函数;goal 表示函数fun 要逼近的目标值,是一个向量,它的维数大小等于目标函数fun 返回向量F 的维数大小;weight 表示给定的权值向量,用于控制目标逼近过程的步长;例1. 程序(利用fgoalattain 函数求解)23222123222132min )3()2()1(min x x x x x x ++-+-+-0,,6..321321≥=++x x x x x x t s①建立M 文件.function f=myfun(x)f(1)= x(1)-1)^2+(x(2)-2)^2+(x(3)-3)^2;f(2)= x(1)^2+2*x(2)^2+3*x(3)^2;②在命令窗口中输入.goal=[1,1];weight=[1,1];Aeq=[1,1,1];beq=[6];x0=[1;1;1];lb=[0,0,0]; %也可以写lb=zero(3,1);[x,fval]=fgoalattain(‘myfun’,x0,goal,weight,[ ],[ ],Aeq,beq,lb,[ ])③得到结果.x =3.27271.63641.0909fval =8.9422 19.6364例2.某钢铁公司因生产需要欲采购一批钢材,市面上的钢材有两种规格,第1种规格的单价为3500元/t ,第2种规格的单价为4000元/t.要求购买钢材的总费用不超过1000万元,够得钢材总量不少于2000t.问如何确定最好的采购方案,使购买钢材的总费用最小且购买的总量最多.解:设采购第1、2种规格的钢材数量分别为1x 和2x .根据题意建立如下多目标优化问题的数学模型.0,200010000040003500max 40003500)(min212121211≥≥+≤++=x x x x x x x x x f ①建立M 文件. 在Matlab 编辑窗口中输入:function f=myfun(x)f(1)= 3500*x(1)+4000*x(2);f(2)=-x(1)-x(2);②在命令窗口中输入.goal=[10000000,-2000];weight=[10000000,-2000];x0=[1000,1000];A=[3500,4000;-1,-1];b=[10000000;-2000];lb=[0,0]; %也可以写lb=zero(3,1);[x,fval]=fgoalattain(‘myfun ’,x0,goal,weight,A,b,[ ],[ ],lb,[ ])③得到结果.x =1000 1000fval =7500000 -2000。
多目标规划matlab程序实现——【2019数学建模+思路】
优化与决策——多目标线性规划的若干解法及MATLAB 实现摘要:求解多目标线性规划的基本思想大都是将多目标问题转化为单目标规划,本文介绍了理想点法、线性加权和法、最大最小法、目标规划法,然后给出多目标线性规划的模糊数学解法,最后举例进行说明,并用Matlab 软件加以实现。
关键词:多目标线性规划 Matlab 模糊数学。
注:本文仅供参考,如有疑问,还望指正。
一.引言多目标线性规划是多目标最优化理论的重要组成部分,由于多个目标之间的矛盾性和不可公度性,要求使所有目标均达到最优解是不可能的,因此多目标规划问题往往只是求其有效解(非劣解)。
目前求解多目标线性规划问题有效解的方法,有理想点法、线性加权和法、最大最小法、目标规划法。
本文也给出多目标线性规划的模糊数学解法。
二.多目标线性规划模型多目标线性规划有着两个和两个以上的目标函数,且目标函数和约束条件全是线性函数,其数学模型表示为:11111221221122221122max n n n nr r r rn nz c x c x c x z c x c x c x z c x c x c x =+++⎧⎪=+++⎪⎨ ⎪⎪=+++⎩ (1)约束条件为:1111221121122222112212,,,0n n n n m m mn n mn a x a x a x b a x a x a x b a x a x a x bx x x +++≤⎧⎪+++≤⎪⎪ ⎨⎪+++≤⎪≥⎪⎩ (2) 若(1)式中只有一个1122i i i in n z c x c x c x =+++ ,则该问题为典型的单目标线性规划。
我们记:()ij m n A a ⨯=,()ij r n C c ⨯=,12(,,,)T m b b b b = ,12(,,,)T n x x x x = ,12(,,,)T r Z Z Z Z = .则上述多目标线性规划可用矩阵形式表示为:max Z Cx =约束条件:0Ax bx ≤⎧⎨≥⎩(3)三.MATLAB 优化工具箱常用函数[3]在MA TLAB 软件中,有几个专门求解最优化问题的函数,如求线性规划问题的linprog 、求有约束非线性函数的fmincon 、求最大最小化问题的fminimax 、求多目标达到问题的fgoalattain 等,它们的调用形式分别为:①.[x,fval]=linprog(f,A,b,Aeq,beq,lb,ub)f 为目标函数系数,A,b 为不等式约束的系数, Aeq,beq 为等式约束系数, lb,ub 为x 的下限和上限, fval 求解的x 所对应的值。
数学建模-多目标规划
例 选课策略
课号
课名
学分
所属类别
先修课要求
1
微积分
5
数学
2
线性代数
4
数学
3
最优化方法
4
数学;运筹学 微积分;线性代数
4
数据结构
3
数学;计算机
计算机编程
5
应用统计
4
数学;运筹学 微积分;线性代数
6
计算机模拟
3
计算机;运筹学
计算机编程
7
计算机编程
2
计算机
8
预测理论
2
运筹学
应用统计
9
数学实验
3
运筹学;计算机 微积分;线性代数
min h(F (x)) st x R
方法:(1)理想点法
第一步:计算出 个单目标规划问题
f* i
min fi ( x) st x R
第二步:构造评价函数
p
h(F(x))
(
fi (x)
f *)2 i
i 1
3、评价函数法
(2)、线性加权法
p
p
h(F(x)) j f j 其中j 0, j 1
上班时间 加班情况
X1+d3- -d3+=24 X2 +d4- -d4+=30
市场需求
X1 , X2 , di- , di+ 0 di- .di+= 0 (i=1,2,3,4)
多目标线性规划问题的Matlab7.0求解
多目标线性规划标准形式 min f (x) ( f1(x), f2(x), fn(x))T gi (x) 0 i 1, 2 , m hj (x) 0 j 1, 2, , k x0
水资源优化配置中多目标模型的建立和求解
93河南科技2010.2下水资源优化配置是指在流域或特定的区域范围内,运用系统工程理论和优化方法,以水资源的可持续利用和经济社会的可持续发展为目标,遵循公平、高效、统筹兼顾和可持续利用的原则,采取除害与兴利、水量与水质、开源与节流、工程与非工程措施相结合的方法,通过合理抑制需求、有效增加供水、积极保护生态环境等手段和措施,对多种可利用水资源在区域间和各用水部门间进行最优化调配和分配,力求水资源与其他资源合理配置,实现有限水资源的经济、社会和生态环境综合效益最大[1]。
水资源的优化配置研究可为水量和水质在时间和空间上的合理调配和使用以及保障水资源的可持续利用提供科学依据和对策、措施。
因此,水资源的优化配置研究在解决我国的水资源问题,实现水资源的可持续利用等方面均占有重要地位,对促进经济社会的可持续发展具有重要理论和实际意义。
1. 水资源优化配置中多目标问题分析区域水资源系统往往是一个用水部门众多的大系统,在现代水资源优化配置思路中,己经改变了过去以经济效益为中心的基本观念,不仅仅是要获得尽可能大的经济效益,还必须将生态环境保护放到重要位置,同时要兼顾引水保障和粮食安全的问题。
配置中所考虑的不同问题可以作为不同的目标,各个目标之间相互矛盾而又不可公度,这就使得区域水资源优化配置转变成一个多目标优化的问题,在协调各个配置目标时要以公平与高效为基本分配原则,目标是寻求水量在各个用水部门之间的最优分配,实现水资源利用的可持续发展。
2 模型的建立及求解2. 1水资源多目标优化配置模型的建立2. 1.1 决策变量根据区域的地形地貌、水利条件、行政区划,一般可将区域划分为若干分区。
根据各水源在区内的配水特性,可将水源划分成两类:共用水源和独立水源。
所谓共用水源是指能同时向两个或两个以上的分区供水的水源。
独立水源是指只能给水源所在的分区供水的水源。
本研究假设区域划分为K个分区,i =1,2,…,K,本文将k分区内所有独立水源计为1个水源、分别有J(K)个用水部门j=1,2, …,J(K)(本文各区均定为4个,分别为工业、生活、农业、生态)。
Matlab多目标规划
算法: 多目标优化同时涉及到一系列对象。fgoalattain函数求解 该问题的基本算法是目标达到法。该法为目标函数建立起目 标值。 实现过程中,使用了松弛变量γ作为模糊变量同时最小化 目标向量F(x);goal参数是一系列目标达到值。在进行优化 之前,通常不知道对象是否会达到目标。使用权向量weight 可以控制是没有达到还是溢出。 attainfactor参数包含解处的γ值。γ取负值时表示目标溢出。
(3)给出约束条件的系数 A=[2 1;-1 –1;-1 0]; b=[200 -100 -50]; lb=zeros(2,1); (4)调用工具箱 [x,fval,attainfactor,exitflag] = … fgoபைடு நூலகம்lattain(@opt26_4o,x0,goal,weight,A,b,[],[],lb,[]) 输出计算结果 x= 50 50 fval = 150 -100 -50 attainfactor = 1.3235e-023 exitflag = 1
min Z ai ( f i f i ) 2
i 1 k
Φi ( x1, x2 ,, xn ) gi (i 1,2,, m)
或写成矩阵形式
min Z ( F F )T A( F F )
Φ( X ) G
式中: a i 是与第i个目标函数相关的权重;
A是由 ai (i 1,2,, k )组成的m×m对 角矩阵。
三、约束模型
理论依据 :若规划问题的某一目标可 以给出一个可供选择的范围,则该目标就 可以作为约束条件而被排除出目标组,进 入约束条件组中。 假如,除第一个目标外,其余目标都 可以提出一个可供选择的范围,则该多目 标规划问题就可以转化为单目标规划问题
18.运用目标达到法求解多目标规划
§18. 运用目标达到法求解多目标规划用目标达到法求解多目标规划的计算过程,可以通过调用Matlab软件系统优化工具箱中的fgoalattain函数实现。
在Matlab的优化工具箱中,fgoalattain函数用于解决此类问题。
其数学模型形式为:minγF(x)-weight ·γ≤goalc(x) ≤0ceq(x)=0A x≤bAeq x=beqlb≤x≤ub其中,x,weight,goal,b,beq,lb和ub为向量;A和Aeq为矩阵;c(x),ceq(x)和F(x)为函数。
调用格式:x=fgoalattain(F,x0,goal,weight)x=fgoalattain(F,x0,goal,weight,A,b)x=fgoalattain(F,x0,goal,weight,A,b,Aeq,beq)134x=fgoalattain(F,x0,goal,weight,A,b,Aeq,beq,lb,ub)x=fgoalattain(F,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon)x=fgoalattain(F,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon,options)x=fgoalattain(F,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon,options,P1,P2)[x,fval]=fgoalattain(…)[x,fval,attainfactor]=fgoalattain(…)[x,fval,attainfactor,exitflag,output]=fgoalattain(…)[x,fval,attainfactor,exitflag,output,lambda]=fgoalattain(…)说明:F为目标函数;x0为初值;goal为F达到的指定目标;weight为参数指定权重;A、b为线性不等式约束的矩阵与向量;Aeq、beq为等式约束的矩阵与向量;lb、ub为变量x的上、下界向量;nonlcon为定义非线性不等式约束函数c(x)和等式约束函数ceq(x);options中设置优化参数。
MATLAB多目标优化计算讲解学习
Ceq(X)=0 (非线性等式约束)
Lb ≤X ≤Ub (边界约束条件)
6.1 函数fgoalattain
二、优化函数使用格式
返回目标函数的最优解 返回目标函数的最优值 返回算法的终止标志 优化算法信息的一个数据结构
返回目标函数在最优解的梯度
[x,fval,exitflag,output, grad,hessian]=
a=a1+sqrt(a1^2-a2);
f(2)=a;
%f2,中心距:目标函数2
P0=0.02424*x(1)-1.1128789;
%单根带额定功率
DP0=0.17;
%功率增量
alpha=180-180*x(1)*(i-1)/pi/a; %小带轮包角
Kalp=alpha/(0.549636*alpha+80.396114); %包角系数
%带速范围V<=Vmax
a1=x(2)/4-pi*x(1)*(i+1)/8;
a2=x(1)^2*(i-1)^2/8;
a=a1+sqrt(a1^2-a2);
g(3)=120-180*(1-x(1)*(i-1)/a/pi); %小带轮包角>=alpmin
g(4)=0.7*x(1)*(i+1)-a;
%中心距范围a>=amin
6.1 函数fgoalattain
三、例题
(3)编制优化设计的M文件
%V带传动多目标优化设计的约束函数文件
function[g,ceq]=VDCD_3mb_YS(x)
i=3;n1=1440;
%已知条件:传动比,转速
g(1)=100-x(1);
%小带轮直径>=Ddmin
基于fgoalattain函数的齿轮传动多目标优化设计
基于fgoalattain函数的齿轮传动多目标优化设计
王纯;韩加好;张燕;卢建国
【期刊名称】《机械工程师》
【年(卷),期】2022()6
【摘要】以二级斜齿圆柱齿轮传动系统为对象,建立了齿轮传动优化设计的多目标优化模型,即以齿轮的齿数、模数、螺旋角为设计变量,充分考虑强度条件和参数间尺寸关系,选取二级斜齿圆柱齿轮传动系统的体积和重合度为目标函数,以强度条件等作为约束条件,并运用fgoalattain函数对二级斜齿圆柱齿轮传动系统进行多目标优化设计,最终得到优化方案。
结果显示,二级斜齿圆柱齿轮传动系统体积减小33.1%,重合度提高0.97%。
【总页数】3页(P16-18)
【作者】王纯;韩加好;张燕;卢建国
【作者单位】连云港职业技术学院
【正文语种】中文
【中图分类】TH132.41
【相关文献】
1.基于ISIGHT的斜齿圆柱齿轮传动多目标优化设计∗
2.基于遗传算法的推料机齿轮传动多目标优化设计
3.基于MATLAB的多目标齿轮传动优化设计
4.基于弹流润滑理论的双圆弧齿轮传动多目标优化设计
5.基于改进粒子群算法的行星齿轮传动多目标可靠性优化设计
因版权原因,仅展示原文概要,查看原文内容请购买。
4、多目标优化方法-fgoalattain
v=%3.2fm/s Xn’ ,v); F0=%3.2fNX1【 ’ ,F0); FQ=%3.2f N XI 目标 函数文件
funtbton f VDCDJmb~VΙ Boo
P=4;i=3;KA=1.1;
1)=x(1); ※
%已 知条件 :功 率 、传 动 比、工况 系 数
a=%3.2f mm Xn’
,a);
D凼 =%3。 Ofmm X11’ ρd0;
革 仑 持 车 作 L角 alpha=o/。 3.2f麈 : \n1aIpha); V带 根数 z=%3。 OfXn’ ,z);
q=0.1;
v=pi*Dd1*n“ M; %带 速 (m/s) KaIp=aIpha/(0。 M%36*alpha+80.396114); %包 角 系数
**********
fpnnt义 1,9
fprintK△
fprintK1,’ fprintK1,’ fprintK1,’ fprintK1,’
・
计 堡 争结 隽 艮 **********,; ’ d1); 小带轮基准直 径 Dd1=%3。 Ofmm X【 【 ρ
大带轮基准直径 传动 中心距
/l、
V带 基准长度 Ld=%3.Of mm Xn’ ,Ld);
%Ⅱ 丬、 带轮基准直径
a1=x(2)/4-pi*x(1)*(i十 1)/8;
a2〓 x(1)^2*(⒈ 1)^2/8;
a=a1+sqrt(a1^2ˉ a2);
K2)=a;
P0=0.02424*x(1)-1・ 112879;
%】 ,-中 心距
DP0=0.1⒎
a1pha=180-180*x(1)*(i-1)/pVa;
KaIp=aIpha/(0.549636*aIpha+80.396114); KL=0.20639*x(2)^0・ 211806;
最优化方法的Matlab实现(公式完整版)
第九章最优化方法的Matlab实现在生活和工作中,人们对于同一个问题往往会提出多个解决方案,并通过各方面的论证从中提取最佳方案。
最优化方法就是专门研究如何从多个方案中科学合理地提取出最佳方案的科学。
由于优化问题无所不在,目前最优化方法的应用和研究已经深入到了生产和科研的各个领域,如土木工程、机械工程、化学工程、运输调度、生产控制、经济规划、经济管理等,并取得了显著的经济效益和社会效益。
用最优化方法解决最优化问题的技术称为最优化技术,它包含两个方面的内容:1)建立数学模型即用数学语言来描述最优化问题。
模型中的数学关系式反映了最优化问题所要达到的目标和各种约束条件。
2)数学求解数学模型建好以后,选择合理的最优化方法进行求解。
最优化方法的发展很快,现在已经包含有多个分支,如线性规划、整数规划、非线性规划、动态规划、多目标规划等。
概述利用Matlab的优化工具箱,可以求解线性规划、非线性规划和多目标规划问题。
具体而言,包括线性、非线性最小化,最大最小化,二次规划,半无限问题,线性、非线性方程(组)的求解,线性、非线性的最小二乘问题。
另外,该工具箱还提供了线性、非线性最小化,方程求解,曲线拟合,二次规划等问题中大型课题的求解方法,为优化方法在工程中的实际应用提供了更方便快捷的途径。
9.1.1 优化工具箱中的函数优化工具箱中的函数包括下面几类:1.最小化函数表9-1 最小化函数表2.方程求解函数表9-2 方程求解函数表3.最小二乘(曲线拟合)函数表9-3 最小二乘函数表4.实用函数表9-4 实用函数表5.大型方法的演示函数表9-5 大型方法的演示函数表6.中型方法的演示函数表9-6 中型方法的演示函数表9.1.3 参数设置利用optimset函数,可以创建和编辑参数结构;利用optimget函数,可以获得o ptions优化参数。
optimget函数功能:获得options优化参数。
语法:val = optimget(options,'param')val = optimget(options,'param',default)描述:val = optimget(options,'param') 返回优化参数options中指定的参数的值。
Mastercam课件教案第9章多目标规划
• [X,FVAL]=FGOALATTAIN(FUN,X0,...) • 调用格式8:
• [X,FVAL,ATTAINFACTOR]=FGOALATT AIN(FUN,X0,...)
• 调用格式9:
• [X,FVAL,ATTAINFACTOR,EXITFLAG]= FGOALATTAIN(FUN,X0,...)
• 调用格式10:
• [X,FVAL,ATTAINFACTOR,EXITFLAG,O UTPUT]=FGOALATTAIN(FUN,X0,...)
• 调用格式11:
• [FVAL,ATTAINFACTOR,EXITFLAG,O UTPUT,LAMBDA]=FGOALATTAIN(FUN ,X0,...)
• 例:输出反馈控制器 • 考虑如下的微分方程线性系统
• 这是一个双输入双输出非稳态过程,输入 设备的状态空间矩阵如下:
• 要求设计一个复杂设备的输出反馈控制器, 使闭环系统
• 在复平面实轴上点[-5,-3,-1]的左侧有极 点,另外,为了不使输入“饱和”,要求。 也就是说,此控制器不能有可增益元素的 绝对值超过4。
9.3 应用实例分析
• 例:公司决定使用200万元新产品开发基 金购买两种原材料A、B,材料A每吨2.3 万元,材料B每吨3万元,根据新产品开发 的需要,购得原材料的总量不少于70吨, 其中,原材料B不少于30吨,是给该公司 确定最佳采购方案。
• 例:某工厂准备生产两种新产品甲和乙,生产 设备费用分别为:每生产一吨甲需要1万元,生 产一吨乙需要3万元。但是,由于技术方面存在 天然缺陷,这两种产品的生产均会造成环境污 染,为了做好环境处理工作,每生产一吨甲需 要花费3万元,每生产一吨乙需要花费2万元来 治理造成的环境污染;市场调查显示,这两种 新产品有广阔的市场,每个月的需求量不少于8 吨,但是,工厂生产这两种产品的生产能力有 限,分别为:产品甲每月5吨,产品乙每月6吨。 试确定生产方案,使得在满足市场需要的前提 下,使设备投资和环境治理费用最小。另外, 在政府治理环境的压力下,根据工厂决策层的 经验决定,这两个目标中,环境污染应优先考 虑,设备投资的目标值为20万元,环境治理费 用的目标为15万元。
3、多目标优化方法-fgoalattain
机械优化设计
z z z z z z z z z
OUTPUT = iterations: 3 funcCount: 12 lssteplength: 1 stepsize: 3.4101e-010 algorithm: 'goal attainment SQP, Quasi-Newton, line_search' firstorderopt: [] constrviolation: 0 message: [1x771 char]
机械优化设计
பைடு நூலகம்
多目标优化方法
机械优化设计
多目标规划的Matlab求解 fgoalattain--Multiobjective goal attainment 用目标达到法求解多目标规划的计算过程,可以通过 调用Matlab软件系统优化工具箱中的fgoalattain函数实现。 该函数的使用方法,如下: 1、X = fgoalattain(FUN,X0,GOAL,WEIGHT) 2、X= fgoalattain(FUN,X0,GOAL,WEIGHT,A,B,Aeq, Beq,LB,UB) 3、[X,FVAL,ATTAINFACTOR,EXITFLAG,OUTPUT]= fgoalattain(FUN,X0,...) 在command window中输入help fgoalattain 或者doc fgoalattain 看fgoalattain函数的帮助文档
A、Aeq为矩阵;C(x)、Ceq(x)和F(x)是返回向量的函数; F(x)、C(x)、Ceq(x)可以是非线性函数; weight为权值系数向量,用于控制对应的目标函数与用户 定义的目标函数值的接近程度; goal为用户设计的与目标函数相应的目标函数值向量;
多目标规划有关函数介绍
多目标规划有关函数介绍利用fgoalattain 函数求解多目标达到问题。
假设多目标达到问题的数学模型。
minyx,yF(x) –weight·γ≤goalc(x) ≤ 0A·x≤bAeq·x= beqlb≤x≤ub式中,x, weight, goal, b, beq, lb 和ub 为矢量,A 和Aeq 为矩阵,c(x),ceq(x) 和F(x)为函数,返回矢量。
F(x), c(x) 和ceq(x) 可以是非线性函数。
fgoalattain 函数的调用格式为:fgoalattain(fun,x0,goal,weight) 试图通过变化x来使目标函数fun达到goal指定的目标。
初值x0,weight 参数指定权重。
fgoalattain(fun,x0,goal,weight,A,b) 求解目标达到问题,约束条件为线性不等式A*x <= bfgoalattain(fun,x0,goal,weight,A,b,Aeq,beq) 求解目标达到问题,除提供上面的线性不等式外,还提供线性等式Aeq*x = beq. 当没有不等式存在时,设置A=[]. b =[]。
fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub)为设计变量x定义下届lb 和上届ub 集合,这样始终有lb≤ x ≤ ub.fgoalattain(fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon) 将目标到达问题归结为nonlcon参数定义的非线性不等式c(x) 或非线性等式ceq(x)。
fgoalattain 函数优化的约束条件为c(x) ≤ 0 和ceq(x) =0 .若不存在边界,则设置lb =[] 和ub =[].[x,fval] = fgoalattain(…) 返回解x处的目标函数值[x,fval,attainfactor] = fgoalattain(…) 返回解x处的目标到达因子。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
MATLAB 中文论坛讲义
多目标规划优化问题
Matlab 中常用于求解多目标达到问题的函数为fgoalattain.假设多目标函数问题的数学模型为:
ub
x lb beq
x Aeq b
x A x ceq x c goal
weight x F t s y
x ≤≤=≤=≤≤-**0
)(0
)(*)(..min ,γγ weight 为权值系数向量,用于控制对应的目标函数与用户定义的目标函数值的接近程度; goal 为用户设计的与目标函数相应的目标函数值向量;
γ为一个松弛因子标量;
F(x)为多目标规划中的目标函数向量。
综上,fgoalattain 的优化过程就是使得F 逼近goal;
工程应用中fgoalattain 函数调用格式如下:
[x,fval]=fgoalattain (fun,x0,goal,weight,A,b,Aeq,beq,lb,ub,nonlcon)
x0表示初值;
fun 表示要优化的目标函数;
goal 表示函数fun 要逼近的目标值,是一个向量,它的维数大小等于目标函数fun 返回向量F 的维数大小;
weight 表示给定的权值向量,用于控制目标逼近过程的步长;
例1. 程序(利用fgoalattain 函数求解)
23222
12
3222132min )3()2()1(min x x x x x x ++-+-+-
0,,6
..321321≥=++x x x x x x t s
①建立M 文件.
function f=myfun(x)
f(1)= x(1)-1)^2+(x(2)-2)^2+(x(3)-3)^2;
f(2)= x(1)^2+2*x(2)^2+3*x(3)^2;
②在命令窗口中输入.
goal=[1,1];
weight=[1,1];
Aeq=[1,1,1];
beq=[6];
x0=[1;1;1];
lb=[0,0,0]; %也可以写lb=zero(3,1);
[x,fval]=fgoalattain(‘myfun’,x0,goal,weight,[ ],[ ],Aeq,beq,lb,[ ])
③得到结果.
x =
3.2727
1.6364
1.0909
fval =
8.9422 19.6364
例2.某钢铁公司因生产需要欲采购一批钢材,市面上的钢材有两种规格,第1种规格的单价为3500元/t ,第2种规格的单价为4000元/t.要求购买钢材的总费用不超过1000万元,够得钢材总量不少于2000t.问如何确定最好的采购方案,使购买钢材的总费用最小且购买的总量最多.
解:设采购第1、2种规格的钢材数量分别为1x 和2x .根据题意建立如下多目标优化问题的数学模型.
0,2000
100000
40003500max 40003500)(min
212121211≥≥+≤++=x x x x x x x x x f ①建立M 文件. 在Matlab 编辑窗口中输入:
function f=myfun(x)
f(1)= 3500*x(1)+4000*x(2);
f(2)=-x(1)-x(2);
②在命令窗口中输入.
goal=[10000000,-2000];
weight=[10000000,-2000];
x0=[1000,1000];
A=[3500,4000;-1,-1];
b=[10000000;-2000];
lb=[0,0]; %也可以写lb=zero(3,1);
[x,fval]=fgoalattain(‘myfun ’,x0,goal,weight,A,b,[ ],[ ],lb,[ ])
③得到结果.
x =
1000 1000
fval =
7500000 -2000。