搜档网
当前位置:搜档网 › matlab多目标优化模型教程

matlab多目标优化模型教程

matlab多目标优化模型教程
matlab多目标优化模型教程

fgoalattain

Solve multiobjective goal attainment problems

Equation

Finds the minimum of a problem specified by

x, 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.

Syntax

x = 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(...)

Description

fgoalattain 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 Arguments

Function 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 accepts

a vector x and returns a vector F, the objective functions

evaluated at x. The function fun can be specified as a function

handle for a function file:

x = fgoalattain(@myfun,x0,goal,weight)

where myfun is a MATLAB function such as

function 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 are

converted to a vector using linear indexing.

To make an objective function as near as possible to a goal

value, (i.e., neither greater than nor less than) use optimset

to set the GoalsExactAchieve option to the number of objectives

required to be in the neighborhood of the goal values. Such

objectives must be partitioned into the first elements of the

vector F returned by fun.

If the gradient of the objective function can also be computed

and the GradObj option is 'on', as set by

options = optimset('GradObj','on')

then the function fun must return, in the second output

argument, the gradient value G, a matrix, at x. The gradient

consists of the partial derivative dF/dx of each F at the point

x. If F is a vector of length m and x has length n, where n is

the length of x0, then the gradient G of F(x) is an n-by-m matrix

where G(i,j) is the partial derivative of F(j) with respect to

