Maximum value

Use this forum to post Vensim related questions.
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Maximum value

Post by Priscila »

Hi,

I need to find the maximum value of a variable A, I was trying to use GET DATA MAX but the variable A is auxiliary and with this function does not return me to any value, in this case which function can I use.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

This should work.

Code: Select all

MAX VALUE = SAMPLE IF TRUE ( A > MAX VALUE , A , A )
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
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum value

Post by Priscila »

Yes, this works, searches for the maximum value of variable A throughout the simulation, however can I get the maximum value of variable A by separating periods.
For example, the maximum of time 0 to time 2783 and the maximum of time 2784 to time 5759, using GET DATA MAX would look like this:
IF THEN ELSE (Time = 2783, GET DATA MAX (Variable A, 0,2783), IF THEN ELSE (Time = 5759, GET DATA MAX (Variable A, 2784, 5759), 0))
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

You can use SAMPLE IF TRUE and also test on time, for example

Code: Select all

MAX VALUE SPAN 1 = SAMPLE IF TRUE ( A > MAX VALUE :and: TIME > 0 :AND: TIME < 2783, A , A )
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
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum value

Post by Priscila »

So I will have to create several variables to get the maximum over the entire period that totals 37800 or is it possible to get that same variable?
Maximum value = Variable A> Maximum value,IF THEN ELSE (Time> 0: AND: Time <= 2783, IF THEN ELSE (Time = 2783, Variable A, 0), IF THEN ELSE (Time> = 2784: AND: Time <5759, IF THEN ELSE (Time = 5759, Variable A, 0), 0)), 0
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

Priscila wrote:So I will have to create several variables to get the maximum over the entire period that totals 37800 or is it possible to get that same variable?
Maximum value = Variable A> Maximum value,IF THEN ELSE (Time> 0: AND: Time <= 2783, IF THEN ELSE (Time = 2783, Variable A, 0), IF THEN ELSE (Time> = 2784: AND: Time <5759, IF THEN ELSE (Time = 5759, Variable A, 0), 0)), 0
Personally, I'd use several variables. Nesting IF THEN ELSE statements makes your model very hard to read and debug.
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
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum value

Post by Priscila »

The problem is that this is not working, when I used the GET DATA MAX I got the maximum value of variable A in the time interval from 0 to 2783 showing only this maximum value at time 2783 and so on for other values ​​as mostro In the attached image, already with SIMPLE IF TRUE I can not do this
Attachments
teste.png
teste.png (6.54 KiB) Viewed 11751 times
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

How about

Code: Select all

