Matlab線性 非線性規劃優化演算法(5)

2021-10-02 09:58:07 字數 2351 閱讀 7077

值得單獨一說的是fminunc, fminseach, fminbnd的區別:

fminunc只能用於求解連續函式,對於變數沒有限制

fminbnd只能用於求解單變數函式,

fminsearch只能用於求解多變數函式,

%

%clc

clear all

fun = @(x)

-abs(1

/x);

x0 =1;

x1=-3;

x2 =

3;

我們解這個函式的最值,在0出可以取到最值,但函式在0處沒有導數:

[x,fval,exitflag,output]

=fminbnd

(fun,x1,x2)

[x,fval,exitflag,output]

=fminsearch

(fun,x0)

[x,fval,exitflag,output]

=fminunc

(fun,x0)

求解這個函式,可以看到結果:

x =

8.8818e-16

fval =

-1.1259e+15

exitflag =

1output =

struct with fields:

iterations:

17 funccount:

18 algorithm:

'golden section search, parabolic interpolation'

message:

'optimization terminated:↵ the current x satisfies the termination criteria using options.tolx of 1.000000e-04 ↵'

exiting: maximum number of function evaluations has been exceeded

- increase maxfunevals option.

current function value:

-1267650600228229401496703205376.000000

x =7.8886e-31

fval =

-1.2677e+30

exitflag =

0output =

struct with fields:

iterations:

100 funccount:

200 algorithm:

'nelder-mead ******x direct search'

message:

'exiting: maximum number of function evaluations has been exceeded↵ - increase maxfunevals option.↵ current function value: -1267650600228229401496703205376.000000 ↵'

solver stopped prematurely.

fminunc stopped because it exceeded the function evaluation limit,

options.maxfunctionevaluations =

1.000000e+02

.x =

2.2204e-16

fval =

-4.5036e+15

exitflag =

0output =

struct with fields:

iterations:

1 funccount:

101 stepsize:

1.0000

lssteplength:

1.0000

firstorderopt:

3.0223e+23

algorithm:

'quasi-newton'

message:

'↵solver stopped prematurely.↵↵fminunc stopped because it exceeded the function evaluation limit,↵options.maxfunctionevaluations = 1.000000e+02.↵↵'

只有fminbnd的exitflag是1, 其他兩個都是0, 因為這是乙個單變數函式,所以fminsearch不能使用,又因為在0出不可導,所以fminunc也不能使用。

Matlab非線性規劃

在matlab非線性規劃數學模型可以寫成一下形式 minf x s.t.begin ax le b aeq x beq c x le 0 ceq x 0 end f x 為目標函式,a,b,aeq,beq為線性約束對應的矩陣和向量,c x ceq x 為非線性約束。matlab求解命令為 x fmi...

Matlab線性 非線性規劃優化演算法(7)

介紹如何使用quadprog and mpcqpsolver.依然是解決一類典型的二次規劃問題 通過看matlab文件中的例子可以基本了解如何使用。下面給出幾個例子 quadprog the use of quadprog h 1 1 1 2 f 2 6 a 11 12 21 b 2 2 3 x,f...

Matlab 線性與非線性規劃

matlab的運籌與決策問題 線性規劃問題 函式 linprog f,a,b,aep,bep,lb,ub 引數分析 f 目標函式的係數排列 a 約束條件的係數矩陣 b 約束條件的增廣矩陣的結果 aep 等式的係數矩陣 bep 等式的結果矩陣 lb 所求解的最小值 ub 所求解的最大值 非線性規劃問題...