Subscript operations

Use this forum to post Vensim related questions.
Post Reply
matin
Junior Member
Posts: 3
Joined: Sun Feb 18, 2007 6:40 am

Subscript operations

Post by matin »

Hi all,
I am new to VENSIM. I receive the "Missing the closing bracket for a variable" error message, when I enter the equation below for a subscript variable:

IF THEN ELSE
((rand1 >
Cumulative Pn[n-2]) AND (rand1 < Cumulative Pn[n-1]), 1, 0))
while "n" is a subscript defined as:
n1-n1000

Obviously, I cannot have expressions like "n - 1" as the subscript in the equation. I wonder how I can implement this model.

Bests,
Matin
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Subscript operations

Post by Administrator »

I'd do some subscript mapping. See the following post and report back if you can implement it successfully.
http://www.ventanasystems.co.uk/forum/v ... 584#p15537
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
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Subscript operations

Post by tomfid »

The problem here is that you can't use algebraic expressions like [n-1] in subscripts. You need to use mapping (as in the prev/next example here http://www.ventanasystems.co.uk/forum/v ... f=2&t=4584) or use VECTOR ELM MAP if for some reason you do need to use expressions.
matin
Junior Member
Posts: 3
Joined: Sun Feb 18, 2007 6:40 am

Re: Subscript operations

Post by matin »

Many thanks for the hints.
By the way, is it possible to use DELAY FIXED function as follows to generate f(n-1):
f(n-1) = DELAY FIXED(f(n),1)

or DELAY FIXED can only be used when the parameter "n" is time? (In my model, "n" is NOT time)?
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Subscript operations

Post by tomfid »

DELAY FIXED only works over time.
matin
Junior Member
Posts: 3
Joined: Sun Feb 18, 2007 6:40 am

Re: Subscript operations

Post by matin »

Hi again,
It seems that I have not implemented the model correctly, and I cannot figure out what is wrong.
I have defined three subscripts as follows:
n: (n3-n1000)
m: (m2-m999) -> n
k: (K1-k998) -> n

In order to access Cumulative Pn[n-1] and Cumulative Pn[n-2], I defined two new variables Cumulative Free Pn1[n] and Cumulative Free Pn2[n] as follows:
Cumulative Free Pn1[n] = INITIAL(Cumulative Free Pn[m])
Cumulative Free Pn2[n] = INITIAL(Cumulative Free Pn[k])

and then I use these two variables to calculate Promote free member[n]:
Promote free member[n] = IF THEN ELSE((rand1 < Cumulative Free Pn1[n]) :AND: (rand1 > Cumulative Free Pn2[n]), New random free members[n], 0)

Here, I have error messages like:
'Subscript of variable -Cumulative Free Pn- is a member of the -m- family when it should be a member of the -n- family'.

The model is attached.
Last edited by matin on Wed Aug 24, 2011 2:07 pm, edited 1 time in total.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Subscript operations

Post by Administrator »

I think you are trying to make it too complex.

Try again, but follow the example in the following post.
http://www.ventanasystems.co.uk/forum/v ... 584#p15537

Or you could use something like
SUM(IF THEN ELSE(ID[n!] <= n - 1, pn free[n!], 0 ) )
and
SUM(IF THEN ELSE(ID[n!] <= n - 2, pn free[n!], 0 ) )
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
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Subscript operations

Post by tomfid »

I think the problem may be that you're using three different ranges, (n3-n1000), (m2-m999), (K1-k998). If these are really different subsets of the same thing, so that you can refer to n-1 for example, you should define:

n : (n1-n1000)
nPrev = (n1-n999) -> nNext
nNext = (n2-n1000) -> nPrev

Then you can write things like:

x[n]=...
y[n1]=x[n1]
y[nNext]=x[nNext]+y[nPrev]

which is the equivalent of y(n)=y(n-1)+x(n) in more typical notation.

Tom
Post Reply