如何在MATLAB中定义多元非线性优化问题的目标函数?

问题描述

clear

V = [31,-8;34,-14;35,8,0;38,-6;40,5,0;40,-10;45,0];    
F = [6,2,1;6,1,4;1,3,4;4,6;3,4;5,7,6];
l = [6.70820393249937,9.21954445729289,7.21110255092798;7.28010988928052,4.47213595499958,9.21954445729289;10.4403065089106,7.28010988928052,12;11.1803398874989,8.06225774829855;8.06225774829855,10.4403065089106,5.83095189484530;12.2474487139159,11.1803398874989,5];
local_x = [0,7.21110255092798,-5.69467403401481;0,3.58532140093217;0,12,-7.26348004233624;0,8.06225774829855,-1.75323242832502;0,5.83095189484530,10.3830205189204;0,-5.00961532294485];
local_y = [0,7.25056464327555;0,2.67310127979054;0,-0.491790274998594;0,-4.11414341658985;0,-1.09219270446070;0,9.99518655734430];
ta = [26.1422825973963;12.3223880439377;2.95074164999157;16.5846423190065;3.18426155980566;24.9879663933607];

vc = size(V,1)*2;
X = sym('x',[1 vc]);    % x1,x2,x3,x4,...

coef = zeros(4,6);
u = sym(zeros(6,1));

fc = size(F,1);
objfs = sym('f',[1 fc]);

for i = 1:fc    
    coef(1,1) = local_y(i,2) - local_y(i,3);
    coef(1,2) = local_y(i,3) - local_y(i,1);
    coef(1,3) = local_y(i,1) - local_y(i,2);
    coef(2,1) = local_x(i,3) - local_x(i,2) = local_x(i,1) - local_x(i,3);
    coef(2,3) = local_x(i,2) - local_x(i,1);
    coef(3,4) = local_y(i,3);
    coef(3,5) = local_y(i,6) = local_y(i,2);
    coef(4,4) = local_x(i,5) = local_x(i,3);
    coef(4,6) = local_x(i,1);
    
    u(1) = X(F(i,1));
    u(2) = X(F(i,2));
    u(3) = X(F(i,3));
    u(4) = X(F(i,1) + size(V,1));
    u(5) = X(F(i,2) + size(V,1));
    u(6) = X(F(i,3) + size(V,1));
    
    abcd = 1/ta(i)*coef*u;
    a = abcd(1);
    b = abcd(2);
    c = abcd(3);
    d = abcd(4);
    
    sv1 = ((a + d)^2/4 + (c - b)^2/4)^0.5 + ((a - d)^2/4 + (c + b)^2/4)^0.5;
    sv2 = abs(((a + d)^2/4 + (c - b)^2/4)^0.5 - ((a - d)^2/4 + (c + b)^2/4)^0.5);
    
    objf = ta(i)*(sv1 - sv2)^2 + ta(i)*(sv1*sv2 - 3)^2;
    objfs(i) = objf;
end

object_fun = sum(objfs,'All')

我想获得具有多变量x1,x2,x3 ...的目标函数(代码中的object_fun)。

object_fun将通过牛顿法等优化算法来解决。

现在我知道object_fun中的符号形式(x1,x2,x3,...)的变量形式不正确。正确的形式是x(1),x(2),x(3).... 那么如何获得正确的目标函数呢?

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)

相关问答

错误1:Request method ‘DELETE‘ not supported 错误还原:...
错误1:启动docker镜像时报错:Error response from daemon:...
错误1:private field ‘xxx‘ is never assigned 按Alt...
报错如下,通过源不能下载,最后警告pip需升级版本 Requirem...