• PHP Video Tutorials

PHP - Stats Dens Exponential() Function



Definition and Usage

The stats_dens_exponential() function is a probability density function of the exponential distribution.

Syntax

float stats_dens_exponential( float $x, float $scale )

Parameters

Sr.No Parameter Description
1

x

The value at which the probability density is calculated

2

scale

The scale of the distribution

Return Values

The stats_dens_exponential() function can return the probability density at x, where the random variable can follow the exponential distribution of which the scale is scale, or false for 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 each x.

<?php
   // check for each x
   foreach (range(-0.5, 2, 0.5) as $x) {
      var_dump(round(stats_dens_exponential($x, 2), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0)
    float(0.5)
    float(0.3894)
    float(0.303265)
    float(0.236183)
    float(0.18394)

Example

In the following example, we compute probability density for each scale.

<?php
   // check for each scale
   foreach (range(0.5, 2, 0.5) as $scale) {
      var_dump(round(stats_dens_exponential(1, $scale), 6));
      echo "<br>";
   }
?>

Output

This will produce following result −

  float(0.270671)
  float(0.367879)
  float(0.342278)
  float(0.303265)

Example

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

<?php
   // error cases
   var_dump(stats_dens_exponential(1, 0)); // scale = 0
?>

Output

This will produce following result and a warning in logs PHP Warning: stats_dens_exponential(): scale == 0.0

bool(false)
Advertisements