x(i) (i.e., the jth column of G is the gradient of the jth

objective 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 returned

by fun. fgoalattain attempts to minimize the values in the

vector 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 constraints

ceq(x) = 0. The function nonlcon accepts a vector x and returns

two vectors c and ceq. The vector c contains the nonlinear

inequalities evaluated at x, and ceq contains the nonlinear

equalities evaluated at x. The function nonlcon can be

specified as a function handle.

x = fgoalattain(@myfun,x0,goal,weight,A,b,Aeq,beq,...

lb,ub,@mycon)

where mycon is a MATLAB function such as

function [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 and

the GradConstr option is 'on', as set by

options = optimset('GradConstr','on')

then the function nonlcon must also return, in the third and

fourth 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 not

accept supplied gradients.

If nonlcon returns a vector c of m components and x has length

n, 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 derivative

of c(j) with respect to x(i) (i.e., the jth column of GC is the

gradient of the jth inequality constraint c(j)). Likewise, if

ceq has p components, the gradient GCeq of ceq(x) is an n-by-p

matrix, where GCeq(i,j) is the partial derivative of ceq(j)

with respect to x(i) (i.e., the jth column of GCeq is the

gradient of the jth equality constraint ceq(j)).

Passing Extra Parameters explains how to parameterize the

nonlinear 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 the

values of goal are all nonzero, to ensure the same percentage

of under- or overattainment of the active objectives, set the

weighting function to abs(goal). (The active objectives are the

set of objectives that are barriers to further improvement of

the goals at the solution.)

When the weighting function weight is positive, fgoalattain

attempts to make the objectives less than the goal values. To

make the objective functions greater than the goal values, set

weight to be negative rather than positive. To make an objective

function as near as possible to a goal value, use the

GoalsExactAchieve option and put that objective as the first

element of the vector returned by fun (see the preceding

description of fun and options).

problem objective Vector of objective functions

x0 Initial point for x

goal Goals to attain

weight Relative importance factors of goals

Aineq Matrix for linear inequality constraints

bineq Vector for linear inequality constraints

Aeq Matrix for linear equality constraints

beq Vector for linear equality constraints

lb Vector of lower bounds

ub Vector of upper bounds

nonlcon Nonlinear constraint function

solver 'fgoalattain'

options Options structure created with optimset Output Arguments

Function 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 been

underachieved.

attainfactor contains the value of γ at the solution. A

negative value of γindicates overattainment in the goals.

exitflag Integer identifying the reason the algorithm terminated.

The following lists the values of exitflag and the

corresponding reasons the algorithm terminated.

1 Function converged to a solutions x.

4 Magnitude of the search direction less

than the specified tolerance and

constraint violation less than

options.TolCon

5 Magnitude of directional derivative less

than the specified tolerance and

constraint violation less than

options.TolCon

0 Number of iterations exceeded

options.MaxIter or number of function

evaluations exceeded options.FunEvals

-1 Algorithm was terminated by the output

function.

-2 No feasible point was found.

lambda Structure containing the Lagrange multipliers at the solution x (separated by constraint type). The fields of the

structure are

lower Lower bounds lb

upper Upper bounds ub

ineqlin Linear inequalities

eqlin Linear equalities

ineqnonlin Nonlinear inequalities

eqnonlin Nonlinear equalities

output Structure containing information about the optimization.

The fields of the structure are

iterations Number of iterations taken

funcCount Number of function evaluations

lssteplength Size of line search step relative to

search direction

stepsize Final displacement in x

algorithm Optimization algorithm used

firstorderopt Measure of first-order optimality

constrviolation Maximum of constraint functions

message Exit message

Options

Optimization 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 of

objective or constraints) to finite-differencing

derivatives. The choices are 'on' or the default,

'off'.

Diagnostics Display diagnostic information about the function

to be minimized or solved. The choices are 'on' or

the default, 'off'.

DiffMaxChange Maximum change in variables for finite-difference

gradients (a positive scalar). The default is 0.1.

DiffMinChange Minimum change in variables for finite-difference

gradients (a positive scalar). The default is 1e-8. Display Level of display.

?'off' displays no output.

?'iter' displays output at each iteration, and

gives the default exit message.

?'iter-detailed' displays output at each

iteration, and gives the technical exit

message.

?'notify' displays output only if the function

does not converge, and gives the default exit

message.

?'notify-detailed' displays output only if the

function does not converge, and gives the

technical exit message.

?'final' (default) displays just the final

output, and gives the default exit message.

?'final-detailed' displays just the final

output, and gives the technical exit message.

FinDiffType Finite differences, used to estimate gradients, are

either 'forward' (default), or 'central'

(centered). 'central' takes twice as many function

evaluations, but should be more accurate.

The algorithm is careful to obey bounds when

estimating both types of finite differences. So, for

example, it could take a backward, rather than a

forward, difference to avoid evaluating at a point

outside bounds.

FunValCheck Check whether objective function and constraints

values are valid. 'on' displays an error when the

objective function or constraints return a value

that is complex, Inf, or NaN. The default, 'off',

displays no error.

GoalsExactAchieve Specifies the number of objectives for which it is

required for the objective fun to equal the goal goal

(a nonnegative integer). Such objectives should be

partitioned into the first few elements of F. The

default is 0.

GradConstr Gradient for nonlinear constraint functions defined

by the user. When set to 'on', fgoalattain expects

the constraint function to have four outputs, as

described in nonlcon in the Input Arguments section.

When set to the default, 'off', gradients of the

nonlinear constraints are estimated by finite

differences.

GradObj Gradient for the objective function defined by the

user. See the preceding description of fun to see

how to define the gradient in fun. Set to 'on' to

have fgoalattain use a user-defined gradient of the

objective function. The default, 'off',

causesfgoalattain to estimate gradients using

finite differences.

MaxFunEvals Maximum number of function evaluations allowed (a

positive integer). The default is

100*numberOfVariables.

MaxIter Maximum number of iterations allowed (a positive

integer). The default is 400.

MaxSQPIter Maximum number of SQP iterations allowed (a positive

integer). The default is 10*max(numberOfVariables,

numberOfInequalities + numberOfBounds)

MeritFunction Use goal attainment/minimax merit function if set

to 'multiobj', the default. Use fmincon merit

function if set to 'singleobj'.

OutputFcn Specify one or more user-defined functions that an

optimization function calls at each iteration,

either as a function handle or as a cell array of

function handles. The default is none ([]). See

Output Function.

PlotFcns Plots various measures of progress while the

algorithm executes, select from predefined plots or

write your own. Pass a function handle or a cell

array 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 maximum

constraint violation

?@optimplotstepsize plots the step size

For information on writing a custom plot function,

see Plot Functions.

RelLineSrchBnd Relative bound (a real nonnegative scalar value) on

the line search step length such that the total

displacement in x satisfies

|Δx(i)| ≤relLineSrchBnd· max(|x(i)|,|typical

x(i)|). This option provides control over the

magnitude of the displacements in x for cases in

which the solver takes steps that are considered too

large. 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 SQP

constraint violation, a positive scalar. The

default is 1e-6.

TolFun Termination tolerance on the function value, a

positive scalar. The default is 1e-6.

TolX Termination tolerance on x, a positive scalar. The

default is 1e-6.

TypicalX Typical x values. The number of elements in TypicalX

is equal to the number of elements in x0, the

starting point. The default value is

ones(numberofvariables,1). fgoalattain uses

TypicalX for scaling finite differences for

gradient estimation.

UseParallel When 'always', estimate gradients in parallel.

Disable by setting to the default, 'never'. Examples

Consider a linear system of differential equations.

An output feedback controller, K, is designed producing a closed loop system

The 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 objectives

Next, 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 matrix

goal = [-5 -3 -1]; % Set goal values for the eigenvalues weight = abs(goal); % Set weight for same percentage

lb = -4*ones(size(K0)); % Set lower bounds on the controller

ub = 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 is

Active inequalities (to within options.TolCon = 1e-006):

lower upper ineqlinineqnonlin

1 1

2 2

4

K =

-4.0000 -0.2564

-4.0000 -4.0000

fval =

-6.9313

-4.1588

-1.4099

attainfactor =

-0.3863

Discussion

The 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 is

K =

-1.5954 1.2040

-0.4201 -2.9046

fval =

-5.0000

-3.0000

-1.0000

attainfactor =

1.0859e-20

In 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.

Notes

This 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 steps

toward 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.

Algorithm

Multiobjective 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' with

options = 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'.

Limitations

The objectives must be continuous. fgoalattain might give only local solutions.

matlab优化设计

MATLAB优化设计 学院:机电学院 专业:机械设计制造及其自动化 班级:072&&&-** 学号:20131****** 姓名:大禹 指导老师:祯 2015年10月25日

题目 1 1、求解如下最优化问题 步骤一:对已有的数学模型matlab 编程 1. 编写.m 文件并保存: h=[2 ,-2;-2, 4]; %实对称矩阵 f=[-2;-6]; %列向量 a=[1, 1;-1, 2]; %对应维数矩阵 b=[2;2]; %列向量 lb=zeros(2, 1); [x,value]=quadprog(h, f, a ,b ,[] ,[], lb) 2. 运行.m 文件结果如图1.0所示: subject to 2 21≤+x x 22-21≤+x x 0 21≥x x ,2 2 2121212262)(m in x x x x x x x f +-+--=

图1.0题目一文件运行结果 步骤二:matlab运行结果分析阶段 由图1.0知,当x1=0.8,x2=1.2时,min f (x)= -7.2。 题目 2 2、某农场拟修建一批半球壳顶的圆筒形谷仓,计划每座谷仓容积为300立方米,圆筒半径不得超过3米,高度不得超过10米。半球壳顶的建筑造价为每平方米150元,圆筒仓壁的造价为每平方米120元,地坪造价为每平方米50元,求造价最小的谷仓尺寸为多少?

步骤一:题目分析阶段 设:圆筒的半径为R,圆筒的高度为H 。 谷仓的容积为300立方米,可得: 3003 232=+R H R ππ 圆筒高度不得超过10米,可得: 100≤≤H 圆筒半径不得超过3米,可得: 30≤≤R 当造价最小时: 2225021202150),(m in R H R R H R f πππ+?+?= 步骤二:数学模型建立阶段 2 225021202150),(m in R H R R H R f πππ+?+?=

2019年matlab优化工具箱的使用

优化工具箱的使用 MATLAB的优化工具箱提供了各种优化函数,这些优化函数可以通过在命令行输入相应的函数名加以调用;此外为了使用方便,MA TLAB还提供了图形界面的优化工具(GUI Optimization tool)。 1 GUI优化工具 GUI优化工具的启动 有两种启动方法: (1)在命令行输入optimtool; (2)在MA TLAB主界面单击左下角的“Start”按钮,然后依次选择“Toolboxes→Optimization→Optimization tool” GUI优化工具的界面 界面分为三大块: 左边(Problem Setup and Results)为优化问题的描述及计算结果显示; 中间(Options)为优化选项的设置; 右边(Quick Reference)为帮助。为了界面的简洁,可以单击右上角“<<”、“>>”的按钮将帮助隐藏或显示。 1、优化问题的描述及计算结果显示 此板块主要包括选择求解器、目标函数描述、约束条件描述等部分。 选择合适的求解器以及恰当的优化算法,是进行优化问题求解的首要工作。 ?Solver:选择优化问题的种类,每类优化问题对应不同的求解函数。 ?Algorithm:选择算法,对于不同的求解函数,可用的算法也不同。 Problem框组用于描述优化问题,包括以下内容: ?Objective function: 输入目标函数。 ?Derivatives: 选择目标函数微分(或梯度)的计算方式。 ?Start point: 初始点。 Constraints框组用于描述约束条件,包括以下内容: ?Linear inequalities: 线性不等式约束,其中A为约束系数矩阵,b代表约束向量。 ?Linear equalities: 线性等式约束,其中Aeq为约束系数矩阵,beq代表约束向量。 ?Bounds: 自变量上下界约束。 ?Nonlinear Constraints function; 非线性约束函数。 ?Derivatives: 非线性约束函数的微分(或梯度)的计算方式。 Run solver and view results框组用于显示求解过程和结果。 (对于不同的优化问题类型,此板块可能会不同,这是因为各个求解函数需要的参数个数不一样,如Fminunc 函数就没有Constraints框组。) 2、优化选项(Options) ?Stopping criteria: 停止准则。

基于MATLAB的优化设计

基于MATLAB的曲柄摇杆机构优化设计 1.问题的提出 根据机械的用途和性能要求的不同,对连杆机构设计的要求是多种多样的,但这些设计要求可归纳为以下三种问题:(1)满足预定的运动规律要求;(2)满足预定的连杆位置要求;(3)满足预定的轨迹要求。在在第一个问题 里按照期望函数设计的思想,要求曲柄摇杆机构的曲柄与摇杆转角之间按照φ=f(?)(称为期望函数)的关系实现运动,由于机构的待定参数较少,故一 般不能准确实现该期望函数,设实际的函数为φ=F(?)(称为再现函数),而再 现函数一般是与期望函数不一致的,因此在设计时应使机构再现函数φ=F(?) 尽可能逼近所要求的期望函数φ=f(?)。这时需按机械优化设计方法来设计曲 柄连杆,建立优化数学模型,研究并提出其优化求解算法,并应用于优化模型的求解,求解得到更优的设计参数。 2.曲柄摇杆机构的设计 在图1所示的曲柄摇杆机构中,l1、l2、l3、l4分别是曲柄AB、连杆BC、摇杆CD和机架AD的长度。这里规定?0为摇杆在右极限位置φ0时的曲柄起始 位置角,它们由l1、l2、l3和l4确定。 图1曲柄摇杆机构简图 设计时,可在给定最大和最小传动角的前提下,当曲柄从?0转到?0+90?时,要求摇杆的输出角最优地实现一个给定的运动规律f(?)。这里假设要求: (?-?0)2(1)φE=f(?)=φ0+2 3π

s=30;qb=1;jj=5;fx=0; fa0=acos(((qb+x(1))^2-x(2)^2+jj^2)/(2*(qb+x(1))*jj)); %曲柄初始角 pu0=acos(((qb+x(1))^2-x(2)^2-jj^2)/(2*x(2)*jj));%摇杆初始角for i=1:s fai=fa0+0.5*pi*i/s; pui=pu0+2*(fai-fa0)^2?(3*pi); ri=sqrt(qb^2+jj^2-2*qb*jj*cos(fai)); alfi=acos((ri^2+x(2)^2-x(1)^2)/(2*ri*x(2))); bati=acos((ri^2+jj^2-qb^2)(/2*ri*jj)); if fai>0&fai<=pi psi=pi-alfi-bati; elseif fai>pi&fai<=2*pi psi=pi-alfi+bati; end fx=fx+(pui-psi)^2; end f=fx; (2)编写非线性约束函数M文件confun.m function[c,ceq]=confun(x); qb=1;jj=5;m=45*pi/180;n=135*pi/180; c(1)=x(1)^2+x(2)^2-(jj-qb)^2-2*x(1)*x(2)*cos(m); %最小传动角约束c(2)=-x(1)^2-x(2)^2+(jj+qb)^2+2*x(1)*x(2)*cos(n); %最大传动角约束ceq=[]; (3)在MATLAB命令窗口调用优化程序 x0=[6;4]; lb=[1;1]; ub=[]; %线性不等式约束 a=[-1-1;1-1;-11];b=[-6;4;4];[x,fn]=fmincon(@optimfun, x0,a,b,[],[],lb,ub,@confun); (4)运行结果

最优化方法的Matlab实现(公式(完整版))

第九章最优化方法的MatIab实现 在生活和工作中,人们对于同一个问题往往会提出多个解决方案,并通过各方面的论证从中提取最佳方案。最优化方法就是专门研究如何从多个方案中科学合理地提取出最佳方案的科学。由于优化问题无所不在,目前最优化方法的应用和研究已经深入到了生产和科研的各个领域,如土木工程、机械工程、化学工程、运输调度、生产控制、经济规划、经济管理等,并取得了显著的经济效益和社会效益。 用最优化方法解决最优化问题的技术称为最优化技术,它包含两个方面的内容: 1)建立数学模型即用数学语言来描述最优化问题。模型中的数学关系式反映了最优化问题所要达到的目标和各种约束条件。 2)数学求解数学模型建好以后,选择合理的最优化方法进行求解。 最优化方法的发展很快,现在已经包含有多个分支,如线性规划、整数规划、非线性规划、动态规划、多目标规划等。 9.1 概述 利用Matlab的优化工具箱,可以求解线性规划、非线性规划和多目标规划问题。 具体而言,包括线性、非线性最小化,最大最小化,二次规划,半无限问题,线性、非线性方程(组)的求解,线性、非线性的最小二乘问题。另外,该工具箱还提供了线性、非线性最小化,方程求解,曲线拟合,二次规划等问题中大型课题的求解方法,为优化方法在工程中的实际应用提供了更方便快捷的途径。 9.1.1优化工具箱中的函数 优化工具箱中的函数包括下面几类: 1 ?最小化函数

