matlab计算三元函数最大值f=(1-x)^3+(1-y)^3+(2-z)^3,其中1

问题描述:

matlab计算三元函数最大值
f=(1-x)^3+(1-y)^3+(2-z)^3,其中1

close all
clear,clc
f = @(x) (1-x(1))^3+(1-x(2))^3+(2-x(3))^3
lb = [1; 1; 1]; % x y z的下限
ub = [3; 3; 3] ; % x y z的上限
A = [1 -1 0;0 1 -1];
b = [0;0];
x0 = [1.5;1.5;1.5]; % Starting guess at the solution
[x1,fval1] = fmincon(f,x0,A,b,[],[],lb,ub);
xmax2 = x1(1) % 极值点x的值
ymax2 = x1(2) % 极值点y的值
zmax2 = x1(3) % 极值点z的值
fmax2 = fval1 % f的最小值
计算结果:
xmax2 = 3
ymax2 = 3
zmax2 = 3
fmax2 =-17