Lookup over time with subscripts

Use this forum to post Vensim related questions.
Post Reply
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Lookup over time with subscripts

Post by rubynguyen »

Hello,

I've searched the forum for this topic but couldn't find the answer to my problem.
I have 4 products, demand for each is exogenous over time. Thought it should be easy but Vensim keeps telling me there are more than 1 equations for each product.
Please have a look at the attached model. Thanks!

Ruby
Attachments
testing lookup.mdl
(2.08 KiB) Downloaded 247 times
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

Re: Lookup over time with subscripts

Post by tomfid »

You're on the right track; the only problem is that your lookup definition uses the subscript range name twice. If you want a different lookup for each element, you need to use the individual element names, like:

MyRange : a, b
MyLookup[a] [(2015,0)-(2020,4000)],(2015,1000),(2016,1500),(2017,2000),(2018,2500),(2019,3000),(2020,3500)
MyLookup [(2015,0)-(2020,4000)],(2015,1000),(2016,1500),(2017,2000),(2018,2500),(2019,3000),(2020,3500)
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Re: Lookup over time with subscripts

Post by rubynguyen »

Got it! Many thanks, Tom!
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Re: Lookup over time with subscripts

Post by rubynguyen »

Another problem I encounter is to index the array. There are a couple functions in Vensim but I don't know which one to use.
If I have a vector of Q=[30,50,70,90,110], after calculating the profit of all Qs, I have another vector P=[100,200,500,350,400]. I can easily find Pmax with Vmax function and find the index/location of Pmax (from previous threads). In this case, Pmax location is 3. The question is if I want to extract the value of Q3, what is the simplest way to go? Thanks!

Ruby
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

Re: Lookup over time with subscripts

Post by tomfid »

You want VECTOR REORDER with SORT ORDER. See the example in https://www.vensim.com/documentation/fn ... eorder.htm
LAUJJL
Senior Member
Posts: 1432
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Lookup over time with subscripts

Post by LAUJJL »

Hi

Another solution that does not need the vector order function is joined.

Regards.

JJ
Attachments
sub max.mdl
(1.82 KiB) Downloaded 225 times
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Re: Lookup over time with subscripts

Post by rubynguyen »

JJ,

Many thanks for the solution. This is very similar to Powersim, which I'm familiar with.
Ruby
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

Re: Lookup over time with subscripts

Post by tomfid »

Good solution. The VECTOR operations are computationally expensive if you only need the min or max element.
LAUJJL
Senior Member
Posts: 1432
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Lookup over time with subscripts

Post by LAUJJL »

Hi

There are probably many other ways to solve that problem.
One is to first identify the subscript range corresponding to the maximum and then to find the value in q using a vector elm map function that is maybe quicker if there is a large number of subs. I have not tried. To use the vector elm map one is obliged to find first the subscript. Joined the model. It is maybe quicker but unfortunately more tricky and difficult to understand.

Regards.

JJ
Attachments
sub max2.mdl
(2.19 KiB) Downloaded 225 times
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Re: Lookup over time with subscripts

Post by rubynguyen »

A little off track but still in the subscript topic.
If I have a subscript of 4 products, can I show 2 of them on a graph instead of 4? The reason why I want to show them separately is because of values. Say products A & B are calculated in millions while products C & D are counted in hundreds. Displaying on the same graph will make C & D look like zero.
Thanks!

Ruby
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

Re: Lookup over time with subscripts

Post by tomfid »

Sure - just vary what you select in the Subscript Control: https://www.vensim.com/documentation/in ... ?20165.htm

If you need to make it permanent, create subranges & custom graphs.
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Re: Lookup over time with subscripts

Post by rubynguyen »

So when I select the active subscript, does it mean that I can't have both graphs (1 for A&B) and 1 for ( C&D) at the same time?
Thanks!
tomfid
Administrator
Posts: 3816
Joined: Wed May 24, 2006 4:54 am

Re: Lookup over time with subscripts

Post by tomfid »

You can have both if you define a custom graph, and you can display both on the screen at one time. There just isn't a way to generate two different graphs with one click.

If you have few elements, another option would be to use the strip graph tool with the causes & uses options turned off. Then you'd get a single window with one graph per subscript element in it.
rubynguyen
Junior Member
Posts: 14
Joined: Mon Apr 18, 2016 4:33 pm
Vensim version: DSS

Re: Lookup over time with subscripts

Post by rubynguyen »

Thanks for the suggestion, Tom!
Post Reply