matlab解二次規劃,matlab解二次規劃

2021-03-03 20:27:41 字數 6261 閱讀 2659

1樓:燭龍一現

沒有源**,如何說明問題啊。貼一下你的m檔案和錯誤提示,這個光靠看是無法回答的

matlab求解二次規劃問題 5

2樓:匿名使用者

題主給出的用matlab求解二次規劃問題,執行結果總是求lambda負無窮大,x,y近於零。分析和執行題主的**,其根本的錯誤是缺少lambda變數的下限值,應該為vlb=[0;0;0];再一個問題沒有利用x+y=7的等式條件,應該可以這樣來補充,aeq=[1,1,0];beq=[7];

糾正上述錯誤,後執行可以得到如下的解。

k1 = 3.0071 %x

k2 = 3.9929 %y

k3 = 0.995 %λ

fval = -13.016

matlab 求解二次規劃

3樓:匿名使用者

lingo的確可以解二次規劃,如果想讓某變數x只能取值0-1的話,用@bin(x)即可

我寫個最簡單的例子

--------------------------------

min x1^2+3*x2-x3+4*x^2

s.t. x1+x2-x3-x4>0

x1*x2=-6

x1>3

x2∈r

x3>=0

x4∈-----------------------------------

lingo程式的寫法(最簡單的寫法)

-----------------------------------

model:

min=x1^2+3*x2-x3-4*x4^2;

x1+x2-x3-x4>0;

x1*x2=-6;

x1>3;

@free(x2);! 感嘆號後面的是說明語句。lingo預設變數均為非負的。free表示該變數無約束範圍。

@bin(x4);!bin表示該變數為0-1變數。

end------------------------------------

執行後即可得到解答。

關於lingo更進一步的用法請參閱相關教程,這裡從略。

4樓:匿名使用者

是整數規劃?

lingo不是解線性規劃的麼?

能把問題說的清楚些麼?

matlab有個最優化工具箱(optimization tools),裡面有個單獨解二次規劃的模組。

二次規劃是np-hard問題,一般來講,變數超過一定尺度(14個)就不能在有限的時間內解決了。

請大神幫忙用matlab解一下二次規劃問題,謝謝

5樓:我行我素

可這樣:

f=@(x)-702.5*x(1)*x(2)-750*x(1)*x(4)-625*x(2)*x(3)-350*x(2)*x(4);

a=[700,450,0,0;0,0,762.5,525];b=[200;150];

aeq=[1,1,0,0;0,0,1,1];beq=[1;1];lb=zeros(4,1);[x,f]=fmincon(f,ones(4,1)*0.5,a,b,aeq,beq,lb)

結果是:

x =0.1392

0.8608

0.0000

1.0000

f =-489.8553

也就是,x1=0.1392,x2=0.8608,y1=0,y2=1,maxf=489.8553

matlab二次規劃問題

6樓:兔子和小強

這個優化目標不是二次型、約束也不是線性約束,無法用quadprog求解,可以考慮用fmincon來解。

新建個mycon.m檔案,裡面的內容是:

function [c, ceq] = mycon(x)

u = [3.6 0.8 28 8.3 8.3 3.9 5.5]';

l = [2.6 0.7 17 7.3 7.3 2.9 5.0]';

% 25個不等式約束

c = [27 - x(1)*x(2)^2*x(3);

397.5 - x(1)*x(2)^2*x(3)^2;

1.93*x(4)^3 - x(2)*x(3)*x(6)^4;

1.93*x(5)^3 - x(2)*x(3)*x(7)^4;

sqrt((745*x(4)/x(2)/x(3))^2 + 16.9e6) - 110*x(6)^3;

sqrt((745*x(5)/x(2)/x(3))^2 + 157.5e6) - 85*x(7)^3;

x(2)*x(3) - 40;

x(1) - 12*x(2);

5*x(2) - x(1);

x - u;

l - x;

1.5*x(6)+1.9 - x(4);

1.1*x(7)+1.9 - x(5)];

% 等式約束

ceq = ;

end呼叫的程式是:

%% 最優化目標函式f

f = @(x)0.7854*x(1)*x(2)^2*(3.3333*x(3)^2+14.

9334*x(3)-43.0934)-1.508*x(1)*(x(6)^2+x(7)^2) + 7.

477*(x(6)^3+x(7)^3)+0.7854*(x(4)*x(6)^2+x(5)*x(7)^2);

x = fmincon(f, ones(7,1), ,,,,,, @mycon, optimset('display', 'off'))

f(x)

解出來的值與你的最終答案基本一樣,除了x(5)=7.7以外。

