fmincon returns wrong length

3 ビュー (過去 30 日間)
K0ertis
K0ertis 2014 年 10 月 8 日
コメント済み: K0ertis 2014 年 10 月 8 日
Hi! I have a large Simulink- Modell in which I want to optimize two PI- controllers. My variables are x_1... x_4 such as:
x = [Kp_1 Ti_1 Kp_2 Ti_2];
[x,f,eflag,output] = fmincon(@fun,x0,[],[],[],[],lb,ub,@mynlconst,opts);
In my nonlinear constrains I added 20 constrains, for example:
function [c,ceq] = mynlconst(x)
ceq = [];
set_param(char([SimName '/CF/Kp_1']), 'Gain', 'x(1)');
set_param(char([SimName '/CF/Ti_1']), 'Gain', 'x(2)');
% Same for x(3) and x(4)
opts = simset('DstWorkspace','current','SrcWorkspace','base');
sim(SimName,Tend,opts);
c(1) = max(yout(:,1)) - MaxPX;
c(2) = -min(yout(:,1)) - MinPX;
c(3) = max(yout(:,3)) - MaxTX;
c(4) = -min(yout(:,3)) - MinTX;
c(5) = max(yout(:,5)) - MaxHX;
c(6) = -min(yout(:,5)) - MinHX;
|
c(20)= ...;
yout is a matrix from Simulink with the size (130,variables). As constrains I've used the max, min of the vector.
My optimazion function fun (To keep it simple I just wrote the necessary parts):
function y = fun(x)
set_param(char([SimName '/CF/Kp_1']), 'Gain', 'x(1)');
set_param(char([SimName '/CF/Ti_1']), 'Gain', 'x(2)');
% Same for x(3) and x(4)
opts = simset('DstWorkspace','current','SrcWorkspace','base');
sim(SimName,Tend,opts);
y = e'*e; % e= error, imput of controller
Somehow I get a vector x length 130, my Sample lengh :( I just want a optimized variable x legnth 4.
Any suggestions?
Thank you!

採用された回答

Alan Weiss
Alan Weiss 2014 年 10 月 8 日
What is your x0 input to fmincon? The returned solution x has the same size as x0.
Alan Weiss
MATLAB mathematical toolbox documentation
  4 件のコメント
K0ertis
K0ertis 2014 年 10 月 8 日
Did I wrote my functions in the correct form? For example mynlynconst: by writing 20 nonlinear constraints in this form?
Thank you
K0ertis
K0ertis 2014 年 10 月 8 日
Just found out that i overwrote x in my Simulink Modell. Thank you for your help!

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeNonlinear Control についてさらに検索

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by