$maxf)
{
echo 'abs(f) > '.$maxf;
echo "
";
$itest=0;
}
return $itest;
}
function df(&$fx, $x, $p,$k)
{
global $ipreci,$eps,$maxf,$maxfx,$maxk;
$itest=1;
dTk($Tx,$x,$p,$k);
$fx=bcsub("1",$Tx,$ipreci);
if(abs($fx)>$maxfx)
{
echo 'abs(fx) > '.$maxfx;
echo "
";
$itest=0;
}
return $itest;
}
function T(&$x1, $x, $p)
{
global $ipreci,$eps,$maxf,$maxfx,$maxk;
$itest=1;
$coef="2";
$m=bcmul($coef,$x,$ipreci);
$m2=bcmul($m,$x,$ipreci);
$x1=bcsub($m2,$p,$ipreci);
if(abs($x1)>$maxf)
{
echo 'abs(T) > '.$maxf;
echo "
";
$itest=0;
}
return $itest;
}
function dT(&$Tx, $x, $p)
{
global $ipreci,$eps,$maxf,$maxfx,$maxk;
$itest=1;
$coef="4";
$Tx=bcmul($coef,$x,$ipreci);
if(abs($Tx)>$maxfx)
{
echo 'abs(Tx) > '.$maxfx;
echo "
";
$itest=0;
}
return $itest;
}
function Tk(&$xk, $x, $p ,$k)
{
global $ipreci,$eps,$maxf,$maxfx,$maxk;
If($k>$maxk)
{
echo 'le nombre d\'itération '.$k.' est supérieur à '.$maxk;
echo "
";
$itest=0;
return $itest;
}
$itest=1;
$x0=$x;
if($k==0)
$xk=$x0;
else
{
for($i=1; $i<=$k; $i++)
{
$itest=T($xk,$x0,$p);
if($itest==0)
{
echo 'fin du calcul de Tk pour k = '.$i;
"
";
$itest=0;
return $itest;
}
$x0=$xk;
}
}
return $itest;
}
function dTk(&$Tkx, $x, $p, $k)
{
global $ipreci,$eps,$maxf,$maxfx,$maxk;
$itest=1;
dT($T1x,$x,$p);
if($k==1)
{
$Tkx=$T1x;
return 1;
}
for($i=2;$i<=$k;$i++)
{
T($x1,$x,$p);
dT($T1x,$x1,$p);
$T2x=bcmul($Tx,T1x,$ipreci);
$x=$x1;
$T1x=$T2x;
}
$Tkx=$T2x;
return $itest;
}
function newton(&$xn,$x,$p,$k,$n)
{
global $ipreci,$eps,$maxf,$maxfx,$maxk;
echo 'le test d\'arrêt de la méthode de Newton est en '.$eps;
"
";
$itest=1;
$x0=$x;
for($i=1; $i<=$n; $i++)
{
if($i>$maxk)
{
echo 'trop d\'itérations dans Newton maxk='.$maxk;
$itest=0;
return $itest;
}
$itest=f($xn,$x0,$p,$k);
if($itest==1)
$itest=df($fxn,$x0,$p,$k);
else
{
echo 'dérivée trop grande dans l\'itération de Newton';
return $itest;
}
if($itest==0)
{
echo 'fin de la méthode de Newton à l\'itération '.$i;
echo "
";
return $itest;
}
if($fxn==0)
{
echo 'dérivée nulle dans l\'itération de Newton';
echo "
";
$itest=0;
return $itest;
}
$dxn=bcdiv($xn,$fxn,$ipreci);
$xn=bcsub($x0,$dxn,$ipreci);
echo ' x'.$i.'='.$xn;
echo "
";
if(bccomp($xn,$x0,$ipreci)==0)
{
echo 'l\'itération de Newton converge en '.$i.' itérations'."
";
return 1;
}
$x0=$xn;
}
echo 'fin de l\'itération de Newton après '.$i.' itérations'."
";
return $itest;
}
$x=$_POST['inivar'];
$p=$_POST['inipara'];
$k=$_POST['inik'];
$ipreci=$_POST['inipreci'];
$itest=bcscale($ipreci);
if($itest==1)
echo 'la précision est '.$ipreci.' décimales';
else
echo 'erreur : pas de précision avec '.$ipreci.' décimales';
echo "
";
$eps="0.1";
$eps=bcpow($eps,$ipreci,$ipreci);
$n=20;
newton($xk,$x,$p,$k,$n);
$itest=Tk($x2k,$xk,$p,$k);
echo "
Pour x=".$xk." et c=".$p.", après ".$k." itérations, on obtient x2k=".$x2k;
?>