# File: examples/TestFunc.php

 Recommend this page to a friend! ReTweet
 Classes of Jose Gomez > Linear Fit > examples/TestFunc.php > Download
File: examples/TestFunc.php Example script text/plain Functional lineal fitting example Linear Fit Perform linear regression on a set of data values By Jose Gomez 4 years ago 2,269 bytes

## Contents

 ``` SetData(array(0,1,2,3), array(0,1,2,3));     \$oFit->AddData(4, 4);     \$aF=array('_x', '_x2');     \$oFit->SetFunctions(\$aF);     \$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 y=" . \$aRes . "\n";     }     else     {         echo "Equation: y=a0";         for (\$i=1; \$i\$i*" . \$aF[\$i-1] . "(x)";         }         echo "
";         for (\$i=0; \$i\$i=" . \$aCoeffs[\$i] . "±" . \$aConf[\$i] . "
";         }         echo "r2=" . \$oFit->R2() . "
";         echo "x=5 -> y=" . \$aRes . "
";     }     \$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));     \$aCoeffs=\$oFit->Fit();     \$aConf=\$oFit->ConfInterval(0.95);     \$aRes=\$oFit->GetValues(5);     if (php_sapi_name()=='cli')     {         for (\$iEq=0; \$iEq y=" . \$aRes[\$iEq] . "\n";         }     }     else     {         for (\$iEq=0; \$iEq0";         for (\$i=1; \$i\$i*" . \$aF[\$i-1] . "(x)";         }         echo "
";         for (\$i=0; \$i\$i=" . \$aCoeffs[\$i][\$iEq] . "±" . \$aConf[\$i][\$iEq] . "
";         }         echo "r2=" . \$oFit->R2()[\$iEq] . "
";         echo "x=5 -> y=" . \$aRes[\$iEq] . "
";         }     }     function _x(\$adX)     {         return \$adX;     }     function _x2(\$adX)     {         if (!is_array(\$adX))         {             \$adXr= \$adX*\$adX;         }         else         {             \$adXr=array();             foreach ( \$adX as \$dX )                 \$adXr[]=\$dX*\$dX;         }         return \$adXr;     } ?> ```

 Advertise on this site Site map Newsletter Statistics Site tips Privacy policy Contact