ordering vectors

Use this forum to post Vensim related questions.
Post Reply
chester riddalls
Junior Member
Posts: 14
Joined: Tue Mar 25, 2003 9:25 am

ordering vectors

Post by chester riddalls »

Hello
I'm looking for a way to add 2 subscripted variables (var1 and var2) together so that the largest element of var2 is added to the first element of var1, the second largest element of var2 is added to the second element of var1... and so on.
I have seen the functions vector reorder and vector sort order, but they do not appear in the ref manual. Could someone explain these functions to me or propose another way to do this. Many thanks.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

Hello Chester,

The Vensim documentation on the web contains some help,
http://www.vensim.com/documentation/html/22782.htm

I would use the sort function (to give "sorted vars"), then something like

addition param[subrange 2] =
sum (
if then else ( sorted vars[sub range 1!] = subrange 2
, sorted vector[sub range 1!] + vector to be added to[subrange 2]
, 0 ) )

Is this ok to follow?

Tony.
chester riddalls
Junior Member
Posts: 14
Joined: Tue Mar 25, 2003 9:25 am

Post by chester riddalls »

Hi Tony
One problem: the function "vector sort order" does not give the expected results.
I've defined var1[day]=1,4,2,3,5,7,6
Then sorted var=Vector sort order(var1[day],1)
This gives
sorted var[day]=0,2,3,1,4,6,5
Not
sorted var[day]=0,3,1,2,4,6,5
as I would expect. Can you explain please?
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

I have asked for clarification (I would expect the same results as you).

If you are still using our external function library, you could use the SORT ASCEND/DESCEND funciotns. That should work as expected (not zero based though).

Syntax is something like
SORT ASCEND 1D ( vector, size of vector, trigger).

Tony.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Post by Administrator »

As a followup, the VECTOR SORT ORDER function works fine (we just misunderstood its return values).

It returns in the first position the index of the smallest element, in the second the index of the next smallest and so on. The indices are 0 based.

We thought it was a VECTOR RANK function.

Tony
chester riddalls
Junior Member
Posts: 14
Joined: Tue Mar 25, 2003 9:25 am

Post by chester riddalls »

thanks tony
that works.
odd about the other function though
regards
chester
chester riddalls
Junior Member
Posts: 14
Joined: Tue Mar 25, 2003 9:25 am

Post by chester riddalls »

Ahhh I see
thanks
Post Reply