Hello!
I wonder if there are recursive functions in Vensim. Like the attached diagram, t is the independent variable, P, S, W, π are all dependent variables. Each arrow means that the function between the two variables that the arrow connected is known. In principle, once the initial value P0 and W1 are known, we can extrapolate all the values of P, S, W, π afterwards. But how to realize it in Vensim, are there functions that can be used to do this?
Thank you!!!
Recursive function
Recursive function
- Attachments
-
- function structure.png (44.21 KiB) Viewed 1793 times
-
- Super Administrator
- Posts: 4626
- Joined: Wed Mar 05, 2003 3:10 am
Re: Recursive function
Is "t" time? If yes, this is easy in Vensim.
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: Recursive function
Yes, t is time, all integers, namely 0,1,2,3...... Could you give me some hints, please?
-
- Super Administrator
- Posts: 4626
- Joined: Wed Mar 05, 2003 3:10 am
Re: Recursive function
You will need variables
P
S
W
Pi
P will probably be a level with initial value P0. That should get you started.
P
S
W
Pi
P will probably be a level with initial value P0. That should get you started.
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: Recursive function
Thank you! I'm just stuck on setting a function for P. Because it has two initial value to input. Put it simply, let us assume a function z=f(x,y), where x and y are both functions of t. t are intergers: 0, 1, 2, 3.......And the functions xt+1=g(xt), yt+1=k(yt) are known. Initial value x0 and y0 are also known. How could I translate this into Vensim, so that all the values of x,y,z can be calculated automatically?Administrator wrote: ↑Thu Nov 18, 2021 12:16 pm You will need variables
P
S
W
Pi
P will probably be a level with initial value P0. That should get you started.
Sorry to bother you with this, but I've done a lot of research and still haven't found a solution, could you help me a little bit?
Re: Recursive function
I think you might want to look through some of the sample models or exercises in the Help system in order to get into the continuous dynamic system mindset.
/*
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: Recursive function
In your second example, x and y are stocks, with an equation like:
x = INTEG( dx, x0 )
With Euler integration, this becomes
x(t+dt) = x(t) + dx*dt
where dt is the time step, which could be 1 time unit if desirable to match your discrete case.
If x(t+1) = g(x(t)) then you can rewrite
dx = g(x(t)) - x(t)
Using the implicit time step simplifies the expression but will likely lead to unit problems, so you may wish to preserve dt explicitly. See https://metasd.com/2017/11/discrete-time-stinks/ for more thoughts on this.
x = INTEG( dx, x0 )
With Euler integration, this becomes
x(t+dt) = x(t) + dx*dt
where dt is the time step, which could be 1 time unit if desirable to match your discrete case.
If x(t+1) = g(x(t)) then you can rewrite
dx = g(x(t)) - x(t)
Using the implicit time step simplifies the expression but will likely lead to unit problems, so you may wish to preserve dt explicitly. See https://metasd.com/2017/11/discrete-time-stinks/ for more thoughts on this.
/*
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
*/