你所貼的最終答案是錯的,如果x(5) = 7.3,那麼g25約束無法滿足。

7樓:匿名使用者

約束條件非線性,quadprog做不了吧

這些啥意思? g8(x) ----- : g9(x)

急求一份用matlab求解二次規劃問題的**。

8樓:匿名使用者

樓上正解,不過用doc+quadprog或者helpwin+quarprog介面更好。

以下是help+quadprog得到的用法,英文不懂的查字典…

採納吧~少年~

我最近在研究matlab的平行計算~哦吼吼

quadprog quadratic programming.

x=quadprog(h,f,a,b) attempts to solve the quadratic programming problem:

min 0.5*x'*h*x + f'*x subject to: a*x <= b

xx=quadprog(h,f,a,b,aeq,beq) solves the problem above while additionally

satisfying the equality constraints aeq*x = beq.

x=quadprog(h,f,a,b,aeq,beq,lb,ub) defines a set of lower and upper

bounds on the design variables, x, so that the solution is in the

range lb <= x <= ub. use empty matrices for lb and ub

if no bounds exist. set lb(i) = -inf if x(i) is unbounded below;

set ub(i) = inf if x(i) is unbounded above.

x=quadprog(h,f,a,b,aeq,beq,lb,ub,x0) sets the starting point to x0.

x=quadprog(h,f,a,b,aeq,beq,lb,ub,x0,options) minimizes with the default

optimization parameters replaced by values in the structure options, an

argument created with the optimset function. see optimset for details.

used options are display, diagnostics, tolx, tolfun, hes**ult, largescale,

maxiter, precondbandwidth, typicalx, tolpcg, and maxpcgiter. currently,

only 'final' and 'off' are valid values for the parameter display ('iter'

is not available).

x=quadprog(hinfo,f,a,b,aeq,beq,lb,ub,x0,options,p1,p2,...) passes the

problem-dependent parameters p1,p2,... directly to the hmfun function

when optimset('hes**ult',hmfun) is set. hmfun is provided by the user.

pass empty matrices for a, b, aeq, beq, lb, ub, xo, options, to use the

default values.

[x,fval]=quadprog(h,f,a,b) returns the value of the objective function at x:

fval = 0.5*x'*h*x + f'*x.

[x,fval,exitflag] = quadprog(h,f,a,b) returns an exitflag that describes the

exit condition of quadprog. possible values of exitflag and the corresponding

exit conditions are

1 quadprog converged with a solution x.

3 change in objective function value **aller than the specified tolerance.

4 local minimizer found.

0 maximum number of iterations exceeded.

-2 no feasible point found.

-3 problem is unbounded.

-4 current search direction is not a direction of descent; no further

progress can be made.

-7 magnitude of search direction became too **all; no further progress can

be made.

[x,fval,exitflag,output] = quadprog(h,f,a,b) returns a structure

output with the number of iterations taken in output.iterations,

the type of algorithm used in output.algorithm, the number of conjugate

gradient iterations (if used) in output.cgiterations, a measure of first

order optimality (large-scale method only) in ouput.firstorderopt, and the

exit message in output.message.

[x,fval,exitflag,output,lambda]=quadprog(h,f,a,b) returns the set of

lagrangian multipliers lambda, at the solution: lambda.ineqlin for the

linear inequalities a, lambda.eqlin for the linear equalities aeq,

lambda.lower for lb, and lambda.upper for ub.

用Matlab求解凸二次規劃問題

凸二次規劃。也可以用fmincon函式,你寫了你的 還沒寫你的問題 急求一份用matlab求解二次規劃問題的 max f x1,x2 x1x2 3sub.to x1 x2 2 0 解 化成標準形式 sub.to x1 x2 2 在matlab中實現如下 h 0,1 1,0 f 0 0 aeq 1 1...

怎麼解二次函式

一 理解二次函式的內涵及本質 二次函式 y ax2 bx c a 0 a b c 是常數 中含有兩個變數 x y 我們只要先確定其中一個變數,就可利用解析式求出另一個變數,即得到一組解 而一組解就是一個點的座標,實際上二次函式的圖象就是由無數個這樣的點構成的圖形 二 熟悉幾個特殊型二次函式的圖象及性...

用二次函式解該問題

解 x x1 x x2 x xn nx 2x x1 x2 xn x1 x2 xn n x 2x x1 x2 xn n x1 x2 xn n x x1 x2 xn n x1 x2 xn n x1 x2 xn 則當x x1 x2 xn n時,取最小值,最小值為 x1 x2 xn x1 x2 xn n y...