Maximum and average

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

Maximum and average

Post by Priscila »

How to obtain the maximum value of all the simulation time of an auxiliary variable?
For example : 1,2,3,4,5,6,7,8
maximum = 8
How to get the average value of an auxiliary variable , jumping from four ?
For example : Values ​​1,2,3,4,5,6,7,8,...
Average = ( ( 1 + 2 + 3 + 4 ) / 4 ) , ( ( 5 + 6 + 7 + 8 ) / 4 ),....
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Maximum and average

Post by tomfid »

You can use the Stats tool if you just need to report these values.

If you need them for use in an equation, you can use SAMPLE IF TRUE for the max. You can compute the average with a stock, or use a SMOOTH for a moving average.

If you tell us a little more about what you're trying to do, we can suggest more specific options.
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum and average

Post by Priscila »

My final result depends on these two variables , I need them providing results within the simulation . If the maximum value have a variable assist " Reduced demand in tip " that varies over time 0-2687 hours and need to get the most out of this variable to enter the variable "contract exceeding value " where this value is multiplied by a constant.
In case of need average obtain the average every four values ​​of the variable " Reduced demand at peak " , that is, from time 0 to 4 , time 5 to 8 and so on , yielding a variable called " low consumption " with time 0-671 hours.
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Maximum and average

Post by tomfid »

For the Max, see the first example in https://www.vensim.com/documentation/fn ... f_true.htm

Also:
http://www.ventanasystems.co.uk/forum/v ... LE+IF+TRUE

For the moving average, you can build a structure like:

Code: Select all

average X = Sum X / Averaging Period 
	Units: stuff
	
Averaging Period = 4
	Units: time
	
initial average = 0
	Units: stuff
	
Sum X = INTEG( X in - X out , initial average * Averaging Period ) 
	Units: stuff*time
	
X = RANDOM UNIFORM ( 0, 1, 0) 
	Units: stuff
	
X in = X 
	Units: stuff
	
X out = DELAY FIXED ( X in ,Averaging Period , initial average ) 
	Units: Dmnl
Note that the average will lag by one TIME STEP (though this can be corrected if necessary). A SMOOTH may be a simpler and more realistic choice in many cases.
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum and average

Post by Priscila »

With this code is very complicated and the outcome is not expected, there is a simpler way to do the average calculation ? Could you give me an example for the case presented using the SMOOTH function. I need the variable average is calculated and displayed every four values
And to make the sum of these values ​​after calculating the average, which function can I use?
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum and average

Post by Priscila »

With this code, the program calculates the average but I need the result to four and the rest zero.
For example :
Time = 0,1,2,3,4,5,6,7,8,9,10,11 ...
Data = 8,9,4,7,2,6,5,3,2,4,5,4 , ...
mean = 0,0,0,7,0,0,0,4,0,0,0,3.75 ...
tomfid
Administrator
Posts: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Maximum and average

Post by tomfid »

average x = SMOOTH(x,interval) gives an exponentially weighted moving average of x with mean horizon of interval.

If you need 0s in between, you can use something like:

avg or 0 = IF THEN ELSE( PULSE TRAIN(initial time, time step, interval, final time), average x, 0 )
Priscila
Senior Member
Posts: 51
Joined: Thu Aug 25, 2016 1:11 pm
Vensim version: PRO

Re: Maximum and average

Post by Priscila »

Thank you for quick return , suggestions are working but still have some questions .

To calculate the maximum value am using the SAMPLE IF TRUE function but I'm getting a graph with a step at the beginning and takes the maximum value over all the time , how can I solve this?

Also I need to perform a sum of all the values ​​of a variable, which function can I use? Since the SUM function only sum vectors.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum and average

Post by Administrator »

Priscila wrote:To calculate the maximum value am using the SAMPLE IF TRUE function but I'm getting a graph with a step at the beginning and takes the maximum value over all the time , how can I solve this?
Can you post the equation you are using? And is this actually giving you the maximum over all time?
Also I need to perform a sum of all the values ​​of a variable, which function can I use? Since the SUM function only sum vectors.
Use a level (INTEG). Cumulative value = integ(variable,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 and average

Post by Priscila »

The equation is Maximum demand = SAMPLE IF TRUE (Maximum demand <reduced demand, reduced demand, Stores)
With this equation can get the most value from the time 32 but need to get the maximum value from the initial time to the end time.

In the case of the sum indicated by equation get a ramp and as accurate value for the maximum of only one value, without varying in time.
Administrator
Super Administrator
Posts: 4590
Joined: Wed Mar 05, 2003 3:10 am

Re: Maximum and average

Post by Administrator »

With this equation can get the most value from the time 32 but need to get the maximum value from the initial time to the end time.
This cannot be done. All you can really do is run the model once to calculate the value, then use it as an input when running the model a 2nd time.
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: 3811
Joined: Wed May 24, 2006 4:54 am

Re: Maximum and average

Post by tomfid »

The reason you can't retrieve values of variables ahead of time in Vensim is that this creates an acausal model. No one can really look into the future; they have expectations of the future, not knowledge. Normally the right way to solve the problem is to model those expectations explicitly.

If you need a future value for some technical reason, there is sometimes an iterative method or other trick for working it out, but it won't be pretty.
Post Reply