Unable to break algebraic loop for...

Moderators: Frank, paul, Hiwot, Chris, peter

Post Reply
Van Oort
Posts: 12
Joined: Wed Sep 21, 2005 9:54 am
Location: University of Twente
Contact:

Unable to break algebraic loop for...

Post by Van Oort » Wed Sep 21, 2005 1:35 pm

If you try the following code:

Code: Select all

variables
	real state;
	boolean changestate;
equations
	changestate = event(sin(time));
	if      (state==1 and changestate) then state = 2;
	else if (state==2 and changestate) then state = 1; end;
	end;

compiling it will give you the following error: unable to break algebraic loop for (state==1 and changestate).
You might wonder which algebraic loop is meant. Well, none. The problem here is that the variable state has no initial value. So adding

Code: Select all

initialequations
	state=1;


to the code solves the problem. It occurs quite often that this error results from an initialization that was forgotten.

paul
Posts: 152
Joined: Mon Sep 19, 2005 2:00 pm
Location: Controllab Products B.V.

Re: Unable to break algebraic loop for...

Post by paul » Wed Oct 05, 2005 10:05 am

Van Oort wrote:The problem here is that the variable state has no initial value. So adding

Code: Select all

initialequations
	state=1;

to the code solves the problem. It occurs quite often that this error results from an initialization that was forgotten.
That's true. The actual problem is that the submodel consists of equations. In this case you are actually typing procedural code (as you mention above your post). If you use the code keyword instead of equations, 20-sim will not try to sort and reshape your submodel, and thus assume that the expressions are all in computational order and form (think of x = x + 1 as an equation instead of code).

As a resulty the algebraic loop is gone, but you still might need to specify some initial value. In the Tools->Options of the Simulator you can specify if 20-sim needs to initialize variables, the initialization can be 0 or NaN. The last situation is made to trace variables that are not initialized; a simulation in debugmode will give an error on this.

Hope this helps,
Paul.
member 20-sim development team

Post Reply