当前位置: 首页>>代码示例>>PHP>>正文


PHP square函数代码示例

本文整理汇总了PHP中square函数的典型用法代码示例。如果您正苦于以下问题:PHP square函数的具体用法?PHP square怎么用?PHP square使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了square函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getPlayerCovarianceMatrix

 private static function getPlayerCovarianceMatrix(array &$teamAssignmentsList)
 {
     // This is a square matrix whose diagonal values represent the variance (square of standard deviation) of all
     // players.
     return new DiagonalMatrix(self::getPlayerRatingValues($teamAssignmentsList, function ($rating) {
         return square($rating->getStandardDeviation());
     }));
 }
开发者ID:modulexcite,项目名称:PHPSkills,代码行数:8,代码来源:FactorGraphTrueSkillCalculator.php

示例2: even_square

function even_square($arr)
{
    foreach ($arr as $value) {
        if ($value % 2 == 0) {
            yield from square($value);
        }
    }
}
开发者ID:igorsimdyanov,项目名称:php7,代码行数:8,代码来源:combine_from.php

示例3: sumofsquares

function sumofsquares($n, $sum = 0)
{
    if ($n == 0) {
        return $sum;
    } else {
        $sum += square($n);
        return sumofsquares($n - 1, $sum);
    }
}
开发者ID:ajaybhatia,项目名称:php-scripts,代码行数:9,代码来源:sumofsquares.php

示例4: Mandelbrot

function Mandelbrot($x, $y)
{
    $z = 0;
    $c = array($x, $y);
    for ($i = 0; $i < N; ++$i) {
        $z = add(square($z), $c);
        if (value($z) > M) {
            return $i;
        }
    }
    return true;
}
开发者ID:Hepic,项目名称:web-class,代码行数:12,代码来源:fractal.php

示例5: testDivision

 public function testDivision()
 {
     // Since the multiplication was worked out by hand, we use the same numbers but work backwards
     $product = new GaussianDistribution(0.2, 3.0 / sqrt(10));
     $standardNormal = new GaussianDistribution(0, 1);
     $productDividedByStandardNormal = GaussianDistribution::divide($product, $standardNormal);
     $this->assertEquals(2.0, $productDividedByStandardNormal->getMean(), '', GaussianDistributionTest::ERROR_TOLERANCE);
     $this->assertEquals(3.0, $productDividedByStandardNormal->getStandardDeviation(), '', GaussianDistributionTest::ERROR_TOLERANCE);
     $product2 = new GaussianDistribution((4 * square(7) + 6 * square(5)) / (square(5) + square(7)), sqrt(square(5) * square(7) / (square(5) + square(7))));
     $m4s5 = new GaussianDistribution(4, 5);
     $product2DividedByM4S5 = GaussianDistribution::divide($product2, $m4s5);
     $this->assertEquals(6.0, $product2DividedByM4S5->getMean(), '', GaussianDistributionTest::ERROR_TOLERANCE);
     $this->assertEquals(7.0, $product2DividedByM4S5->getStandardDeviation(), '', GaussianDistributionTest::ERROR_TOLERANCE);
 }
开发者ID:modulexcite,项目名称:PHPSkills,代码行数:14,代码来源:GaussianDistributionTest.php

示例6: similarly

function similarly($r, $g, $b, $color)
{
    return 1 / (1 + sqrt(square($r - $color[0]) + square($g - $color[1]) + square($b - $color[2])));
}
开发者ID:nigohiroki,项目名称:RubiksCube,代码行数:4,代码来源:index.php

示例7: displayResults


