Maximum value
Maximum value
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.
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.
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
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))
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))
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
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
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
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
Personally, I'd use several variables. Nesting IF THEN ELSE statements makes your model very hard to read and debug.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
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
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 (6.54 KiB) Viewed 25559 times
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
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.
Thanks for the patience and agility in the answers.
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
... and if you want multiple intervals, put the same structure in an array, with one element per time interval to be considered.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Junior Member
- Posts: 2
- Joined: Sun Apr 14, 2019 5:39 pm
- Vensim version: PLE
Re: Maximum value
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)
Re: Maximum value
This seems to be working fine. T2 and T2max both reach their max values at time 2. What's the problem?
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
-
- Junior Member
- Posts: 2
- Joined: Sun Apr 14, 2019 5:39 pm
- Vensim version: PLE
Re: Maximum value
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.
Re: Maximum value
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.
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.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Maximum value
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
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 1215 times
-
- future_in_an_array.mdl
- (3.41 KiB) Downloaded 1118 times
Re: Maximum value
A complementary question for this one:
Is it possible to get the time which a given auxiliary achieved its maximum value in the simulation?
Is it possible to get the time which a given auxiliary achieved its maximum value in the simulation?
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
It works well for maximum. Is it correct for getting minimum?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 )
Code: Select all
MIN VALUE = SAMPLE IF TRUE ( A <MIN VALUE , A , A )
-
- Super Administrator
- Posts: 4827
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum value
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
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Units are important!
http://www.bbc.co.uk/news/magazine-27509559
Re: Maximum value
And you can also sample MAX TIME = SAMPLE IF TRUE ( A > MAX VALUE , Time, Time ) to capture when this occurs.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Maximum value
Do you have any suggestion why it always generates zero?
Re: Maximum value
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.
/*
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Advice to posters (it really helps us to help you)
http://www.ventanasystems.co.uk/forum/v ... f=2&t=4391
Blog: http://blog.metasd.com
Model library: http://models.metasd.com
Bookmarks: http://delicious.com/tomfid/SystemDynamics
*/
Re: Maximum value
Sounds plausible. There is one 0 in initialization step. Any idea to solve it?
Re: Maximum value
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!])
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])
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)
One common way is using maximum as an initial value of minimum function, but it does not work here.