Page 1 of 1

Lookup over time with subscripts

Posted: Mon Apr 18, 2016 4:56 pm
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

Re: Lookup over time with subscripts

Posted: Mon Apr 18, 2016 5:08 pm
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)

Re: Lookup over time with subscripts

Posted: Mon Apr 18, 2016 6:15 pm
by rubynguyen
Got it! Many thanks, Tom!

Re: Lookup over time with subscripts

Posted: Mon Apr 18, 2016 7:34 pm
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

Re: Lookup over time with subscripts

Posted: Mon Apr 18, 2016 7:48 pm
by tomfid
You want VECTOR REORDER with SORT ORDER. See the example in https://www.vensim.com/documentation/fn ... eorder.htm

Re: Lookup over time with subscripts

Posted: Tue Apr 19, 2016 3:14 am
by LAUJJL
Hi

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

Regards.

JJ

Re: Lookup over time with subscripts

Posted: Tue Apr 19, 2016 2:14 pm
by rubynguyen
JJ,

Many thanks for the solution. This is very similar to Powersim, which I'm familiar with.
Ruby

Re: Lookup over time with subscripts

Posted: Tue Apr 19, 2016 2:19 pm
by tomfid
Good solution. The VECTOR operations are computationally expensive if you only need the min or max element.

Re: Lookup over time with subscripts

Posted: Tue Apr 19, 2016 5:18 pm
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

Re: Lookup over time with subscripts

Posted: Thu Oct 06, 2016 7:54 pm
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

Re: Lookup over time with subscripts

Posted: Thu Oct 06, 2016 8:08 pm
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.

Re: Lookup over time with subscripts

Posted: Thu Oct 06, 2016 9:06 pm
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!

Re: Lookup over time with subscripts

Posted: Thu Oct 06, 2016 10:46 pm
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.

Re: Lookup over time with subscripts

Posted: Fri Oct 07, 2016 3:59 pm
by rubynguyen
Thanks for the suggestion, Tom!