Maximum and average
Maximum and average
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 ),....
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 ),....
Re: Maximum and average
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.
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.
/*
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 and average
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.
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.
Re: Maximum and average
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:
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.
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
/*
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 and average
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?
And to make the sum of these values after calculating the average, which function can I use?
Re: Maximum and average
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 ...
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 ...
Re: Maximum and average
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 )
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 )
/*
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 and average
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.
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.
-
- Super Administrator
- Posts: 4610
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum and average
Can you post the equation you are using? And is this actually giving you the maximum over all time?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?
Use a level (INTEG). Cumulative value = integ(variable,0)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.
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 and average
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.
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.
-
- Super Administrator
- Posts: 4610
- Joined: Wed Mar 05, 2003 3:10 am
Re: Maximum and average
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.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.
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 and average
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.
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.
/*
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
*/