2.方程求解函数 3.最小—乘(曲线拟合)函数

4?实用函数 5 ?大型方法的演示函数 6.中型方法的演示函数 9.1.3参数设置 利用OPtimSet函数,可以创建和编辑参数结构;利用OPtimget函数,可以获得o PtiOns优化参数。 ? OPtimget 函数 功能:获得OPtiOns优化参数。 语法:

matlab 有关GA优化的例子

核心函数: (1)function [pop]=initializega(num,bounds,eevalFN,eevalOps,options)--初始种群的生成函数 【输出参数】 pop--生成的初始种群 【输入参数】 num--种群中的个体数目 bounds--代表变量的上下界的矩阵 eevalFN--适应度函数 eevalOps--传递给适应度函数的参数 options--选择编码形式(浮点编码或是二进制编码)[precision F_or_B],如 precision--变量进行二进制编码时指定的精度 F_or_B--为1时选择浮点编码,否则为二进制编码,由precision指定精度) (2)function [x,endPop,bPop,traceInfo] = ga(bounds,evalFN,evalOps,startPop,opts,... termFN,termOps,selectFN,selectOps,xOverFNs,xOverOps,mutFNs,mutOps)--遗传算法函数 【输出参数】 x--求得的最优解 endPop--最终得到的种群 bPop--最优种群的一个搜索轨迹 【输入参数】 bounds--代表变量上下界的矩阵 evalFN--适应度函数 evalOps--传递给适应度函数的参数 startPop-初始种群 opts[epsilon prob_ops display]--opts(1:2)等同于initializega的options参数,第三个参数控制是否输出,一般为0。如[1e-6 1 0] termFN--终止函数的名称,如[maxGenTerm] termOps--传递个终止函数的参数,如[100] selectFN--选择函数的名称,如[normGeomSelect] selectOps--传递个选择函数的参数,如[0.08] xOverFNs--交*函数名称表,以空格分开,如[arithXover heuristicXover simpleXover] xOverOps--传递给交*函数的参数表,如[2 02 32 0] mutFNs--变异函数表,如[boundaryMutation multiNonUnifMutation nonUnifMutation unifMutation] mutOps--传递给交*函数的参数表,如[4 0 06 100 34 100 34 0 0] 注意】matlab工具箱函数必须放在工作目录下 【问题】求f(x)=x+10*sin(5x)+7*cos(4x)的最大值,其中0<=x<=9 【分析】选择二进制编码,种群中的个体数目为10,二进制编码长度为20,交*概率为0.95,变异概率为0.08 【程序清单】 编写目标函数 function[sol,eval]=fitness(sol,options) x=sol(1) eval=x+10*sin(5*x)+7*cos(4*x) 把上述函数存储为fitness.m文件并放在工作目录下

