How to Propagate sim using func 'model'? - Execute particular phase of simulation of model
1 view (last 30 days)
Show older comments
I want to propagate a simulink model step by step in each time step. which model contains continuous states, such as 2nd order dynamics.
'model' function usage is like as follows;
[sys,x0,str,ts] = model([],[],[],'sizes');
[sys,x0,str,ts] = model([],[],[],'compile');
outputs = model(t,x,u,'outputs');
derivs = model(t,x,u,'derivs');%for continuous states
dstates = model(t,x,u,'update');%for discrete states
model([],[],[],'term');
I tried to propagate the step as below
-----------------------------------------
[sys,x0,str,ts] = actuator([],[],[],'compile');
dt = 0.01;
t = [0 0.01 0.02 0.03 0.04 0.05];
u = [0 0 1 1 1 1 ];
x = x0;
for i = 1:6
y = actuator(t(i),x,u(i),'outputs');
dx = actuator(t(i),x,u(i),'derivs');
end
actuator([],[],[],'term');
----------------------------------------
BUT the problem is how to update the states dx, x during time increase?
To solve this problem I used euler update;
for i = 1:6
y = actuator(t(i),x,u(i),'outputs');
dx = actuator(t(i),x,u(i),'derivs');
x = x + dt. *dx
end
but I think it is not a proper method solving the simulink states.
Is there anyone knows to solve this problem in fancy way?
0 Comments
Answers (0)
See Also
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!