<? require('../PolyFit.php');
$oFit=new PolyFit; $oFit->SetData(array(0,1,2,3), array(0,1,2,3)); $oFit->AddData(4, 4); $oFit->SetDegree(2); $aCoeffs=$oFit->Fit(); $aConf=$oFit->ConfInterval(0.95); $aRes=$oFit->GetValues(5); if (php_sapi_name()=='cli') { echo "Equation: y=a0"; for ($i=1; $i<count($aCoeffs); $i++) { echo "+a$i*x^$i"; } echo "\n"; for ($i=0; $i<count($aCoeffs); $i++) { echo "a$i=" . $aCoeffs[$i] . "±" . $aConf[$i]. "\n"; } echo "r2=" . $oFit->R2() . "\n"; echo "x=5 -> y=" . $aRes . "\n"; } else { echo "Equation $iEq: y=a<sub>0</sub>"; for ($i=1; $i<count($aCoeffs); $i++) { echo "+a<sub>$i</sub>*x<sup>$i</sup>"; } echo "<br>"; for ($i=0; $i<count($aCoeffs); $i++) { echo "a<sub>$i</sub>=" . $aCoeffs[$i] . "±" . $aConf[$i] . "</br>"; } echo "r<sup>2</sup>=" . $oFit->R2() . "</br>"; echo "x=5 -> y=" . $aRes . "</br>"; }
$oFit->SetData(array(0,1,2,3), array(array(0,1),array(1,2),array(2,3),array(3,4))); $oFit->AddData(4, array(4,5)); $oFit->SetDegree(1); $aCoeffs=$oFit->Fit(); $aConf=$oFit->ConfInterval(0.95); $aRes=$oFit->GetValues(5); if (php_sapi_name()=='cli') { for ($iEq=0; $iEq<count($aCoeffs[0]);$iEq++) { echo "Equation $iEq: y=a0"; for ($i=1; $i<count($aCoeffs); $i++) { echo "+a$i*x^$i"; } echo "\n"; for ($i=0; $i<count($aCoeffs); $i++) { echo "a$i=" . $aCoeffs[$i][$iEq] . "±" . $aConf[$i][$iEq]. "\n"; } echo "r2=" . $oFit->R2()[$iEq] . "\n"; echo "x=5 -> y=" . $aRes[$iEq] . "\n"; } } else { for ($iEq=0; $iEq<count($aCoeffs[0]);$iEq++) { echo "Equation $iEq: y=a<sub>0</sub>"; for ($i=1; $i<count($aCoeffs); $i++) { echo "+a<sub>$i</sub>*x<sup>$i</sup>"; } echo "<br>"; for ($i=0; $i<count($aCoeffs); $i++) { echo "a<sub>$i</sub>=" . $aCoeffs[$i][$iEq] . "±" . $aConf[$i][$iEq] . "</br>"; } echo "r<sup>2</sup>=" . $oFit->R2()[$iEq] . "</br>"; echo "x=5 -> y=" . $aRes[$iEq] . "</br>"; } }
?>
|