最优化算法实验报告(附Matlab程序)

最优化方法(Matlab)实验报告 ——Fibonacci 法 一、实验目的: 用MATLAB 程序实现一维搜索中用Fibonacc 法求解一元单峰函数的极小值问题。二、实验原理: (一)、构造Fibonacci 数列:设数列{}k F ,满足条件: 1、011F F == 2、11 k k k F F F +-=+则称数列{}k F 为Fibonacci 数列。(二)、迭代过程: 首先由下面的迭代公式确定出迭代点: 1 1 1 (),1,...,1(),1,...,1n k k k k k n k n k k k k k n k F a b a k n F F u a b a k n F λ---+--+=+ -=-=+ -=-易验证,用上述迭代公式进行迭代时,第k 次迭代的区间长度缩短比率恰好为 1 n k n k F F --+。故可设迭代次数为n ,因此有11121211221111223231 ()()......()()n n n n n n n n n F F F F F F b a b a b a b a b a F F F F F F F ------= -=?-==?-=-若设精度为L ,则有第n 次迭代得区间长度111 ()n n n b a L b a L F -≤-≤,即 就是 111 ()n b a L F -≤,由此便可确定出迭代次数n 。

假设第k 次迭代时已确定出区间[,]k k a b 以及试探点,[,]k k k k u a b λ∈并且k k u λ<。计算试探点处的函数值,有以下两种可能:(1)若()()k k f f u λ>,则令 111111111,,()() () k k k k k k k k n k k k k k n k a b b f f F a b a F λλμλμμ++++--++++-=====+-计算1()k f μ+的值。(2)()()k k f f u λ≤,则令 111121111,,()() () k k k k k k k k n k k k k k n k a a b f f F a b a F μμλμλλ++++--++++-=====+-计算1()k f λ+的值。 又因为第一次迭代确定出了两个迭代点,以后每迭代一次,新增加一个迭代点,这样在迭代n-1后便计算完了n 个迭代点。因此第n 次迭代中,选用第n-1次的迭代点以及辨别常数δ构造n λ和n μ: 1 1n n n n λλμλδ --==+再用同样的方法进行判断:(1)、若()n f λ>()n f μ则令 1 n n n n a b b λ-==(2)、若()n f λ<=()n f μ则令 1n n n n a a b μ-==这样便可确定出最优解的存在区间[,]n n a b 。

基于MATLAB的生产过程中最大利润问题的优化设计

基于MATLAB的生产过程中最大利润问题的优化设计

2010-2011 学年一学期研究生课程考核 (读书报告、研究报告) 考核科目:现代设计理论与方法 学生所在院(系):机电工程学院 学生所在学科:车辆工程 姓名:陈松 学号:Y100201802 题目:基于MATLAB的生产过程中最大利润问题的优化设计

