# File: examples/TestPoly.php

 Recommend this page to a friend! ReTweet
 Classes of Jose Gomez > Linear Fit > examples/TestPoly.php > Download
File: examples/TestPoly.php Example script text/plain Polynomial fitting example Linear Fit Perform linear regression on a set of data values By Jose Gomez 3 years ago 1,995 bytes

## Contents

 ``` 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 y=" . \$aRes . "\n";     }     else     {         echo "Equation \$iEq: y=a0";         for (\$i=1; \$i\$i*x\$i";         }         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));     \$oFit->SetDegree(1);     \$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*x\$i";         }         echo "
";         for (\$i=0; \$i\$i=" . \$aCoeffs[\$i][\$iEq] . "±" . \$aConf[\$i][\$iEq] . "
";         }         echo "r2=" . \$oFit->R2()[\$iEq] . "
";         echo "x=5 -> y=" . \$aRes[\$iEq] . "
";         }     } ?> ```