README.md (4040B)
1 <!-- 2 3 @license Apache-2.0 4 5 Copyright (c) 2018 The Stdlib Authors. 6 7 Licensed under the Apache License, Version 2.0 (the "License"); 8 you may not use this file except in compliance with the License. 9 You may obtain a copy of the License at 10 11 http://www.apache.org/licenses/LICENSE-2.0 12 13 Unless required by applicable law or agreed to in writing, software 14 distributed under the License is distributed on an "AS IS" BASIS, 15 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 16 See the License for the specific language governing permissions and 17 limitations under the License. 18 19 --> 20 21 # Mean 22 23 > [Triangular][triangular-distribution] distribution [expected value][expected-value]. 24 25 <!-- Section to include introductory text. Make sure to keep an empty line after the intro `section` element and another before the `/section` close. --> 26 27 <section class="intro"> 28 29 The [mean][expected-value] for a [triangular][triangular-distribution] random variable is 30 31 <!-- <equation class="equation" label="eq:triangular_mean" align="center" raw="\mathbb{E} \left[ X \right] = \frac{a+b+c}{3}" alt="Mean for a triangular distribution."> --> 32 33 <div class="equation" align="center" data-raw-text="\mathbb{E} \left[ X \right] = \frac{a+b+c}{3}" data-equation="eq:triangular_mean"> 34 <img src="https://cdn.jsdelivr.net/gh/stdlib-js/stdlib@51534079fef45e990850102147e8945fb023d1d0/lib/node_modules/@stdlib/stats/base/dists/triangular/mean/docs/img/equation_triangular_mean.svg" alt="Mean for a triangular distribution."> 35 <br> 36 </div> 37 38 <!-- </equation> --> 39 40 where `a` is the lower limit, `b` is the upper limit and `c` is the mode. 41 42 </section> 43 44 <!-- /.intro --> 45 46 <!-- Package usage documentation. --> 47 48 <section class="usage"> 49 50 ## Usage 51 52 ```javascript 53 var mean = require( '@stdlib/stats/base/dists/triangular/mean' ); 54 ``` 55 56 #### mean( a, b, c ) 57 58 Returns the [expected value][expected-value] of a [triangular][triangular-distribution] distribution with parameters `a` (minimum support), `b` (maximum support), and `c` (mode). 59 60 ```javascript 61 var v = mean( 0.0, 1.0, 0.8 ); 62 // returns ~0.6 63 64 v = mean( 4.0, 12.0, 5.0 ); 65 // returns 7.0 66 67 v = mean( 2.0, 8.0, 5.0 ); 68 // returns 5.0 69 ``` 70 71 If provided `NaN` as any argument, the function returns `NaN`. 72 73 ```javascript 74 var v = mean( NaN, 4.0, 2.0 ); 75 // returns NaN 76 77 v = mean( 0.0, NaN, 2.0 ); 78 // returns NaN 79 80 v = mean( 0.0, 4.0, NaN ); 81 // returns NaN 82 ``` 83 84 If provided parameters not satisfying `a <= c <= b`, the function returns `NaN`. 85 86 ```javascript 87 var y = mean( 1.0, 0.0, 1.5 ); 88 // returns NaN 89 90 y = mean( 0.0, 1.0, -1.0 ); 91 // returns NaN 92 93 y = mean( 0.0, -1.0, 0.5 ); 94 // returns NaN 95 ``` 96 97 </section> 98 99 <!-- /.usage --> 100 101 <!-- Package usage notes. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 102 103 <section class="notes"> 104 105 </section> 106 107 <!-- /.notes --> 108 109 <!-- Package usage examples. --> 110 111 <section class="examples"> 112 113 ## Examples 114 115 <!-- eslint no-undef: "error" --> 116 117 ```javascript 118 var randu = require( '@stdlib/random/base/randu' ); 119 var mean = require( '@stdlib/stats/base/dists/triangular/mean' ); 120 121 var a; 122 var b; 123 var c; 124 var v; 125 var i; 126 127 for ( i = 0; i < 10; i++ ) { 128 a = ( randu()*10.0 ); 129 b = ( randu()*10.0 ) + a; 130 c = ( randu()*( b-a ) ) + a; 131 v = mean( a, b, c ); 132 console.log( 'a: %d, b: %d, c: %d, E(X;a,b,c): %d', a.toFixed( 4 ), b.toFixed( 4 ), c.toFixed( 4 ), v.toFixed( 4 ) ); 133 } 134 ``` 135 136 </section> 137 138 <!-- /.examples --> 139 140 <!-- Section to include cited references. If references are included, add a horizontal rule *before* the section. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 141 142 <section class="references"> 143 144 </section> 145 146 <!-- /.references --> 147 148 <!-- Section for all links. Make sure to keep an empty line after the `section` element and another before the `/section` close. --> 149 150 <section class="links"> 151 152 [triangular-distribution]: https://en.wikipedia.org/wiki/Triangular_distribution 153 154 [expected-value]: https://en.wikipedia.org/wiki/Expected_value 155 156 </section> 157 158 <!-- /.links -->