Page 1 of 1

IF THEN ELSE Qns

Posted: Mon Oct 09, 2006 4:55 pm
by Seikyo
Just wondering, how do we formulate a double IF THEN ELSE condition? For example,

Before time x, the value is x,
After time x, the value is STEP(y,<Time X>),
Then after time z, the value is change to STEP(z, <time z>)

is it possible to write equation like other programming language

IF <Condition> Then <Value X>

IF <Condition> Then <Value Y>

Else <Value Z>

Posted: Mon Oct 09, 2006 6:21 pm
by Administrator
You can nest IF THEN ELSE statements, but it does make the equations harder to read (I try to avoid them unless it is absolutly necessary).

IF THEN ELSE ( time < A
, condition A
, IF THEN ELSE ( time < B
, condition B
, condition C )
)

Tony.

Posted: Mon Oct 09, 2006 8:06 pm
by Seikyo
Thanks. That is the syntax I am looking for. I am still figuring out ways to avoid it.

nested if then else

Posted: Tue Oct 10, 2006 7:50 am
by LAUJJL
Hi
To avoid the syntax, the solution is to use intermediary variables.
If then else (A < B,C,D),
D = if then esle (X >Y,E,F)
It reduces the complexity of the equations but increases the
complexity of the sketch.
Regards.

Posted: Tue Oct 10, 2006 2:03 pm
by Administrator
If I cannot avoid nesting IF THEN ELSE, I do something like the following.

Some result =
IF THEN ELSE ( time < A , condition A , 0 )
+ IF THEN ELSE ( time >= A :AND: time < B , condition B , 0 )
+ IF THEN ELSE ( time >= B :AND: time < C , condition C , 0 )
+ IF THEN ELSE ( time >= C :AND: time < D , condition C , 0 )

As long as you are careful and make sure each condition can only happen by itself, it makes things a little easier to read. It does for me anyway.

Tony.

Posted: Tue Oct 17, 2006 2:56 am
by rdudley
But I think that the point is not only to avoid _nesting_ If then else statememts, but to avoid USING them in the first place.

If you have lots of if then else statements you should probably think about using a different modeling approach.

I normally use them only to turn on or off effects from selected parts of the model.