How can I optimize function output by tuning 3 input parameters?

I want to optimize a non-linear output (Pressures) by finding the best 3 input parameters (Kp,Kd,Ki).
An optimized output is a constrained output.
Attached an example for unconstrained output for the input (0.0001,0.0008,0.000002). Thats not optimized.
  • I have tried using fminimax. It did not go well because Preasures is a long scalar vector (1x300) while the input is 3 scalars.
  • I have tried using live editor optimization tool. It did not go well because I have 3 parameters to tune in order to find the best output.
  • Unfortunately I do not know the system transfer function so I can not use the tune controller.
Thanks in advance.
function [Pressures] = myFunc(Kp,Kd,Ki)
for i = 1:500
...
end
end

回答 (1 件)

Bjorn Gustavsson
Bjorn Gustavsson 2021 年 1 月 7 日

0 投票

You'll have to modify (at least for simplicity) your function to something like this:
function [Pressures] = myFunc(KpKdKi)
Kp = KpKdKi(1);
Kd = KpKdKi(2);
Ki = KpKdKi(3);
for i = 1:500
...
end
end
Then you can use fminimax or some of the other optimization-functions. The important point is to combine all the input parameters into one array - that is the format the optimization-tools expect things to have.
HTH

4 件のコメント

Yossef Yossefi
Yossef Yossefi 2021 年 1 月 7 日
First of all, thank you for your answer.
Second, you are right. I have tried changing the input to a raw vector of 3 scalars. It did not help me to get an optimized output. I might have not used the function fminimax correctly.
I have tried the following code. I get an error 'not enough input argument'.
KpKdKi = [Kp, Kd, Ki];
x = fminimax(mainProgram,KpKdKi) ;
function [Pressures] = myFunc(KpKdKi)
Kp = KpKdKi(1);
Kd = KpKdKi(2);
Ki = KpKdKi(3);
for i = 1:500
...
end
end
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 1 月 7 日
In that version you try to optimize a function mainProgramme. You want to run fminimax on myFunc. I'd do something like this:
KpKdKi_best = fminimax(@(pars) myFunc(pars),KpKdKi);
In that call to fminimax a function-handle is used, this is a preferable way of doing this.
HTH
Yossef Yossefi
Yossef Yossefi 2021 年 1 月 7 日
Ok I see, it worked.
Thank you very much :)
Bjorn Gustavsson
Bjorn Gustavsson 2021 年 1 月 7 日
My pleasure.

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

カテゴリ

タグ

質問済み:

2021 年 1 月 7 日

コメント済み:

2021 年 1 月 7 日

Community Treasure Hunt

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

Start Hunting!

Translated by