Solving quadratic optimization problem in Simulink and code generation - Different behavior in Matlab?
5 ビュー (過去 30 日間)
古いコメントを表示
Hello,
I'm experimenting with solving quadratic optimization problems (about 400 variables and only equality constraints) in Simulink using Matlab function blocks. Basically, I tried 2 approaches:
First, I formulated the matrix and vector of the resulting linear equation system and solved it:
%H: Weighting matrix of the problem
%f: Weighting vector of the problem
%Aeq: Matrix of equality constraints
%beq: Vector of equality constraints
Atmp = [H,Aeq';Aeq,zeros(size(Aeq,1),size(Aeq,1))];
btmp = [-f;beq];
Solution = Atmp\btmp;
Executing this code in matlab delivers a warning of a bad conidtioned matrix but I get the right solution of the problem. Executing this code in Simulink with putting it into a Matlab function block delivers no solution (only NaN's) and also a warning of a bad condition.
Second, I tried to solve the problem using quadprog():
options = optimoptions('quadprog','algorithm','active-set');
[Solution,fval,exitflag,output] = quadprog(H,f,[],[],Aeq,beq,[],[],zeros(length(H),1),options);
Again, I first executed this in Matlab where I got the right result in 2 iterations and an acceptable computation time. Executing this code inside a function block in Simulink I also get a result (exitflag = 1), but the solution is nonsense and it's not solving my original problem.
Does anyone here has a guess for explaining the observed behavior? What is there to consider when solving numerical problems in Matlab function blocks in Simulink? Could it have something to do with the automatic code generation (missing libraries etc.) or is it a execution time problem? I execute the Simulink model with a fixed time step of 1 s, the problem solving should not need more than some ms.
Thank you very in advance!
Cheers,
Clemens
0 件のコメント
回答 (1 件)
Matt J
2021 年 8 月 5 日
編集済み: Matt J
2021 年 8 月 5 日
Well, the problem is what the warning message told you - the conditioning of the problem is poor needs and needs to be improved if you hope to have a unique solution. It is likely that both quadprog solutions are valid, which you can verify by looking at the fval output in both cases. You should see that both are approximately the same, meaning that both solutions are solving the minimization problem that you are providing.
参考
カテゴリ
Help Center および File Exchange で Quadratic Programming and Cone Programming についてさらに検索
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!