基于问题的非线性优化(MATLAB)的初始值

时间:2019-05-23 10:58:21

标签: matlab optimization solver

我已经编写了一些代码来在MATLAB中运行一个非常基本的非线性优化问题。我一直在关注他们的guide,但是在指定初始点时遇到了问题。这是我一直在使用的代码:

k1 = optimvar('k1', 'LowerBound', -5, 'UpperBound', 5);
k2 = optimvar('k2', 'LowerBound', -5, 'UpperBound', 5);
k3 = optimvar('k3', 'LowerBound', -5, 'UpperBound', 5);
f = optimvar('k4', 'LowerBound', -5, 'UpperBound', 5);

obj1 = fcn2optimexpr(@eq1, k1, k2, k3, f);
obj2 = fcn2optimexpr(@eq2, k1, k2, k3, f);

confn1 = obj1 == 0;
confn2 = obj2 == 0;
confn3 = 1/2*(-0.0581244*f - 1.2747*k1 - 2.20973*k2 - 2.52383*k3 - (0.0162586*f^2 - 0.00622076*f*k1 + 0.406664*k1^2 - 0.0475778*f*k2 + 1.41521*k1*k2 + 1.24684*k2^2 - 0.148724*f*k3 + 1.62991*k1*k3 + 2.9517*k2*k3 + 1.84751*k3^2)^(1/2)) <= 0;
confn4 = 1/2*(-0.0581244*f - 1.2747*k1 - 2.20973*k2 - 2.52383*k3 + (0.0162586*f^2 - 0.00622076*f*k1 + 0.406664*k1^2 - 0.0475778*f*k2 + 1.41521*k1*k2 + 1.24684*k2^2 - 0.148724*f*k3 + 1.62991*k1*k3 + 2.9517*k2*k3 + 1.84751*k3^2)^(1/2)) <= 0;

prob1 = optimproblem('Objective', obj1);
prob2 = optimproblem('Objective', obj2);

prob1.Constraints.confn1 = confn1;
prob1.Constraints.confn2 = confn2;
prob1.Constraints.confn3 = confn3;
prob1.Constraints.confn4 = confn4;

prob2.Constraints.confn1 = confn1;
prob2.Constraints.confn2 = confn2;
prob2.Constraints.confn3 = confn3;
prob2.Constraints.confn4 = confn4;

k10.k1 = 0;
k20.k2 = 0;
k30.k3 = 0;
f0.f = 0;

[sol, fval, exitflag, output] = solve(prob1, k10, k20, k30, f0)

function f1 = eq1(k1, k2, k3, f)
f1 = 0.01309 + 0.0297574*f + 1/3*(-1.02013*k1 - 1.78339*k2 - 2.10318*k3);
end

function f2 = eq2(k1, k2, k3, f)
f2 = 0.01309 + 0.0334722*f + 1/3*(-0.653523*k1 - 1.14525*k2 - 1.36932*k3);
end

我得到了错误:

  

使用optim.problemdef.OptimizationProblem / solve的错误   “ x0”无效。起始点必须包含变量“ k2”的值。

     

SymSolver中的错误(第32行)[sol,fval,exitflag,输出] =   解决(prob1,k10,k20,k30,f0)

我确定这只是语法问题,但我不知道这是什么。有什么建议么?谢谢:)

1 个答案:

答案 0 :(得分:2)

尝试

k0.k1 = 0;
k0.k2 = 0;
k0.k3 = 0;
k0.f = 0;
[sol, fval, exitflag, output] = solve(prob1, k0)