PHP Doku:: Returns the harmonic mean of an array of values - function.stats-harmonic-mean.html

Verlauf / Chronik / History: (50) anzeigen

Sie sind hier:
Doku-StartseitePHP-HandbuchFunktionsreferenzMathematische ErweiterungenStatisticsStatistic Funktionenstats_harmonic_mean

Ein Service von Reinhard Neidl - Webprogrammierung.

Verdiene Geld mit Deiner Homepage oder deinem Blog: Setzte eine Textlinkwerbung und bestimme den Preis selber.
Einfach kostenlos anmelden und einen Platz auf Deiner Homepage anbieten.
Make money with your homepage or blog: Set a text link advertising and declare the price.
Register free of charge and offer a place on your homepage.
Statistic Funktionen

<<stats_dens_weibull

stats_kurtosis>>

stats_harmonic_mean

(PECL stats >= 1.0.0)

stats_harmonic_meanReturns the harmonic mean of an array of values

Beschreibung

number stats_harmonic_mean ( array $a )
Warnung

Diese Funktion ist bis jetzt nicht dokumentiert. Es steht nur die Liste der Argumente zur Verfügung.

Parameter-Liste

a

Rückgabewerte


Verdiene Geld mit Deiner Homepage oder deinem Blog: Setzte eine Textlinkwerbung und bestimme den Preis selber.
Einfach kostenlos anmelden und einen Platz auf Deiner Homepage anbieten.
Make money with your homepage or blog: Set a text link advertising and declare the price.
Register free of charge and offer a place on your homepage.
Ein BenutzerBeitrag:
- Beiträge aktualisieren...
Daniel Morris (www.danielxmorris.com)
15.08.2008 16:51
I wrote this to calculate harmonic averages in my shares program.  Hopefully this can help someone who doesn't want to use PECL.  The function accepts an unlimited number of arguments without the need to place them into an array, which is better than the way the PECL extension handles the function.

<?php

/**
 *  @author    Daniel Morris
*/
function harmonic () {
   
$num_args = func_num_args ();
    for (
$i = 0; $i < $num_args; $i++) {
       
$sum += 1 / func_get_arg ($i);
    }
    return
$num_args / $sum;
}

// Tests

echo harmonic (1, 2, 3, 4, 5);
echo
harmonic (-1, 3, 4, 10293);
echo
harmonic (-1, -2, -3, -4, -5);

//  2.1897810218978
//  -9.6022389365052
//  -2.1897810218978 

?>



PHP Powered Diese Seite bei php.net
The PHP manual text and comments are covered by the Creative Commons Attribution 3.0 License © the PHP Documentation Group - Impressum - mail("TO:Reinhard Neidl",...)