//.........这里部分代码省略.........
         //5 = 5 Point Scale
         //A = Array (5 Point Choice)
         if ($outputs['qtype'] == "5" || $outputs['qtype'] == "A") {
             $stddev = 0;
             $stddevarray = array_slice($grawdata, 0, 5, true);
             $am = 0;
             //calculate arithmetic mean
             if (isset($sumitems) && $sumitems > 0) {
                 //calculate and round results
                 //there are always 5 items
                 for ($x = 0; $x < 5; $x++) {
                     //create product of item * value
                     $am += ($x + 1) * $stddevarray[$x];
                 }
                 //prevent division by zero
                 if (isset($stddevarray) && array_sum($stddevarray) > 0) {
                     $am = round($am / array_sum($stddevarray), 2);
                 } else {
                     $am = 0;
                 }
                 //calculate standard deviation -> loop through all data
                 /*
                  * four steps to calculate the standard deviation
                  * 1 = calculate difference between item and arithmetic mean and multiply with the number of elements
                  * 2 = create sqaure value of difference
                  * 3 = sum up square values
                  * 4 = multiply result with 1 / (number of items)
                  * 5 = get root
                  */
                 for ($j = 0; $j < 5; $j++) {
                     //1 = calculate difference between item and arithmetic mean
                     $diff = $j + 1 - $am;
                     //2 = create square value of difference
                     $squarevalue = square($diff);
                     //3 = sum up square values and multiply them with the occurence
                     //prevent divison by zero
                     if ($squarevalue != 0 && $stddevarray[$j] != 0) {
                         $stddev += $squarevalue * $stddevarray[$j];
                     }
                 }
                 //4 = multiply result with 1 / (number of items (=5))
                 //There are two different formulas to calculate standard derivation
                 //$stddev = $stddev / array_sum($stddevarray);        //formula source: http://de.wikipedia.org/wiki/Standardabweichung
                 //prevent division by zero
                 if (array_sum($stddevarray) - 1 != 0 && $stddev != 0) {
                     $stddev = $stddev / (array_sum($stddevarray) - 1);
                     //formula source: http://de.wikipedia.org/wiki/Empirische_Varianz
                 } else {
                     $stddev = 0;
                 }
                 //5 = get root
                 $stddev = sqrt($stddev);
                 $stddev = round($stddev, 2);
             }
             switch ($outputType) {
                 case 'xls':
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Arithmetic mean"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $am);
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Standard deviation"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $stddev);
                     break;
                 case 'pdf':
                     $tablePDF[] = array(gT("Arithmetic mean"), $am, '', '');
                     $tablePDF[] = array(gT("Standard deviation"), $stddev, '', '');
开发者ID:jgianpiere,项目名称:lime-survey,代码行数:67,代码来源:statistics_helper.php

示例8: calculateMatchQuality

 /**
  * {@inheritdoc }
  */
 public function calculateMatchQuality(GameInfo &$gameInfo, array &$teams)
 {
     Guard::argumentNotNull($gameInfo, "gameInfo");
     $this->validateTeamCountAndPlayersCountPerTeam($teams);
     // We've verified that there's just two teams
     $team1Ratings = $teams[0]->getAllRatings();
     $team1Count = count($team1Ratings);
     $team2Ratings = $teams[1]->getAllRatings();
     $team2Count = count($team2Ratings);
     $totalPlayers = $team1Count + $team2Count;
     $betaSquared = square($gameInfo->getBeta());
     $meanGetter = function ($currentRating) {
         return $currentRating->getMean();
     };
     $varianceGetter = function ($currentRating) {
         return square($currentRating->getStandardDeviation());
     };
     $team1MeanSum = sum($team1Ratings, $meanGetter);
     $team1StdDevSquared = sum($team1Ratings, $varianceGetter);
     $team2MeanSum = sum($team2Ratings, $meanGetter);
     $team2SigmaSquared = sum($team2Ratings, $varianceGetter);
     // This comes from equation 4.1 in the TrueSkill paper on page 8
     // The equation was broken up into the part under the square root sign and
     // the exponential part to make the code easier to read.
     $sqrtPart = sqrt($totalPlayers * $betaSquared / ($totalPlayers * $betaSquared + $team1StdDevSquared + $team2SigmaSquared));
     $expPart = exp(-1 * square($team1MeanSum - $team2MeanSum) / (2 * ($totalPlayers * $betaSquared + $team1StdDevSquared + $team2SigmaSquared)));
     return $expPart * $sqrtPart;
 }
开发者ID:ramn,项目名称:ants-tcp,代码行数:31,代码来源:TwoTeamTrueSkillCalculator.php

示例9: generate_statistics


//.........这里部分代码省略.........
                            {
                                //create product of item * value
                                $am += (($x+1) * $stddevarray[$x]);
                            }

                            //prevent division by zero
                            if(isset($stddevarray) && array_sum($stddevarray) > 0)
                            {
                                $am = round($am / array_sum($stddevarray),2);
                            }
                            else
                            {
                                $am = 0;
                            }

                            //calculate standard deviation -> loop through all data
                            /*
                             * four steps to calculate the standard deviation
                             * 1 = calculate difference between item and arithmetic mean and multiply with the number of elements
                             * 2 = create sqaure value of difference
                             * 3 = sum up square values
                             * 4 = multiply result with 1 / (number of items)
                             * 5 = get root
                             */



                            for($j = 0; $j < 5; $j++)
                            {
                                //1 = calculate difference between item and arithmetic mean
                                $diff = (($j+1) - $am);

                                //2 = create square value of difference
                                $squarevalue = square($diff);

                                //3 = sum up square values and multiply them with the occurence
                                //prevent divison by zero
                                if($squarevalue != 0 && $stddevarray[$j] != 0)
                                {
                                    $stddev += $squarevalue * $stddevarray[$j];
                                }

                            }

                            //4 = multiply result with 1 / (number of items (=5))
                            //There are two different formulas to calculate standard derivation
                            //$stddev = $stddev / array_sum($stddevarray);		//formula source: http://de.wikipedia.org/wiki/Standardabweichung

                            //prevent division by zero
                            if((array_sum($stddevarray)-1) != 0 && $stddev != 0)
                            {
                                $stddev = $stddev / (array_sum($stddevarray)-1);	//formula source: http://de.wikipedia.org/wiki/Empirische_Varianz
                            }
                            else
                            {
                                $stddev = 0;
                            }

                            //5 = get root
                            $stddev = sqrt($stddev);
                            $stddev = round($stddev,2);
                        }
                        switch($outputType)
                        {
                            case 'xls':
开发者ID:nmklong,项目名称:limesurvey-cdio3,代码行数:66,代码来源:statistics_function.php

示例10: displayResults


//.........这里部分代码省略.........
         //5 = 5 Point Scale
         //A = Array (5 Point Choice)
         if ($outputs['qtype'] == "5" || $outputs['qtype'] == "A") {
             $stddev = 0;
             $stddevarray = array_slice($grawdata, 0, 5, true);
             $am = 0;
             //calculate arithmetic mean
             if (isset($sumitems) && $sumitems > 0) {
                 //calculate and round results
                 //there are always 5 items
                 for ($x = 0; $x < 5; $x++) {
                     //create product of item * value
                     $am += ($x + 1) * $stddevarray[$x];
                 }
                 //prevent division by zero
                 if (isset($stddevarray) && array_sum($stddevarray) > 0) {
                     $am = round($am / array_sum($stddevarray), 2);
                 } else {
                     $am = 0;
                 }
                 //calculate standard deviation -> loop through all data
                 /*
                  * four steps to calculate the standard deviation
                  * 1 = calculate difference between item and arithmetic mean and multiply with the number of elements
                  * 2 = create sqaure value of difference
                  * 3 = sum up square values
                  * 4 = multiply result with 1 / (number of items)
                  * 5 = get root
                  */
                 for ($j = 0; $j < 5; $j++) {
                     //1 = calculate difference between item and arithmetic mean
                     $diff = $j + 1 - $am;
                     //2 = create square value of difference
                     $squarevalue = square($diff);
                     //3 = sum up square values and multiply them with the occurence
                     //prevent divison by zero
                     if ($squarevalue != 0 && $stddevarray[$j] != 0) {
                         $stddev += $squarevalue * $stddevarray[$j];
                     }
                 }
                 //4 = multiply result with 1 / (number of items (=5))
                 //There are two different formulas to calculate standard derivation
                 //$stddev = $stddev / array_sum($stddevarray);        //formula source: http://de.wikipedia.org/wiki/Standardabweichung
                 //prevent division by zero
                 if (array_sum($stddevarray) - 1 != 0 && $stddev != 0) {
                     $stddev = $stddev / (array_sum($stddevarray) - 1);
                     //formula source: http://de.wikipedia.org/wiki/Empirische_Varianz
                 } else {
                     $stddev = 0;
                 }
                 //5 = get root
                 $stddev = sqrt($stddev);
                 $stddev = round($stddev, 2);
             }
             switch ($outputType) {
                 case 'xls':
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Arithmetic mean"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $am);
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Standard deviation"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $stddev);
                     break;
                 case 'pdf':
                     $tablePDF[] = array(gT("Arithmetic mean"), $am, '', '');
                     $tablePDF[] = array(gT("Standard deviation"), $stddev, '', '');
开发者ID:krsandesh,项目名称:LimeSurvey,代码行数:67,代码来源:statistics_helper.php

示例11: displayResults


//.........这里部分代码省略.........
         //5 = 5 Point Scale
         //A = Array (5 Point Choice)
         if ($outputs['qtype'] == "5" || $outputs['qtype'] == "A") {
             $stddev = 0;
             $stddevarray = array_slice($grawdata, 0, 5, true);
             $am = 0;
             //calculate arithmetic mean
             if (isset($sumitems) && $sumitems > 0) {
                 //calculate and round results
                 //there are always 5 items
                 for ($x = 0; $x < 5; $x++) {
                     //create product of item * value
                     $am += ($x + 1) * $stddevarray[$x];
                 }
                 //prevent division by zero
                 if (isset($stddevarray) && array_sum($stddevarray) > 0) {
                     $am = round($am / array_sum($stddevarray), 2);
                 } else {
                     $am = 0;
                 }
                 //calculate standard deviation -> loop through all data
                 /*
                  * four steps to calculate the standard deviation
                  * 1 = calculate difference between item and arithmetic mean and multiply with the number of elements
                  * 2 = create sqaure value of difference
                  * 3 = sum up square values
                  * 4 = multiply result with 1 / (number of items)
                  * 5 = get root
                  */
                 for ($j = 0; $j < 5; $j++) {
                     //1 = calculate difference between item and arithmetic mean
                     $diff = $j + 1 - $am;
                     //2 = create square value of difference
                     $squarevalue = square($diff);
                     //3 = sum up square values and multiply them with the occurence
                     //prevent divison by zero
                     if ($squarevalue != 0 && $stddevarray[$j] != 0) {
                         $stddev += $squarevalue * $stddevarray[$j];
                     }
                 }
                 //4 = multiply result with 1 / (number of items (=5))
                 //There are two different formulas to calculate standard derivation
                 //$stddev = $stddev / array_sum($stddevarray);        //formula source: http://de.wikipedia.org/wiki/Standardabweichung
                 //prevent division by zero
                 if (array_sum($stddevarray) - 1 != 0 && $stddev != 0) {
                     $stddev = $stddev / (array_sum($stddevarray) - 1);
                     //formula source: http://de.wikipedia.org/wiki/Empirische_Varianz
                 } else {
                     $stddev = 0;
                 }
                 //5 = get root
                 $stddev = sqrt($stddev);
                 $stddev = round($stddev, 2);
             }
             switch ($outputType) {
                 case 'xls':
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Arithmetic mean"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $am);
                     $this->xlsRow++;
                     $this->sheet->write($this->xlsRow, 0, gT("Standard deviation"));
                     $this->sheet->writeNumber($this->xlsRow, 1, $stddev);
                     break;
                 case 'pdf':
                     $tablePDF[] = array(gT("Arithmetic mean"), $am, '', '');
                     $tablePDF[] = array(gT("Standard deviation"), $stddev, '', '');
开发者ID:mfavetti,项目名称:LimeSurvey,代码行数:67,代码来源:statistics_helper.php

示例12: switch

$age = 7;
switch (true) {
    case $age < 5:
        // no school for you! *snap*
        break;
    case $age > 4 && $age < 13:
        // grade school
        break;
    case $age > 12 && $age < 18:
        // high school
        break;
    case $age > 17:
        // adult ed
        break;
    default:
        // ??? get a job then
        break;
}
$a = 10;
function foo()
{
    $a = 5;
}
function square(&$val)
{
    $val = $val * $val;
    return $val;
}
echo '<p>' . $a . '</p>';
echo '<p>' . square($a) . '</p>';
echo '<p>' . $a . '</p>';
开发者ID:seelang2,项目名称:ClassArchive,代码行数:31,代码来源:example1.php

示例13: square

// Step 1. Do the following drills & exercises in PHP.
// Step 2. Commit your answers to github and send me the link. Call the file "drills.php" or something similar.
// Step 3. Don't forget to go into `vagrant ssh` and do `php -a` if you need a PHP console for rapid testing out of ideas.
// Step 4. Don't forget to use PHP's internal functions. They make your tasks easier!
// Step 5. If you're stuck, Google the heck out of stuff and search StackOverflow for solutions.
// Write a function that takes in a number and returns the number multiplied by itself.
// Make a function that takes in a string and returns it capitalized. If the input is not a string, return false.
// Make a function that takes in a string and returns it lowercased. If the input is not a string, return false.
// Write a function called isVowel that takes in a single character and returns true if the character is a vowel, false if not.
// Write a function called countVowels that takes in a string and returns the number of vowels in the string.
function square($number)
{
    $square = $number * $number;
    return $square;
}
echo square(7);
//
function upperCase($string)
{
    if (!is_string($string)) {
        return false;
    }
}
return strtoupper($string);
echo upperCase([]);
echo upperCase("foo");
//
function lowerCase($string)
{
    if (!is_string($string)) {
        return false;
开发者ID:Craig240z,项目名称:CodeUp-Web-Exercises,代码行数:31,代码来源:drills.php

示例14: foreach

}
?>
<style type="text/css">
.square {
    margin:2px; 
    float:left; 
    text-align:center; 
    position:relative; 
    height:50px; 
    width:50px;
    font-size:6pt;
    font-family:Arial, Verdana, sans-serif;
}
</style>
<?php 
echo '<table border="0" cellpadding="8" cellspacing="0"><tr valign="top"><td id="palette" style="width:312px;">';
foreach ($theme as $t) {
    square($t);
}
shuffle($theme);
foreach ($theme as $t) {
    square($t);
}
echo '</td>';
echo '<td>';
echo '<div style="height:800px; overflow:scroll">';
foreach ($rgb_table as $t => $nop) {
    square($t);
}
echo '</div>';
echo '</td></tr></table>';
开发者ID:pombredanne,项目名称:tuleap,代码行数:31,代码来源:jpgraphColorChooser.php

示例15: soma

    static $total;
    $total += $km;
    return $km;
}
// print($total);
print $line;
// ----------------------------------------------------------
//imprimir diretamente o valor retornado
print soma(2, 4, 6);
function soma($num1, $num2, $num3)
{
    return $num1 + $num2 + $num3;
}
print $line;
// ----------------------------------------------------------
print square(4);
print $line;
// ----------------------------------------------------------
//TRABALHANDO COM ARRAYS!
//Uma maneira de montar um array simples
$vet = array('maça', 'laranja', 'banana', 'pera', 'abacaxi');
//Segunda maneira de montar array ASSOCIATIVO, onde informo a chave e o seu valor
$vet2 = array("maça" => "vermelha", "laranja" => "Adivinha", "banana" => 3, "pera" => 4, "abacaxi" => 5, "abacate" => "verde com caroço");
//Terceira maneira de montar um array simples
$vet3[] = "Maria";
$vet3[] = "José";
$vet3[] = "Ricardo";
$vet3[] = "Jucelina";
$vet3[] = "Astrogildo";
//Quarta maneira de montar um vetor em formato ASSOCIATIVO
$vet4["nome"] = "Maria da Silva";
开发者ID:jfpadilha,项目名称:basicExercisesPhp,代码行数:31,代码来源:index.php


注:本文中的square函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。