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>
IF THEN ELSE Qns
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
nested if then else
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.
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.
-
- Super Administrator
- Posts: 4590
- Joined: Wed Mar 05, 2003 3:10 am
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.
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.
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.
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.
R. G. Dudley