matlab中约束条件非线性,求目标函数(线性)最大值怎么做?

2024-11-02 08:40:14
推荐回答(2个)
回答1:

脚本如下:
fun = @(t)-(183545*t-367490003);
lb = 2004;
ub = 2030;
t0 = 2015;
x = fmincon(fun,t0,[],[],[],[],lb,ub,@c)
起始值t0随便写一个。
另外在c.m中定义非线性约束函数:
function [c,ceq] = c(t)
c = 462.2*t.^2-2e6*t+2e9; % nonlinear inequalities at x.
ceq = 0; % nonlinear equalities at x.
运行结果2030。

回答2:

function [c ceq]=mycon1(x)
c=462.2*x^2-2e6*x+2e9;
ceq=[];
上面程序保存为mycon1.m
f=@(x)-183545*x+367490003;fmincon(f,[2005],[],[],[],[],[2004],[2030],@mycon1)
结果:
ans =
2030
即t=2030时得最大值