2
2
3
3
namespace PhpOffice \PhpSpreadsheet \Calculation \Statistical \Distributions ;
4
4
5
+ use PhpOffice \PhpSpreadsheet \Calculation \ArrayEnabled ;
5
6
use PhpOffice \PhpSpreadsheet \Calculation \Engineering ;
6
7
use PhpOffice \PhpSpreadsheet \Calculation \Exception ;
7
8
use PhpOffice \PhpSpreadsheet \Calculation \Functions ;
8
9
9
10
class Normal
10
11
{
12
+ use ArrayEnabled;
13
+
11
14
public const SQRT2PI = 2.5066282746310005024157652848110452530069867406099 ;
12
15
13
16
/**
@@ -18,17 +21,23 @@ class Normal
18
21
* testing.
19
22
*
20
23
* @param mixed $value Float value for which we want the probability
24
+ * Or can be an array of values
21
25
* @param mixed $mean Mean value as a float
26
+ * Or can be an array of values
22
27
* @param mixed $stdDev Standard Deviation as a float
28
+ * Or can be an array of values
23
29
* @param mixed $cumulative Boolean value indicating if we want the cdf (true) or the pdf (false)
30
+ * Or can be an array of values
24
31
*
25
- * @return float|string The result, or a string containing an error
32
+ * @return array|float|string The result, or a string containing an error
33
+ * If an array of numbers is passed as an argument, then the returned result will also be an array
34
+ * with the same dimensions
26
35
*/
27
36
public static function distribution ($ value , $ mean , $ stdDev , $ cumulative )
28
37
{
29
- $ value = Functions:: flattenSingleValue ( $ value );
30
- $ mean = Functions:: flattenSingleValue ( $ mean );
31
- $ stdDev = Functions:: flattenSingleValue ( $ stdDev );
38
+ if ( is_array ( $ value) || is_array ( $ mean ) || is_array ( $ stdDev ) || is_array ( $ cumulative )) {
39
+ return self :: evaluateArrayArguments ([ self ::class, __FUNCTION__ ], $ value , $ mean, $ stdDev , $ cumulative );
40
+ }
32
41
33
42
try {
34
43
$ value = DistributionValidations::validateFloat ($ value );
@@ -56,16 +65,21 @@ public static function distribution($value, $mean, $stdDev, $cumulative)
56
65
* Returns the inverse of the normal cumulative distribution for the specified mean and standard deviation.
57
66
*
58
67
* @param mixed $probability Float probability for which we want the value
68
+ * Or can be an array of values
59
69
* @param mixed $mean Mean Value as a float
70
+ * Or can be an array of values
60
71
* @param mixed $stdDev Standard Deviation as a float
72
+ * Or can be an array of values
61
73
*
62
- * @return float|string The result, or a string containing an error
74
+ * @return array|float|string The result, or a string containing an error
75
+ * If an array of numbers is passed as an argument, then the returned result will also be an array
76
+ * with the same dimensions
63
77
*/
64
78
public static function inverse ($ probability , $ mean , $ stdDev )
65
79
{
66
- $ probability = Functions:: flattenSingleValue ( $ probability );
67
- $ mean = Functions:: flattenSingleValue ( $ mean );
68
- $ stdDev = Functions:: flattenSingleValue ( $ stdDev );
80
+ if ( is_array ( $ probability) || is_array ( $ mean ) || is_array ( $ stdDev )) {
81
+ return self :: evaluateArrayArguments ([ self ::class, __FUNCTION__ ], $ probability , $ mean, $ stdDev );
82
+ }
69
83
70
84
try {
71
85
$ probability = DistributionValidations::validateProbability ($ probability );
0 commit comments