基于MATLAB的生产过程中最大利润问题的优化设计 在工厂编制生产计划中,使产品的计划利润最大是通常的目标。可是,在生产过程中,总是有种种条件的限制,使得我们的生产成本增多,从而导致利润并没有达到理想值。为了解决如何在有约束条件下解决最大利润的问题,我们通常将这些有约束的最优化问题转化为无约束最优化问题。而通过MATLAB现成的优化工具箱,我们可以通过调用最佳优化函数求解,从而更好的计算出生产产品所获得最大利润。 1.数学模型的建立

建立数学模型,即用数学语言来描述最优化问题,模型中的数学关系式反 映了最优化问题所要达到的目标和各种约束条件。而通过这些约束条件,我们能更好的制定新的生产计划,以便克服生产过程中的某些不利于生产的约束,从而更大的降低产品生产成本,使利润最大化。 1.1设计变量的确定 设计变量是指设计过程中可以进行调整和优选的独立参数,分为连续变量和离散变量。而本文主要用的是连续变量,设计变量一般表示为: 式中,X i 表示生产产品的台数,而当我们确定了生产每台的利润后,我们 就能知道X i 台的利润。 1.2目标函数的确定 已知某工厂能生产A、B、C三种产品,每月生产的数量分别为X 1,X 2 , X 3,产品每台利润分别为m 1 ,m 2 ,m 3 ,则可知该厂每月的利润为: Y= m 1 *X 1 + m 2 *X 2 + m 3 *X 3 即目标函数为: X * m + X * m + X * m ) ( 3 3 2 2 1 1 = X F 简化为: F(X)= i i X M*i=1,2,3 1.3约束条件的建立 生产A、B、C三种产品需用到四种机器V1、V2、V3、V4,每种机器的生产能力分别为K1、K2、K3、K4,所以有: 1)用V1每月生产的A、B、C三种部件分别为N1、N2、 N3,则:g 1(x)=N1*X 1 +N2*X 2 +N3*X 3 ≤K1 2)用V2每月生产的A、B、C三种部件分别为N11、N12、 N13,则:g 2(x)=N11*X 1 +N12*X 2 +N13*X 3 ≤K2 3)用V3每月生产的A、B、C三种部件分别为N21、N22、N23, 则:g 3(x)=N21*X 1 +N22*X 2 +N23*X 3 ≤K3

优化方法MATLAB编程——大连理工大学

优化方法上机大作业 学院: 姓名: 学号: 指导老师:肖现涛

第一题 源程序如下: function zy_x = di1ti(x) %di1ti是用来求解优化作业第一题的函数。 x0=x; yimuxulong=0.000001; g0=g(x0);s0=-g0; A=2*ones(100,100); k=0; while k<100 lanmed=-(g0)'*s0/(s0'*A*s0); x=x0+lanmed*s0; g=g(x); k=k+1; if norm(g)

