Jump to content

funcion pi php


Recommended Posts

<?php
function my_pi($ex){
$n=$ex;
$a[0]=1;
$b[0]=1/pow(2,1/2);
$t[0]=1/4;
$p[0]=$a[0];
for($i=0;$i<=$n;$i++){
$j=$i+1;
$a[$j] = ($a[$j-1]+$b[$j-1])/2;
$b[$j] = pow($a[$j-1]*$b[$j-1],1/2);
$p[$j] = 2*$p[$j-1];
$t[$j] = $t[$j-1]-($p[$j-1]*pow($a[$j-1]-$a[$j],2));
}
return number_format(pow($a[$n]+$b[$n],2)/(4*$t[$n]),$n);
}
echo my_pi(40);
?>

 

mientras mas grande el argumento mas excacto el valor de pi

Edited by cañangasñangas
Link to comment
Share on other sites

  • 1 year later...

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...