Recursive function

Use this forum to post Vensim related questions.
Post Reply
chenho
Junior Member
Posts: 10
Joined: Tue Oct 26, 2021 10:24 am
Vensim version: PLE

Recursive function

Post by chenho »

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!!!
Attachments
function structure.png
function structure.png (44.21 KiB) Viewed 1588 times
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Recursive function

Post by Administrator »

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
chenho
Junior Member
Posts: 10
Joined: Tue Oct 26, 2021 10:24 am
Vensim version: PLE

Re: Recursive function

Post by chenho »

Administrator wrote: Thu Nov 18, 2021 12:08 pm Is "t" time? If yes, this is easy in Vensim.
Yes, t is time, all integers, namely 0,1,2,3...... Could you give me some hints, please?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Recursive function

Post by Administrator »

You will need variables
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
chenho
Junior Member
Posts: 10
Joined: Tue Oct 26, 2021 10:24 am
Vensim version: PLE

Re: Recursive function

Post by chenho »

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.
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?

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?
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Recursive function

Post by tomfid »

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.
tomfid
Administrator
Posts: 3804
Joined: Wed May 24, 2006 4:54 am

Re: Recursive function

Post by tomfid »

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.
Post Reply