Hamburger Hamburger

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

1globals.php
2readData.php
3XML_readFile.php
4fraktal.php
5fileGrep.php
6XML_extractTag.php
7writeNamedData.php
8readXmlFile.php
9readNamedData.php
10XML_findAllElements.php
11readFromStdIn.php
12plotResult.php
13dtaus.php
14pdf.php
15fitData.php
16XML_extractElement.php
17readFilenames.php
18writeData.php
19genDTAUS.php
20closeFigures.php
21XML_extractAttribute.php
22enumerateFiles.php
23db.php
24polynominalFit.php
25LaTeXbrief.php
26hex2dec.php

Der gesamte Sourcecode darf gemäß GNU General Public License weiterverbreitet werden.