Adjustment of a simulation model by optimization of parameters

18 ビュー (過去 30 日間)
Ainara Ramos
Ainara Ramos 2020 年 4 月 2 日
コメント済み: Max 2023 年 11 月 27 日
I have a Simulink multibody model which depend on some uncertain parameters. I want to adjust them by using experimental data, so I pretend to give them diferent values on a range until simulation results are the same as experimental ones (or very close to them), in a iterative way. This is the algorithm I have on my mind:
  • Give a value to uncertain variables
  • Run the simulation model in Simulink
  • Take some examples of the simulation results
  • Compare them with experimental results
  • Repite the cycle unti the results of the simulation are the same as experimental
I know there are optimization tools and functions on Matlab, but I don't know how to choose the appropriate one, neither how to configurate them. Could I do it using this optimization tool or is it better to do it programming by code?
Could someone recommend me a method, tool, function, tutorial or something to help me doing this adjustment? Has anyone an example of something similar to this? I would be great if i could see it.
Thank you in advance. Best regards,
Ainara

採用された回答

Ameer Hamza
Ameer Hamza 2020 年 4 月 2 日
If your model runs very fast, then you can use an optimization function such as fmincon to optimize the parameter. Something like this will work
fmincon(@objFun, rand(a,1));
function y = objFun(x)
% change values of x to your parameter names
sinOut = sim('modelName');
% calculate the fitness of the parameters using the simulation data
end
However, fmincon can take several hundred or thousands function evaluations to reach an optimal solution, so try this only if your model runs fast.
The other approach is to use the batch simulation features provided by the Simulink. See these links for details.
  2 件のコメント
L.Schuring
L.Schuring 2022 年 4 月 7 日
編集済み: L.Schuring 2022 年 4 月 7 日
Hi Ameer (or anyone who would like to answer),
I am having difficulty following your example for using fmincon. Could you elaborate more? I am specifically having trouble understanding how to pass the parameters I want to optimize between my simulink model and fmincon. Here's a distillation of my scripting, so hopefully we can identify where my misunderstanding lies:
I am working on a spring-mass-damper system in simulation. I would like to optimize the spring constant and damping coefficient in my simulation to experimental data by minimizing the root mean square error (rmse) of the simulation values and experimental values. I have initial guesses for the spring and damping parameters, and upper and lower bounds for each.
% k.k0 = initial guess for spring constant
% k.lb = lower-bound for spring constant
% k.up = upper-bound for spring constant
% c.c0 = initial guess for damping constant
% c.lb = lower-bound for damping constant
% c.up = upper-bound for damping constant
x = fmincon(@objfun, [k.k0,c.c0], [],[],[],[],[k.lb,c.lb],[k.ub,c.ub]);
function rmse = objfun(x)
% load experimental data
load('expdata.mat')
% set the spring constant and damping coeff:
% This is where I am stuck. I don't understand how to call on the
% values that fmincon feeds for the parameter optimization
params.k = x(1);
params.c = x(2);
% Simulate model
out = sim('SpringMassDamperSystem')
% SpringMassDamperSystem.slx looks for params.k and params.c to feed them
% into my spring and damper blocks. The way I have this function set up
% currently, it is unable to find params.k and params.c
% I then calculate the rmse here between the simulation and experimental data.
rmse = rmsefun(out.predicted, expdata.actual)
end
function rmse = rmsefun(actual, predicted)
err = (actual-predicted);
rmse = sqrt(mean(err.^2));
end
Where am I messing up that you can see? Let me know if there is any more information that I did not provide here that could be beneficial for troubleshooting. Thank you!
Max
Max 2023 年 11 月 27 日
Were you able to solve your problem? I am trying to do more or less the same and am also encountering some difficulties.
Thanks!

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

その他の回答 (0 件)

カテゴリ

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

Community Treasure Hunt

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

Start Hunting!

Translated by