1. 程式人生 > >matlab非線性規劃(含有多次方或者其他函式的目標函式)

matlab非線性規劃(含有多次方或者其他函式的目標函式)

對於以下的非線性規劃問題:


我們可以先分別建立兩個函式:fun1,fun2檔案

fun1:

function f = fun1(x);

f = x(1)^2+x(2)^2+8;

fun2:

function [g,h]= fun2(x);
g = -x(1)^2+x(2);

h = -x(1)-x(2)^2+2;

最後的測試函式:

options = optimset;
[x,y] = fmincon('fun1',rand(2,1),[],[],[],[],zeros(2,1),[],...

    'fun2',options)

可得到結果:


當X1 = 1=X2時候得到最值最小y = 10 。