Initial Condition block does not output as intended at start of simulation - simulink

The simulation below is a bouncing ball model. Instead of wiring State port to the determine Initial condition, I wired integrator output. The result after first time step is shown and the output from Initial condition block is zero. Why ?

When stepping through the model, at the bottom of the model there is a hyperlink to View diagnostics. In the diagnostics you'll see the message:
Detected algebraic loop path(s) through integrator reset or IC ports.
Results may not be intuitive (see documentation). Use integrator state
port to avoid algebraic loops.
Note the Results may not be intuitive part. Basically the algebraic loop solver is overriding the IC block, and you need to use the state-port for the feedback to the initial condition.

Related

Solving an Algebraic Loop in Simulink using an Initial Value

I am building a circuit model for a transformer which models the effects of hysteresis. It does so using the Matlab function block on the right, and works successfully when tested in isolation. However, the value of the magnetising inductance Lm depends on calculations requiring the value of Im. But Simulink cannot determine the value of Im without the value of Lm, thus forming an algebraic loop.
However, I have the initial value for the inductance, Lm_initial loaded into the workspace. With this, I should be able to solve for the first Im value, which can be used to determine the next Lm, and so on. However, specifying Lm_initial in the variable inductor's properties doesn't work; Simulink tries to evaluate Lm with the nonexistent 'phi' and 'Im' values rather than trying to solve for an initial Im using the value of the initial inductance.
I have tried solutions involving commenting/uncommenting blocks and implementing further subsystems which activate/deactivate depending on the time step, as well as unit delays, but these run into issues regarding tracking time for calculating the derivatives or output very incorrect/noisy waveforms.
Is there a relatively simple solution for this case? The problem appears as if it'd be relatively simple to solve, but I cannot seem to find a workaround for this.
Transformer Equivalent Model
The exact placement of the unit delay in the loop might be the key here: try to place the unit delay between the [lm] GoTo block and the lm input of your MATLAB function block fcn, that should work. And set the initial condition parameter to Lm_initial.

Simulink: get step time in a triggered subsystem

I have a question about my triggered subsystem in Simulink:
So the Susbsystem is executed every 0.01 s.
My question is: how can I get this variable (0.01) inside my subsystem?
NB: I don't need the Simulation step time.
I've already thought to two solutions:
1) use a Digital Clock with a Memory block
2) use a Weighted Sample Time block
but, both of them gave me an initial value of 0.
Do you have an elegant solution for my task
Thank you very much.
Have a nice day
The easiest solution is to have a constant block feeding into the subsystem. Define a MATLAB Workspace variable dt=0.01; and have the constant set to dt, and the sample rate of your Pulse Generator set to dt.
Alternatively you can use the Probe block to get the Sample Rate of the signal coming out of the Pulse Generator, and feed that as an input to the Subsystem.
Another way is to use get_param() command in your workspace.
In your case, it should be:
get_param('<path-to-block>/Pulse Generator','Period')
This should output:
>> ans =
0.01
I had this same problem myself. I received the following feedback from MATHWORKS when I reported it as a bug:
If triggered subsystems are executed on edge detection on the triggering event then it will require at least two model execution time steps in order to satisfy the triggering condition. As a result the triggered subsystem will not execute at 0 causing the results you are seeing. This is expected behavior.
If you require the triggered subsystem to execute on the first timestep you can change the "Trigger type" option to "function call." This option will execute the subsystem or model when the control signal receives a function-call event from a Statflow chart, Function-Call Generator block, or an S-function block." In this case you will just need to confirm that your function call block executes prior to the triggered subsystem block. This can be confirmed using the "Blocks - Execution Order" Debug tool under "Information Overlays."

Can state space matrix initial conditions be set by signals in simulink

I want to feed the initial conditions in state space matrix block in simulink by using signals "from-go to signal blocks". I m trying it with signal blocks but some errors pop up at the end and it says that the signal variables used as initial conditions are all undefined variable. In other words there exists "Undefined function or variable".
Any help appreciated, thank you
I take it you are using the State-Space block. The "initial conditions" parameter for the block is just that, a parameter:
You need to understand the difference between a parameter and a signal: a parameter is something that is constant throughout the simulation (e.g. a variable in the MATLAB workspace), whereas a signal is something whose value is updated at each time step. You cannot use a "signal" to parameterise a block, it's not possible, you can only use a parameter. Hope that clears things up.
If I misunderstood your question, please provide more details, including which block(s) you are using and if possible a screenshot of the model and the relevant block parameters.

Restarting or resetting input signal independently of simulation time and many times

I have designed a signal by using the Signal Builder block in Simulink. During the run of my simulation, the signal builder is to restart depending on the satisfaction of a condition. The condition can be satisfied many times, so, the signal should start from the beginning each time. If I want to put it in another way: You can take step input instead of the designed signal. Step input is to be reset conditionally. How can I make it?
I haven't seen such a functionality built-in Simulink (maybe the newer versions have it?) but here is a workaround:
You can simulate passed time with an integrator that has a Constant block set to 1 as input. The point is that the integrator block has a reset port which you can connect to your condition. So, when your condition becomes true, the integrator restarts a time variable from 0 (which is set in the initial conditions). Beforehand, you need to have your signal saved in something like a Table Lookup block, which outputs the signal as a function of time. Then you connect the integrator output to the Table Lookup block.
Have you tried putting your Signal Builder block in an enabled subsystem? You probably need to set the states when enabling to reset for it to work. Have a look at Create an Enabled Subsystem in the documentation for more details.

Initial value of signal in Simulink model

I have some questions regarding the simulink model, below.
Given an input in In1, what is the initial input of the 1 tagged in red?
What is the meaning of the block 1/s tagged with 2 in red?
It may be easier to answer these questions in reverse:
2) What is the meaning of the block 1/s tagged with 2 in red?
Answer: This is the Integrator block. It outputs the integral of its input at the current time step. Note that at the first time step, it will output whatever you have specified as its initial condition. By default, I believe that the initial condition is 0. (See the linked doc above for more info on setting various parameters for this block, including initial condition).
1) Given an input in In1, what is the initial input of the 1 tagged in red?
Answer: The initial input at 1 is actually completely independent of In1. It will depend only on the initial conditions of the blocks that feed into it at a given timestep.
You have to take into consideration the execution order of the blocks. In this model, the first block to execute will probably be the integrator block that you have marked with a 2. Following this will be the next integrator block and the gain blocks that they feed. One of the last blocks to execute will actually be the Subtract block that In1 feeds into. This is because this Subtract block needs to know what its input are before it can do any sort of calculations on them, therefore, the other blocks need to execute first.
This may be a little bit confusing considering that there is a loop here and therefore the Subtract block ends up feeding in to the Integrator blocks. This ends up not being an issue because the Integrator blocks do not have direct-feedthrough. This means that the current output of the integrator is not a direct function of the current input. Rather it is calculate based on the current state of the integrator block (which is determined mainly by the input at previous timesteps). This means that the Integrator block doesn't need to know its current input in order to calculate its current output.
So at the first time-step, the output of the integrator block is just the initial condition that you set (or the default initial condition of 0). So most likely, the initial value at 1 is 0.
(This link has some more info on algebraic loops and direct-feedthrough).
See here for more info on execution order in Simulink. This link also shows how to display the execution order in a model, which can sometimes be extremely useful to know.