• PHP Video Tutorials

PHP - Stats Dens Uniform() Function



Definition and Usage

The stats_dens_uniform() function is a probability density function of the uniform distribution.

Syntax

  float stats_dens_uniform( float $x, float $a, float $b )

Parameters

Sr.No Parameter Description
1

x

The value at which the probability density is calculated

2

a

The lower bound of the distribution

3

b

The upper bound of the distribution

Return Values

The stats_dens_uniform() function can return the probability density at x, where the random variable can follow the uniform distribution in which the lower bound is a, and the upper bound is b. This function can return false on failure.

Dependencies

This function was first introduced in statistics extension (PHP 4.0.0 and PEAR 1.4.0). We have used latest release of stats-2.0.3 (PHP 7.0.0 or newer and PEAR 1.4.0 or newer) for this tutorial

Example

In the following example, we compute probability density for condition A <= X <= B.

<?php
   var_dump(stats_dens_uniform(2.5, 1, 3));    // A <= X <= B
?>

Output

This will produce following result −

float(0.5)

Example

In the following example, we compute probability density for condition X < A.

<?php
   var_dump(stats_dens_uniform(0, 1, 3));      // X < A
?>

Output

This will produce following result −

float(0)

Example

In the following example, we compute probability density for condition X > B.

<?php
   var_dump(stats_dens_uniform(4, 1, 3));      // X > B
?>

Output

This will produce following result −

float(0)

Example

Following is an error case. In the following example, we pass A == B. A warning is displayed in logs.

<?php
   // error cases
   var_dump(stats_dens_uniform(1, 1, 1));      // A == B
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_dens_uniform(): b == a == 1.000000E+0

bool(false)
Advertisements