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

1 Ansicht (letzte 30 Tage)
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.

Antworten (1)

Lokesh
Lokesh am 23 Okt. 2023
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

Kategorien

Mehr zu Component-Based Modeling finden Sie in Help Center und File Exchange

Produkte


Version

R2020b

Community Treasure Hunt

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

Start Hunting!

Translated by