How to iterate in simulink?

Hi,
I have the following problem, I want to iterate two variables in Simulink. In normal code it would look like this:
X(i+1)=X(i)+4*(X(i)-Y(i));
Y(i+1)=Y(i)+2*(X(i)-Y(i));
I used For Iterate Block but it doesn't work. I'm getting an error:
"Trouble solving algebraic loop containing 'untitled/For Iterator Subsystem1' at time 0. Stopping simulation. There may be a singularity in the solution. If the model is correct, try reducing the step size (either by reducing the fixed step size or by tightening the error tolerances)."
Here's what i have done in Simulink

 Respuesta aceptada

Azzi Abdelmalek
Azzi Abdelmalek el 10 de Nov. de 2013
Editada: Azzi Abdelmalek el 10 de Nov. de 2013

0 votos

% x(i+1)=x(i)+4*(x(i)-y(i));
% can be written as
% x(i+1)-5x(i)=-4y(i)
% z X(z)-5X(z)=-4Y(z)
% H(z)=-4/(z-5)
To get the result you can use a discrete transfer function with
numerator=-4
denominator=[1 -5]
% input signal=y
% output signal x

3 comentarios

Daniel
Daniel el 10 de Nov. de 2013
Editada: Daniel el 11 de Nov. de 2013
Thanks, that helped me. I have one more question, how do I include initial conditions x(1)=400 and y(1)=100?
Azzi Abdelmalek
Azzi Abdelmalek el 11 de Nov. de 2013
Editada: Azzi Abdelmalek el 11 de Nov. de 2013
set initial values of your unit delay block to 400 and 100
Daniel
Daniel el 11 de Nov. de 2013
thanks one more time, that is what i was looking for.

Iniciar sesión para comentar.

Más respuestas (0)

Categorías

Más información sobre Simulink en Centro de ayuda y File Exchange.

Etiquetas

Preguntada:

el 10 de Nov. de 2013

Comentada:

el 11 de Nov. de 2013

Community Treasure Hunt

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

Start Hunting!

Translated by