php Library
fitData
Keine Erläuterungen gefunden.
<?php function fitData($data,$order,$xCol,$yCol){ $dim=count($data); for($i=0;$i<$dim;$i++){ $dataString.=sprintf("%3.2e %4.3e \n",$data[$i][$xCol], $data[$i][$yCol]); } #i $abc=array("a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"); $formula="a"; $variables="a"; for($o=1;$o<=$order;$o++){ $formula.="+".$abc[$o]."*x**".$o; $variables.=",".$abc[$o]; } $plotCommand="f(x)=".$formula." \n"; $plotCommand.="fit f(x) '-' u 1:2 via ".$variables." \n"; $plotCommand.=$dataString." \n"; $plotCommand.="end \n"; $plotCommand.="set format y '%2.1e' \n"; #$plotCommand.="set logscale y 10 \n"; $plotCommand.="plot '-',f(x) \n"; $plotCommand.=$dataString." \n"; $plotCommand.="end \n"; $plotCommand.="pause -1"; $fid=fopen("fit.plot","w"); fputs($fid,$plotCommand); fclose($fid); $string="rm -f fit.log"; system($string); $string="gnuplot fit.plot"; system($string); /* read result */ $result=array(); $rid=fopen("fit.log","r"); $flag=false; while(!feof($rid)){ $line=fgets($rid,2048); if ($flag){array_push($result,$line);} if (eregi("Final set of parameters",$line)){$flag=true;} } fclose($rid); for($l=0;$l<count($result)/2;$l++){ $line=$result[$l]; $pos1=strpos($line,"="); $pos2=strpos($line,"+"); $number=trim(substr($line,$pos1+1,($pos2-$pos1-3))); for($b=0;$b<count($abc);$b++){ if ($abc[$b]==$line[0]){ $coefficient[$b]=$number; break; } } #b } #l # print_r($coefficient); return $coefficient; } ?>
Index of Library
Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.