# How can I apply bayesopt to my Simulink model?

6 ビュー (過去 30 日間)
Elia Bontempelli 2021 年 11 月 2 日
コメント済み: Elia Bontempelli 2021 年 11 月 2 日
Dear all,
I'm doing a thesis about semi-active suspension, systems that can only change the viscous damping coefficient of the shock absorber. The case that I'm studying is with magneterheological damper, which is a damper filled with magneterheological fluid. This kind of fluid can change viscosity changing the magnetic field.
I did in Simulink the quarter car model, now my purpose is to find the best value of my control variable "u_MR" (constant value), that maximize the passenger comfort. The comfort is evaluated with the index of performance "J", calculated as the RMS of the (vertical) acceleration, which is the final output of my model.
Thus, the problem is to find the optimal value of uMR that minimize the index "J" using the Bayesian Optimization and in Matlab the function bayesopt().
I'm finding problems writing the objective function, input of the bayesopt function...
The other input of bayesopt() is the variable:
uMR_opt = optimizableVariable('uMR',[0,f_max]);
I have the acceleration, which is a vector, result of the simulation that I can extract in Matlab and than I can calculate the index "J" (which is a single value, e.g. J = 1.6 m/s^2), but than I don't know how to write the objective function, related to this.
out = sim("quarter_car_model.slx");
%extracting the acceleration from simulink
output_xs2punti = getElement(out.yout, 'xs_2punti');
xs_2punti = output_xs2punti.Values.Data(:);
J_sim = rms(xs_2punti); %index of performance
Any suggestion on how to do the objective function?
Thanks to all

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

### 採用された回答

Alan Weiss 2021 年 11 月 2 日
As the documentation states, the objective function accepts a 1-by-D table of values, where D is the number of variables. So you need to write your objective function like this:
function J_sim = fun(x)
xval = x.uMR; % x is a table, xval is a scalar represending the uMR value
% Call your simulation with xval as the uMR value. Then
output_xs2punti = getElement(out.yout, 'xs_2punti');
xs_2punti = output_xs2punti.Values.Data(:);
J_sim = rms(xs_2punti); %index of performance
end
Alan Weiss
MATLAB mathematical toolbox documentation
##### 3 件のコメント表示非表示 2 件の古いコメント
Elia Bontempelli 2021 年 11 月 2 日
It works perfect, thank you very much!!

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

R2019b

### Community Treasure Hunt

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

Start Hunting!