0

I have a simulink process model with a number of control inputs. I have modeled the process model using a number of susbsytems (m-file block in series and parallel), and the integration is done using an integrator for each subsystem.

I can run this model and get the states and outputs (Is is possible to programmatically play a Simulink model and measure its states?), but I would also like to be able to get the time derivative of the states sometimes.

For example, if I am running an optimal control problem , I need a function that programmatically returns the state variable derivatives to use as constraints. I would ideally be reusing the same model, but not using the simulink software for integration.

I suppose I could gather the input to every integrator in the model and use that as the derivative, but that is a horrible way to go about it (difficult to maintain, for starters).

Community
  • 1
  • 1

1 Answers1

0

i have the same problem when running simulink, you may find the following command useful:

[sys,x0,str,ts] = model([],[],[],'sizes');
[sys,x0,str,ts] = model([],[],[],'compile');
outputs = model(t,x,u,'outputs');
derivs = model(t,x,u,'derivs');
dstates = model(t,x,u,'update');
model([],[],[],'term');

for more details, you can refer to the page: https://www.mathworks.com/help/simulink/slref/model_cmd.html