subscripts

Use this forum to post Vensim related questions.
Post Reply
sarahboyar@gmail.com
Junior Member
Posts: 10
Joined: Mon May 08, 2023 8:34 am
Vensim version: PRO

subscripts

Post by sarahboyar@gmail.com »

Subscript question:

If I have a subscript of Fruit with elements:
mandarins, satsumas, easy peelers, granny smith, red delicious, pink lady

subrange oranges: mandarins, satsumas, easy peelers
subrange apples: granny smith, red delicious, pink lady

Why can't I write an equation as follows:

Total Annual Fruit[Fruit] = SUM(total annual oranges[oranges!]) + SUM(total annual apples[apples!])

total annual oranges = average yield[oranges] * trees[oranges]
total annual apples = average yield[apples] * trees [apples]
sarahboyar@gmail.com
Junior Member
Posts: 10
Joined: Mon May 08, 2023 8:34 am
Vensim version: PRO

Re: subscripts

Post by sarahboyar@gmail.com »

Ok, maybe that's because the LHS is Fruit but we summed everything up.

What about this:

Total Annual Fruit[Fruit] = total annual oranges[oranges] + total annual apples[apples]

If all the elements in Fruit are accounted for in the equation, via the 2 subranges, why does it return an error?
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: subscripts

Post by tomfid »

Your second equation has 6 elements on the left, and 2 instances of 3 elements on the right, so it can't work.

You could do something like the following:

oranges : mandarins, satsumas, easy peelers
apples : granny smith, red delicious, pink lady

fruit : oranges, apples ~ build the master list hierarchically
fruitType : o, a -> (fruit : oranges, apples) ~ this maps the 2 types to the 6 detailed types

total[o] = SUM( detail[oranges!])
total[a] = SUM( detail[apples!])
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: subscripts

Post by tomfid »

The mapping lets you write stuff like:

sales[fruit] = preference[fruitType]*supply[fruit]
Post Reply