use sim with an ode solver, stop time, and time step

2 ビュー (過去 30 日間)
Oliver Paleen
Oliver Paleen 2023 年 5 月 26 日
回答済み: Abhaya 2024 年 9 月 4 日
I want to use the sim command where I can set the ode solver, stop time, and time step so I can change these and compare the accurcary and time it takes to run each

回答 (1 件)

Abhaya
Abhaya 2024 年 9 月 4 日
Hi Oliver,
To configure the solver type, stop time, and time step for your model, you can use the Simulink.SimulationInput object. The Simulink.SimulationInput object enables you to modify model parameters.
For more information, please refer to the following documentation of Simulink.SimulationInput , https://www.mathworks.com/help/simulink/slref/simulink.simulationinput.html
Below is an example code that illustrates how to achieve the same,
% Load your model
modelName = 'your_model_name';
load_system(modelName);
% Create a SimulationInput object
simIn = Simulink.SimulationInput(modelName);
% Set the solver
simIn = simIn.setModelParameter('Solver', 'ode45');
% Set the fixed-step size (if using a fixed-step solver)
simIn = simIn.setModelParameter('FixedStep', '0.01');
% Set start and stop times
simIn = simIn.setModelParameter('StartTime', '0', 'StopTime', '10');
% Run the simulation
simOut = sim(simIn);
Hope this helps.

カテゴリ

Help Center および File ExchangeOrdinary Differential Equations についてさらに検索

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by