Hello,
Can I use the TREND function within Vensim PLE?
kind regards,
Lukas
TREND function and Vensim PLE
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
-
- Senior Member
- Posts: 107
- Joined: Wed Nov 26, 2008 6:12 am
-
- Senior Member
- Posts: 107
- Joined: Wed Nov 26, 2008 6:12 am
Macros
Dear Lukas,
As for the macros, you have to go into the text editor for Vensim (under view "As Text") and insert the macro code in the equation set.
For example, here is a macro which demonstrates (one possible) way to find the first derivative of a variable:
:MACRO: firstderiv(input,dt)
firstderiv = (((input-SMOOTH(input,dt))/dt))
~ input/dt
~ |
:END OF MACRO:
Once this is done, you can go back to the "sketch" view and introduce a variable which will call the macro. Open the equation editor, go to functions and select macro - your macro should show up. Put in the required inputs and the units and things should work!
Model Attached.
As for the macros, you have to go into the text editor for Vensim (under view "As Text") and insert the macro code in the equation set.
For example, here is a macro which demonstrates (one possible) way to find the first derivative of a variable:
:MACRO: firstderiv(input,dt)
firstderiv = (((input-SMOOTH(input,dt))/dt))
~ input/dt
~ |
:END OF MACRO:
Once this is done, you can go back to the "sketch" view and introduce a variable which will call the macro. Open the equation editor, go to functions and select macro - your macro should show up. Put in the required inputs and the units and things should work!
Model Attached.
- Attachments
-
- firstderivmacro.mdl
- (1.39 KiB) Downloaded 288 times
Equations for TREND are in the online help entry for the function:
TREND=ZIDZ(input-avval,average time*ABS(avval))
avval=INTEG((input-avval)/average time,input/(1+ini*averate time))
Incidentally, Karan's macro shows nicely why the TREND function (which is basically a first derivative divided by a baseline value) is not a good model for expectations when the input is noisy or subject to abrupt changes. In those cases, the input changes quickly. If you use (((input-SMOOTH(input,dt))/dt)) the result is dominated by noise. If you lengthen the horizon from dt to some longer value, it helps a little, but not much because of the presence of the unfiltered input.
To model expectations with realistically noisy inputs, you really need a second-order structure that smooths the data before forming slope expectations.
Tom
TREND=ZIDZ(input-avval,average time*ABS(avval))
avval=INTEG((input-avval)/average time,input/(1+ini*averate time))
Incidentally, Karan's macro shows nicely why the TREND function (which is basically a first derivative divided by a baseline value) is not a good model for expectations when the input is noisy or subject to abrupt changes. In those cases, the input changes quickly. If you use (((input-SMOOTH(input,dt))/dt)) the result is dominated by noise. If you lengthen the horizon from dt to some longer value, it helps a little, but not much because of the presence of the unfiltered input.
To model expectations with realistically noisy inputs, you really need a second-order structure that smooths the data before forming slope expectations.
Tom
/*
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
*/
-
- Senior Member
- Posts: 1107
- Joined: Wed Mar 12, 2003 2:46 pm
The equations for Vensim's trend function are in the documentation for that function. This is true of all functions that are implemented as Macros. Note that Vensim's trend function is different from that documented in Business Dynamics, and also the Trend Molecule both of which have an additional SMOOTH relative to the Vensim implementation.
You can't enter MACROs in Vensim PLE, you will need to explicitly build out the equations (eg as the Trend Molecule). Molecules can be download from vensim.com
You can't enter MACROs in Vensim PLE, you will need to explicitly build out the equations (eg as the Trend Molecule). Molecules can be download from vensim.com