MAX VALUE = SAMPLE IF TRUE ( A > MAX VALUE , A , A )
MAX VALUE PEAK = IF THEN ELSE ( TIME = 5000 , MAX VALUE , 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
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum value

Post by Priscila »

Thus the value shown is the value of time = 5000 and not the maximum of the series. For example, the value to be shown at time = 2783 must be the maximum value found in the time interval from 0 to 2783. Is it possible to do this with some function or is there some way to transform the data of an auxiliary variable into constant or Data so that I can use GET DATA MAX.


Thanks for the patience and agility in the answers.
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

Code: Select all

MAX VALUE = SAMPLE IF TRUE ( A > MAX VALUE :and: time >=0 :and: time <= 2783 , A , A )
MAX VALUE PEAK = IF THEN ELSE ( TIME = 2783 , MAX VALUE , 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: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Maximum value

Post by tomfid »

... and if you want multiple intervals, put the same structure in an array, with one element per time interval to be considered.
felipeherminio
Junior Member
Posts: 2
Joined: Sun Apr 14, 2019 5:39 pm
Vensim version: PLE

Re: Maximum value

Post by felipeherminio »

could someone help me because I can't get the maximum value of T2 in the attached model. Did all the recommended procedures SAMPLE IF TRUE (T2> T2max, T2, T2)
model.mdl
(2.34 KiB) Downloaded 331 times
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Maximum value

Post by tomfid »

This seems to be working fine. T2 and T2max both reach their max values at time 2. What's the problem?
felipeherminio
Junior Member
Posts: 2
Joined: Sun Apr 14, 2019 5:39 pm
Vensim version: PLE

Re: Maximum value

Post by felipeherminio »

I would like the variable T2max to remain over time (1-20) with the maximum value of T2 (378,733). As you can see, even using the suggestion of this topic, the variable still has the same values ​​as T2.
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Maximum value

Post by tomfid »

When I run this model, T2 starts at 341 and reaches 378 at time 2, and remains there after. T2max is the same, because T2 is always nondecreasing. If I override T2 with a Sin wave of period 8, T2max is still OK - it follows the wave to its maximum and then holds that value.

If you mean that T2max at time 0 or 1 should contain the eventual maximum of T2 at time 2, that is not possible. That would be an acausal model, with variables using information from the future. This is not possible in principle.

However, if there's some utility purpose for using information from the future, there might be a workaround, like using an array dimension as a quasi-time axis. I'd have to know more about the situation to suggest something.
LAUJJL
Senior Member
Posts: 1421
Joined: Fri May 23, 2003 10:09 am
Vensim version: DSS

Re: Maximum value

Post by LAUJJL »

Hi

Transforming future deterministic or not results into present results is often useful like for instance dynamic programming where you have to evaluate future expectations and transform them into actual one’s by backward calculations.

Here is a simplistic example joined where is calculated the expected capital with interests if needed at the beginning of the time model.

The files joined can be read with Vensim pro or DSS (.mdl) or the Vensim reader (.vpm)

Regards.

JJ
Attachments
future_in_an_array.vpm
(90.2 KiB) Downloaded 333 times
future_in_an_array.mdl
(3.41 KiB) Downloaded 319 times
danguzzo
Junior Member
Posts: 12
Joined: Wed Jan 22, 2020 12:10 pm
Vensim version: DSS

Re: Maximum value

Post by danguzzo »

A complementary question for this one:

Is it possible to get the time which a given auxiliary achieved its maximum value in the simulation?
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

You can record this using the SAMPLE IF TRUE function.
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
RWTH_FCN
Senior Member
Posts: 148
Joined: Wed Feb 08, 2017 9:10 am
Vensim version: DSS

Re: Maximum value

Post by RWTH_FCN »

Administrator wrote: Mon Jul 10, 2017 12:48 pm This should work.

Code: Select all

MAX VALUE = SAMPLE IF TRUE ( A > MAX VALUE , A , A )
It works well for maximum. Is it correct for getting minimum?

Code: Select all

MIN VALUE = SAMPLE IF TRUE ( A <MIN VALUE , A , A )
Administrator
Super Administrator
Posts: 4573
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum value

Post by Administrator »

Correct, that should get the minimum.
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: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Maximum value

Post by tomfid »

And you can also sample MAX TIME = SAMPLE IF TRUE ( A > MAX VALUE , Time, Time ) to capture when this occurs.
RWTH_FCN
Senior Member
Posts: 148
Joined: Wed Feb 08, 2017 9:10 am
Vensim version: DSS

Re: Maximum value

Post by RWTH_FCN »

Administrator wrote: Sat Jan 25, 2020 8:04 pm Correct, that should get the minimum.
Do you have any suggestion why it always generates zero?
tomfid
Administrator
Posts: 3806
Joined: Wed May 24, 2006 4:54 am

Re: Maximum value

Post by tomfid »

The initial value of the input would have to be 0. It's possible that there's a 0 in the initialization step, even if the dynamic value is nonzero. Hard to say more without seeing equations and data.
RWTH_FCN
Senior Member
Posts: 148
Joined: Wed Feb 08, 2017 9:10 am
Vensim version: DSS

Re: Maximum value

Post by RWTH_FCN »

tomfid wrote: Sun Jan 26, 2020 4:08 pm The initial value of the input would have to be 0. It's possible that there's a 0 in the initialization step, even if the dynamic value is nonzero. Hard to say more without seeing equations and data.
Sounds plausible. There is one 0 in initialization step. Any idea to solve it?
RWTH_FCN
Senior Member
Posts: 148
Joined: Wed Feb 08, 2017 9:10 am
Vensim version: DSS

Re: Maximum value

Post by RWTH_FCN »

tomfid wrote: Sun Jan 26, 2020 4:08 pm The initial value of the input would have to be 0. It's possible that there's a 0 in the initialization step, even if the dynamic value is nonzero. Hard to say more without seeing equations and data.
I cannot upload the model, but I hope these equations help to understand the problem.

I want to calculate yearly min price with this code:

Code: Select all

min yearly price[EndUse Region]=SUM(min price[EndUse Region]*is year[year!])
where min price is caluculated as follows:

Code: Select all

min price[EndUse Region]=SAMPLE IF TRUE (average regional energy price[EndUse Region,now]<min price[EndUse Region], average regional energy price[EndUse Region,now] , average regional energy price[EndUse Region,now])
Average regional price is also calculated with this:

Code: Select all

average regional energy price[EndUse Region]=zidz(regional cumulative revenues[EndUse Region]*eurocents per euro*million unit,
cum regional energy produced[EndUse Region]*KW per MW*MW per GW) 
Since regional cumulative revenues is a stock and its initial point is zero SAMPLE IF TRUE generates zero.
One common way is using maximum as an initial value of minimum function, but it does not work here.
Post Reply