Simulink - Initial condition for first iteration only

I've built a closed-loop model on Simulink and I used a Memory block in order to delay the feedback signal. The problem is that Memory block delays every input signal by one step and I would like to use an initial value for the first step only and then use the computed value for the second step and so on.
Is there a way to accomplish this is Simulink?
Thanks in advance.

Answers (2)

Run the attached model. I simply made a logic where the clock of the simulation is compared to a constant, let's say your sampling time(assuming you are working with fixed step). Then, At the very first step, it enables Memory block to be active via a MATLAB Function(see the content of MATLAB Function and try to understand), and after it passes first step, direct feedback is applied. Try to understand and adapt this into your problem. Hope this helps.

8 Comments

Thanks! I implemented this technique and it worked at first. But now I get an error when running the simulation over 700s, Step size is 100 (fixed-step): "Simulink cannot solve the algebric loop... the model is ill-defined..."
I attached the changes I've made to the model. Is there a way to fix this issue?
Where does the error occur in your signal? Put a Delay block at that point.
The error occurs at the same signal, the one that goes in to the 2nd port of the multiport switch without a Memory block. If I put a delay block there, then we're back to square one since originally I wanted an initial value for the first step only and the computed value for the second step and so on.
The error I get is:
An error occurred while running the simulation and the simulation was terminated Caused by: Simulink cannot solve the algebraic loop containing 'TC/Car Temperature' at time 700.0 using the TrustRegion-based algorithm due to one of the following reasons: the model is ill-defined i.e., the system equations do not have a solution; or the nonlinear equation solver failed to converge due to numerical issues. To rule out solver convergence as the cause of this error, either a) switch to LineSearch-based algorithm using set_param('TC','AlgebraicLoopSolver','LineSearch') b) reducing the fixed step size. If the error persists in spite of the above changes, then the model is likely ill-defined and requires modification.
Can you share your model?
I solved your problem by adding a Delay block inside Car Temperature subsystem. Check it please.
The error is solved, but now due to the addition of delay block - the model doesn't act as expected: The expected result should be that the "AC Temp" figure and the "Calculated AC Temp" figure are the same except for the first step but due to the addition of delay - the "AC temp" is always "one step" behind instead of being equal (I attached the figures).
(I altered your delay block - only added an initial value of 20).
Oh, that is because you set your Fixed step size to 100. You should lower it to see more accurate results. Do you have any logic setting the step size to 100?

Sign in to comment.

Abdolvakil Fazli
Abdolvakil Fazli on 18 Dec 2018
Edited: Abdolvakil Fazli on 18 Dec 2018
Hi,
I have trouble setting the initial value of the adaptation block in simulink attached in this post. I am dealing with a loop in the input of this loop I take one data x (or say a sample) and calculate y according to that x , and adaptation vector (A), in adaptation block, I would update A according to the previous value of x,y,z and A , then I report A to predistortion block , and this loop is turning. My problem is the initial value of A in the first step; It has to be set as ones(1,65) just in the first time ; I do not know how to do it. Because if you set it in Pred block as ones(1,65) in each sample you will be facing with A=ones not an updated version of A. Someone suggested me using clock and counter, I do not know how for I am beginner in simulink. If anybody has any idea about implimentation of this method, or if you have another suggestion , it would be appreciated.
Thanks in advance

Categories

Find more on Modeling in Help Center and File Exchange

Asked:

on 3 Apr 2018

Edited:

on 18 Dec 2018

Community Treasure Hunt

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

Start Hunting!