Пример #1
0
function newt_raph($C0)
{
$conv_criterion=1;
$tolerance=pow(10,-8);
$i=1;

while(($i<1000)&&($conv_criterion>$tolerance))
  {
 # echo "The number is " . $i . "<br />";
   $Fx= flooding($C0);
   $JFx= jac($C0);
    $Cnew=$C0-$Fx/$JFx;
    $conv_criterion=abs($Cnew-$C0)/$C0;
    $C0=$Cnew;
  $i++;
  }
return $C0;
}
Пример #2
0
function jac($C0)
{
    $eps = $C0 / 1000;
    if ($eps == 0) {
        $eps = 1 / 1000;
    }
    $Cp = $C0;
    $Cp = $Cp + $eps;
    $Fp = flooding($Cp);
    $Cn = $C0;
    $Cn = $Cn - $eps;
    $Fn = flooding($Cn);
    $J = ($Fp - $Fn) / (2 * $eps);
    return $J;
}