I know this is a similar post to one that discussed how to create multiple IF THEN ELSE statements/also using LOOKUP functions, but I haven't had success with the solutions proposed yet. I have a sine wave that I am using to create a pattern of mortality rates. I do not want the mortality rate to reach above 1.0, or go below 0.148. Individually, these equations work:
IF THEN ELSE(((sine wave*0.13852)+0.28775) < 0.148 , 0.148, (sine wave*
0.13852)+0.28775)
IF THEN ELSE(((sine wave*0.13852)+0.28775) > 1.0 , 1.0, (sine wave*
0.13852)+0.28775)
However, trying to add them together creates some kind of compounding effect/does not seem to model properly. Would a look up function work better? I already have an established working function, again just trying to set a max and min value basically. Thank you so much for any input. Happy to attach my .mdl file if that helps.
using IF THEN ELSE for creating max/min values
-
- Super Administrator
- Posts: 4573
- Joined: Wed Mar 05, 2003 3:10 am
Re: using IF THEN ELSE for creating max/min values
Will the min or max functions work?
For example,
value = max ( 0.148, min ( 1, sine wave ) )
For example,
value = max ( 0.148, min ( 1, sine wave ) )
Advice to posters seeking help (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: using IF THEN ELSE for creating max/min values
Doing this resulted in the proper boundaries, but removed the sine wave increasing in amplitude over time. The sine wave will not hit these bounds until timestep = 50 or 60 years and the function is increasing in amplitude over time.Administrator wrote: ↑Fri Apr 03, 2020 8:46 pm Will the min or max functions work?
For example,
value = max ( 0.148, min ( 1, sine wave ) )
Re: using IF THEN ELSE for creating max/min values
I also tried nesting again this morning, with an error that I'm expecting an operator.
IF THEN ELSE(((sine wave*0.13852)+0.28775) <= 0.148 , 0.148, IF THEN ELSE(sine wave*0.13852)+0.28775) >= 1.0 , 1.0, (sine wave*0.13852)+0.28775)))
IF THEN ELSE(((sine wave*0.13852)+0.28775) <= 0.148 , 0.148, IF THEN ELSE(sine wave*0.13852)+0.28775) >= 1.0 , 1.0, (sine wave*0.13852)+0.28775)))
Re: using IF THEN ELSE for creating max/min values
It's probably a parentheses nesting problem.
It's better if you make the sin wave a separate variable, then clip it in another equation. Also, the parameters should be made into variables so that units balance.
For example:
sinwave = amplitude*SIN( (Time-PhaseShift)/period*2*3.1415926 )
clippedSinwave = MIN( xmax, MAX( xmin, sinwave ) )
It's better if you make the sin wave a separate variable, then clip it in another equation. Also, the parameters should be made into variables so that units balance.
For example:
sinwave = amplitude*SIN( (Time-PhaseShift)/period*2*3.1415926 )
clippedSinwave = MIN( xmax, MAX( xmin, sinwave ) )
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: using IF THEN ELSE for creating max/min values
Nesting the function with proper parentheses worked. Thank you very much for the help.tomfid wrote: ↑Wed Apr 08, 2020 4:49 pm It's probably a parentheses nesting problem.
It's better if you make the sin wave a separate variable, then clip it in another equation. Also, the parameters should be made into variables so that units balance.
For example:
sinwave = amplitude*SIN( (Time-PhaseShift)/period*2*3.1415926 )
clippedSinwave = MIN( xmax, MAX( xmin, sinwave ) )