break; end miu=norm(g)^2/norm(g0)^2; s=-g+miu*s0; g0=g; s0=s;x0=x; end function f=f(x) f=(x'*ones(100,1))^2-x'*ones(100,1); function g=g(x) g=(2*x'*ones(100,1))*ones(100,1)-ones(100,1); 代入x0,运行结果如下: >> x=zeros(100,1); >> di1ti(x) After 1 iterations,obtain the optimal solution. The optimal solution is -0.250000. The optimal "x" is "ans". ans =0.005*ones(100,1).

matlab与优化设计

机械优化设计课程设计 题目:齿轮减速器最优化设计班级:机械班 成员

2013年6月19日 一.设计题目:二级斜齿圆柱减速器的最优化设计二.设计要求:要求减速器有最小的体积和最紧凑的结

构 三.原始数据: 四.设计内容 1.设计方案的拟定及说明 2.电动机的选择及参数计算 3.带轮的初选与计算 4.计算圆柱斜齿轮的输入转矩、传动比、转速,然 后建立数学模型编写matlab语言程序,运行 程序包括geardesign. m 齿轮系统设计主程序 Gearobjfun. m目标函数子程序 Gearconstr. m 约束条件子程序 Gearparameter.m许用应力计算子程序 5.输出结果

1.该减速器为二级斜齿圆柱减速器,低速级采用二级斜齿圆 柱齿轮传动,选择三相交流异步电动机,v带传动 2.确定电动机的容量: 选择电动机的容量应保证电动机的额定功率大于等于工作机所需要的功率 电动机参数t=60/40=1.5s v=s/t=6.0*10^-3m/s P=0.5FV=0.5*110*60*0.001=3.3kw 1.η=η1* η32*η23*η4*η5 其中齿轮传动η1=0.96滚动轴承η2=0.98齿轮传动η3=0.97联轴器η4=0.99卷筒η5=1.0 η=0.96*0.98^3*0.97^2*0.99*1.00=0.84 P d=3.3\0.84=2.93kw 三,确定电动机的转速 已知压片机的转速40piece/min带传动的传动比i1=2~4 二级齿轮减速器的传动比i2=8~40,所以电动机的转动范围n=i1i2n=640~6400r/min 可行方案如下 确定电动机的转速具体数据如下 计算减速器输入转矩T1,输入转速n,总传动比i

最优化方法matlab作业

实用最优化方法 ——matlab编程作业

题一、 初值为[-1;1] 其中g0、g1分别为不同x值下得导数,f0、f1为函数值 MATLAB程序: x0=[-1;1]; s0=[1;1]; c1=0.1;c2=0.5;a=0;b=inf;d=1;n=0; x1=x0+d*s0; g0=[-400*(x0(2)-x0(1)^2)*x0(1)-2*(1-x0(1));200*(x0(2)-x0(1) ^2)]; g1=[-400*(x1(2)-x1(1)^2)*x1(1)-2*(1-x1(1));200*(x1(2)-x1(1) ^2)]; f1=100*(x1(2)-x1(1)^2)^2+(1-x1(1))^2; f0=100*(x0(2)-x0(1)^2)^2+(1-x0(1))^2; while((f0-f1<-c1*d*g0'*s0)||(g1'*s0

Matlab最优化编程例子

题目:分别用最速下降法、FR 共轭梯度法、DFP 法和BFGS 法求解问题: 22112212minf(x)x 2x x 4x x 3x =-++- 取初始点(1)T x (1,1)=,通过Matlab 编程实现求解过程。 公用函数如下: 1、function f= fun( X ) %所求问题目标函数 f=X(1)^2-2*X(1)*X(2)+4*X(2)^2+X(1)-3*X(2); end 2、function g= gfun( X ) %所求问题目标函数梯度 g=[2*X(1)-2*X(2)+1,-2*X(1)+8*X(2)-3]; end 3、function He = Hess( X ) %所求问题目标函数Hesse 矩阵 n=length(X); He=zeros(n,n); He=[2,-2; -2,4]; End 解法一:最速下降法 function [ x,val,k ] = grad( fun,gfun,x0 ) %功能:用最速下降法求无约束问题最小值 %输入:x0是初始点,fun 和gfun 分别是目标函数和梯度 %输出:x 、val 分别是最优点和最优值,k 是迭代次数 maxk=5000;%最大迭代次数 rho=0.5;sigma=0.4; k=0;eps=10e-6; while (k

转向梯形优化设计matlab程序

优化计算MATLAB程序 首先,将目标函数写成M文件,其程序语句如下; function f = fun (x) global K L thetamax alpha for i=1:61 f = 0 betae = atan(tan(alpha(i)/(1-(K/L)*tan(alpha(i)))); A(i)=2*x(1).^2*sin(x(2)+alpha(i)); B(i)=2*K*x(1)-2*x(1).^2*cos(x(2)+alpha(i)); C(i)=2*x(1).^2-4*x(1).^2*(cos(x(2)).^2+4*K*x(1)*cos(x(2))-2*K*x(1)* cos(x(2)+alpha(i)); theta3(i)= 2*acot((A(i)+sqrt(A(i).^2+B(i).^2-C(i).^2))/(B(i)+C(i))); beta(i)=x(2)+theta3(i)-pi; if alpha(i)<=pi/18 f(i)=1.5*abs(beta(i)-betae3(i)); elseif alpha>=pi/18,alpha(i)<=pi/9;f(i)=abs(betaa(i)-betae3(i)); elsef(i)=0.5*abs(beta(i)-betae3(i)); global K L thetamax alpha K=input L=input thetamax=input x0(1)=input

x0(2)=input thetamax = thetamax*pi/180; x0(2)=x0(2)*pi/180;lb(1)=0.17K; lb(2)=0.17*K; ub(1)=acot(K/(1.2*L))ub(2)=pi/2; alpha=linspace (0, theamax ,61); lb=[lb(1),lb(2)]; ub=[ub(1),ub(2)];x(0)=[x0(1),x0(2)]; options = optimset ( ‘TolFun’,‘le-10’,‘TolCon’,‘le-6’) [x,resnorm] = lsqnonlin(‘fun’,x0,lb,ub,options) g lobal K L thetamax alpha K = input L= input thetamax= input x ( 1) = input x ( 2) = input thetamax = thetamax * pi/ 180; x ( 2) = x ( 2) * pi/ 180; alpha= linspace( 0, thetamax , 61) ; fo r i= 1∶61 betae= atan( tan( alpha( i) ) / (( 1- K/ L) * tan( alpha( i) ) ) ) ; A ( i) = 2* ( x ( 1) ) .∧2* sin ( x ( 2) + alpha( i) ) ; B( i) = 2* K* x( 1) - 2* ( x ( 1) ) . ∧2* cos( x( 2) + alpha( i) ) ) ;

最优化方法的Matlab实现(公式完整版)

第九章最优化方法的Matlab实现 在生活和工作中,人们对于同一个问题往往会提出多个解决方案,并通过各方面的论证从中提取最佳方案。最优化方法就是专门研究如何从多个方案中科学合理地提取出最佳方案的科学。由于优化问题无所不在,目前最优化方法的应用和研究已经深入到了生产和科研的各个领域,如土木工程、机械工程、化学工程、运输调度、生产控制、经济规划、经济管理等,并取得了显著的经济效益和社会效益。 用最优化方法解决最优化问题的技术称为最优化技术,它包含两个方面的内容:1)建立数学模型即用数学语言来描述最优化问题。模型中的数学关系式反映了最优化问题所要达到的目标和各种约束条件。 2)数学求解数学模型建好以后,选择合理的最优化方法进行求解。 最优化方法的发展很快,现在已经包含有多个分支,如线性规划、整数规划、非线性规划、动态规划、多目标规划等。 9.1 概述 利用Matlab的优化工具箱,可以求解线性规划、非线性规划和多目标规划问题。具体而言,包括线性、非线性最小化,最大最小化,二次规划,半无限问题,线性、非线性方程(组)的求解,线性、非线性的最小二乘问题。另外,该工具箱还提供了线性、

非线性最小化,方程求解,曲线拟合,二次规划等问题中大型课题的求解方法,为优化方法在工程中的实际应用提供了更方便快捷的途径。 9.1.1 优化工具箱中的函数 优化工具箱中的函数包括下面几类: 1.最小化函数 表9-1 最小化函数表 2.方程求解函数 表9-2 方程求解函数表

3.最小二乘(曲线拟合)函数 表9-3 最小二乘函数表 4.实用函数 表9-4 实用函数表 5.大型方法的演示函数 表9-5 大型方法的演示函数表

多目标优化实例和matlab程序

NSGA-II 算法实例 目前的多目标优化算法有很多, Kalyanmoy Deb 的带精英策略的快速非支配排序遗传算法(NSGA-II) 无疑是其中应用最为广泛也是最为成功的一种。本文用的算法是MATLAB 自带的函数gamultiobj ,该函数是基于NSGA-II 改进的一种多目标优化算法。 一、 数值例子 多目标优化问题 424221********* 4224212212112 12min (,)10min (,)55..55 f x x x x x x x x x f x x x x x x x x x s t x =-++-=-++-≤≤??-≤≤? 二、 Matlab 文件 1. 适应值函数m 文件: function y=f(x) y(1)=x(1)^4-10*x(1)^2+x(1)*x(2)+x(2)^4-x(1)^2*x(2)^2; y(2)=x(2)^4-x(1)^2*x(2)^2+x(1)^4+x(1)*x(2); 2. 调用gamultiobj 函数,及参数设置: clear clc fitnessfcn=@f; %适应度函数句柄 nvars=2; %变量个数 lb=[-5,-5]; %下限 ub=[5,5]; %上限 A=[];b=[]; %线性不等式约束 Aeq=[];beq=[]; %线性等式约束 options=gaoptimset('paretoFraction',0.3,'populationsize',100,'generations', 200,'stallGenLimit',200,'TolFun',1e-100,'PlotFcns',@gaplotpareto); % 最优个体系数paretoFraction 为0.3;种群大小populationsize 为100,最大进化代数generations 为200, % 停止代数stallGenLimit 为200, 适应度函数偏差TolFun 设为1e-100,函数gaplotpareto :绘制Pareto 前端 [x,fval]=gamultiobj(fitnessfcn,nvars,A,b,Aeq,beq,lb,ub,options)

简述基于MATLAB的优化设计

基于MATLAB 的曲柄摇杆机构优化设计 1. 问题的提出 根据机械的用途和性能要求的不同,对连杆机构设计的要求是多种多样的,但这些设计要求可归纳为以下三种问题:(1)满足预定的运动规律要求;(2)满足预定的连杆位置要求;(3)满足预定的轨迹要求。在在第一个问题里按照期望函数设计的思想,要求曲柄摇杆机构的曲柄与摇杆转角之间按照()f φ?=(称为期望函数)的关系实现运动,由于机构的待定参数较少,故一般不能准确实现该期望函数,设实际的函数为()F φ?=(称为再现函数),而再现函数一般是与期望函数不一致的,因此在设计时应使机构再现函数()F φ?=尽可能逼近所要求的期望函数()f φ?=。这时需按机械优化设计方法来设计曲柄连杆,建立优化数学模型,研究并提出其优化求解算法,并应用于优化模型的求解,求解得到更优的设计参数。 2. 曲柄摇杆机构的设计 在图 1 所示的曲柄摇杆机构中,1l 、2l 、3l 、 4l 分别是曲柄AB 、连杆BC 、摇杆CD 和机架AD 的长度。这里规定0?为摇杆在右极限位置0φ时的曲柄起始位置角,它们由1l 、2l 、3l 和4l 确定。 图1 曲柄摇杆机构简图 设计时,可在给定最大和最小传动角的前提下,当曲柄从0?转到090??+时,要求摇杆的输出角最优地实现一个给定的运动规律()f ?。这里假设要求: ()()2 0023E f φ?φ??π ==+ - (1)

对于这样的设计问题,可以取机构的期望输出角()E f φ?=和实际输出角 ()F φ?=的平方误差之和作为目标函数,使得它的值达到最小。 2.1 设计变量的确定 决定机构尺寸的各杆长度1l 、2l 、3l 和4l ,以及当摇杆按已知运动规律开始运行时,曲柄所处的位置角0?应列为设计变量,即: []12340T x l l l l ?= (2) 考虑到机构的杆长按比例变化时,不会改变其运动规律,通常设定曲柄长度 1l =1.0,在这里可给定4l =5.0,其他杆长则按比例取为1l 的倍数。若取曲柄的初始 位置角为极位角,则?及相应的摇杆l 位置角φ均为杆长的函数,其关系式为: ()()()()222221243230124225arccos 210l l l l l l l l l l l l ?????++-+-+==????++???????? (3) ()()22222124323034325arccos 210l l l l l l l l l l ????? +--+--==???????????? (4) 因此,只有2l 、3l 为独立变量,则设计变量为[][]2312T T x l l x x ==。 2.2目标函数的建立 目标函数可根据已知的运动规律与机构实际运动规律之间的偏差最小为指标来建立,即: ()()2 1min m Ei i i f x φφ==-→∑ (5) 式中,Ei φ-期望输出角;m -输出角的等分数;i φ-实际输出角,由图 1 可知: ()()02i i i i i i i παβ?πφπαβπ?π--≤≤??=?-+≤≤?? (6) 式中,222222322132arccos arccos 22i i i i i r l l r x x rl r x α???? +-+-== ? ????? (7) 222241424arccos arccos 210i i i i i r l l r rl r β???? +-+== ? ????? (8) i r == (9) 2.3约束条件

matlab在优化设计中的应用

m a t l a b在优化设计中的 应用 The Standardization Office was revised on the afternoon of December 13, 2020

Matlab 在优化设计中的应用 摘 要 常见的优化问题包括线性规划、无约束优化、约束优化、最下二乘优化、多目标规划等。本文研究了matlab 在这些常见优化问题中的应用及求解。 在进行研究本课题之前,我们先通过网络、电子书刊等各种有效渠道获取我们所需信息,在充分了解与熟练掌握了各种优化问题的具体特点及性质后,我们给出了关于如何用matlab 进行多类优化问题的求解基本方法,在此前提下,为了体现该软件在这些优化领域的实际应用效果,我们结合若干个优化问题的实例进行分析、建模、以及运用matlab 编程求解,在求解过程中,通过得到的精确数据和反应结果的图例,我们了解到matlab 工具箱的功能强大,是处理优化问题的非常方便的编程工具。 关键词:matlab 优化问题 二、基本概念 线性规划 线性规划是优化的一个重要分支。它在理论和算法上都比较成熟,在实际中有广泛的应用。例如数学表达形式: ???? ? ??? ?=≥=+++=+++=++++++n i x b x a x a x a b x a x a x a b x a x a x a t s x c x c x c i m n mn m m n n n n n n ,,2,1,0..min 221 122222121112121112211

在MTLAB 提供的优化工具箱中,解决规划的命令是linprog ,它的调用格式如下, ),,(b A c linprog x = 求解下列形式的线性规划: ?? ?≤b Ax t s x c T ..min ),,,,(beq Aeq b A c linprog x = 求解下面形式的线性规划: ?? ? ? ????=?≤beq x Aeq b Ax t s x c T ..min 若没有不等式约束b Ax ≤,则只需命令 [][],==b A 。 ),,,,,,(ub lb beq Aeq b A c linprog x = 求解下面形式的线性规划: ??? ?????? ? ??≤≤=?≤ub x lb beq x Aeq b Ax t s x c T ..min 若没有不等式约束b Ax ≤,则只需令[][],==b A ;若只有下界约束,则可以不用输入 ub 。 无约束优化算法 对于无约束优化问题,已经有许多有效的算法。这些算法基本都是迭代法,它们都遵循下面的步骤: ① 选取初始点x 0 ,一般来说初始点越靠近最优解越好;

MATLAB优化应用

methmodeltjut@https://www.sodocs.net/doc/0912757389.html, mathematica MATLAB优化应用 §1 线性规划模型 一、线性规划问题: 实例1:生产计划问题 假设某厂计划生产甲、乙两种产品,现库存主要材料有A类3600公斤,B 类2000公斤,C类3000公斤。每件甲产品需用材料A类9公斤,B类4公斤,C类3公斤。每件乙产品,需用材料A类4公斤,B类5公斤,C类10公斤。甲单位产品的利润70元,乙单位产品的利润120元。问如何安排生产,才能使该厂所获的利润最大。 建立数学模型: 设x1、x2分别为生产甲、乙产品的件数。f为该厂所获总润。 max f=70x1+120x2 s.t 9x1+4x2≤3600 4x1+5x2≤2000 3x1+10x2≤3000 x1,x2≥0 实例2:投资问题 某公司有一批资金用于4个工程项目的投资,其投资各项目时所得的净收益(投入资金百分比)如下表:工程项目收益表

由于某种原因,决定用于项目A的投资不大于其他各项投资之和而用于项目B和C的投资要大于项目D的投资。试确定该公司收益最大的投资分配方案。 建立数学模型: 设x1、x2 、x3 、x4分别代表用于项目A、B、C、D的投资百分数。 max f=0.15x1+0.1x2+0.08 x3+0.12 x4 s.t x1-x2- x3- x4≤0 x2+ x3- x4≥0 x1+x2+x3+ x4=1 x j≥0 j=1,2,3,4 实例3:运输问题 有A、B、C三个食品加工厂,负责供给甲、乙、丙、丁四个市场。三个厂每天生产食品箱数上限如下表: 四个市场每天的需求量如下表: 从各厂运到各市场的运输费(元/每箱)由下表给出: 求在基本满足供需平衡的约束条件下使总运输费用最小。 建立数学模型: 设a i j为由工厂i运到市场j的费用,x i j 是由工厂i运到市场j的箱数。b i 是工厂i的产量,d j是市场j的需求量。

用遗传算法优化BP神经网络的Matlab编程实例

用遗传算法优化BP神经网络的 Matlab编程实例 由于BP网络的权值优化是一个无约束优化问题,而且权值要采用实数编码,所以直接利用Matlab遗传算法工具箱。以下贴出的代码是为一个19输入变量,1个输出变量情况下的非线性回归而设计的,如果要应用于其它情况,只需改动编解码函数即可。 程序一:GA训练BP权值的主函数 function net=GABPNET(XX,YY) %-------------------------------------------------------------------------- % GABPNET.m % 使用遗传算法对BP网络权值阈值进行优化,再用BP 算法训练网络 %-------------------------------------------------------------------------- %数据归一化预处理 nntwarn off XX=premnmx(XX); YY=premnmx(YY); %创建网络 net=newff(minmax(XX),[19,25,1],{'tansig','tansig','purelin'},' trainlm'); %下面使用遗传算法对网络进行优化 P=XX; T=YY; R=size(P,1); S2=size(T,1); S1=25;%隐含层节点数 S=R*S1+S1*S2+S1+S2;%遗传算法编码长度 aa=ones(S,1)*[-1,1]; popu=50;%种群规模 initPpp=initializega(popu,aa,'gabpEval');%初始化种群 gen=100;%遗传代数 %下面调用gaot工具箱,其中目标函数定义为gabpEval [x,endPop,bPop,trace]=ga(aa,'gabpEval',[],initPpp,[1e-6 1 1],'maxGenTerm',gen,... 'normGeomSelect',[0.09],['arithXover'],[2],'nonUnifMutatio n',[2 gen 3]); %绘收敛曲线图 figure(1) plot(trace(:,1),1./trace(:,3),'r-'); hold on plot(trace(:,1),1./trace(:,2),'b-'); xlabel('Generation'); ylabel('Sum-Squared Error'); figure(2) plot(trace(:,1),trace(:,3),'r-'); hold on plot(trace(:,1),trace(:,2),'b-'); xlabel('Generation'); ylabel('Fittness'); %下面将初步得到的权值矩阵赋给尚未开始训练的BP网络 [W1,B1,W2,B2,P,T,A1,A2,SE,val]=gadecod(x); net.LW{2,1}=W1; net.LW{3,2}=W2; net.b{2,1}=B1; net.b{3,1}=B2; XX=P; YY=T; %设置训练参数 net.trainParam.show=1; net.trainParam.lr=1; net.trainParam.epochs=50; net.trainParam.goal=0.001; %训练网络 net=train(net,XX,YY); 程序二:适应值函数 function [sol, val] = gabpEval(sol,options) % val - the fittness of this individual % sol - the individual, returned to allow for Lamarckian evolution % options - [current_generation] load data2 nntwarn off XX=premnmx(XX); YY=premnmx(YY); P=XX; T=YY; R=size(P,1); S2=size(T,1); S1=25;%隐含层节点数 S=R*S1+S1*S2+S1+S2;%遗传算法编码长度 for i=1:S, x(i)=sol(i); end; [W1, B1, W2, B2, P, T, A1, A2, SE, val]=gadecod(x);

相关主题