How to switch a variant model on the basis of the ssimulation solver in use?

1 次查看(过去 30 天)
I have two protected models one for RK4 and one for Euler.
I would like to create a variant system which selects the correct one on the basis of the solver selected in the simulation pane.
How can I do that?
The model is a referenced one run in accelerator mode and I would like it to be recompiled only if the solver is changed between two simulations.

回答(1 个)

Lokesh
Lokesh 2023-10-23
Hi Andrea,
I understand that you want to switch a variant model based on the solver selected in the simulation pane.
You can use the get_param(gcs, 'Solver') command to retrieve the solver selected in the simulation pane. Please refer to the following steps to switch a variant model based on the solver:
  • Create a variant subsystem and include the protected models for both the RK4 and Euler solvers.
  • Select the variant subsystem and access the "Block Parameters" dialog.
  • In the "Variant Choices" section, choose the "RK4" model and set the "Variant control expression" field to (get_param(gcs, 'Solver')=="ode4"). This expression will check if the solver selected in the simulation pane is set to "ode4" (Runge-Kutta). Similarly, set the condition for "Euler" model.
  • Save and close the variant subsystem.
When you run the simulation, the variant subsystem will select the appropriate model.
Please refer to the following MATLAB documentation links to know more aboutget_param” function and variant subsystems:
I hope you find this helpful.
Best Regards,
Lokesh

类别

Help CenterFile Exchange 中查找有关 Component-Based Modeling 的更多信息

产品


版本

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by