Simulink Model
11 次查看(过去 30 天)
显示 更早的评论
I have a feedback loop in Simulink around an Embedded MATLAB block. My code in the block looks like this:
initvel=feedback(3)
dt=.02;
deltvel=commandvelocity-initvel;
accel=max(min(deltvel/dt,maxaccel),maxdecel)
updatevel=accel*dt
finalvel=initvel+updatevel
When I run my model, I look at the time and the values being updated. My output looks like this:
t =
0
initvel =
0
accel =
40
updatevel =
0.8000
finalvel =
0.8000
t =
0
initvel =
0
accel =
40
updatevel =
0.8000
finalvel =
0.8000
t =
0
initvel =
3.6029e+015
accel =
-20
updatevel =
-0.4000
finalvel =
3.6029e+015
I have an initial condition block in the feedback loop that sets the initial velocity to 0. I have two problems:
1. Why does it run through the simulation at time=0 several times?
2. Why does the initial velocity jump to 3.6e15?
回答(1 个)
Seth Popinchalk
2011-5-17
Models will evaluate blocks multiple times in the same time step when there are algebraic loops. Turn the algebraic loop diagnostic to Warning so you can see the message about what blocks are involved in the loop. You can also use the Simulink debugger with the command ashow to highlight the algebraic loop(s).
The reason the output of the block might change when evaluated at the same time step is that the algebraic loop solver is searching for a solution that satisfies the algebraic loop. This uses Newtons method to change the algebraic variable and hopefully find the solution. The solution from the last step is the starting point for the search in the next step. This can cause a change in the answer to something like 3.6e15 if the math in the model computes this value during the search.
0 个评论
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Simulink Functions 的更多信息
产品
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!