hi,
ich habe mal vor einiger zeit das hier geschrieben.
Code:
%Fitting arbitrary function through
%measured data points using gnuplot
%by me
%NOTE:
%This code makes use of the pgfplots package
%which is based on tikz
%
%This code makes use of the external software
%gnuplot which is not part of your LaTeX distribution
%
%You can find gnuplot here: http://www.gnuplot.info/
%
%On Linux systems:
%You have to pass the option -shell-escape
%to pdflatex. Most editors support adding
%custom options.
%
%On Windows:
%You have to pass the option -enable-write18
%to pdflatex (MikTeX), for TeXlive the command might be different
%check the manual if you have problems.
%In TeXnicCenter the options for pdflatex should look like
%-interaction=nonstopmode -enable-write18 "%pm"
%
%Further you have to rename the wgnuplot.exe in the
% ../gnuplot/bin folder to
%gnuplot.exe, otherwise pgfplots won't find it
%
%Also add the path ../gnuplot/bin to the environment
%variables so that gnuplot can be found everywhere on your computer
%
%
%Mac (MacTeX) users have to check the distribution's manual
%
%
%
%Create some data we can fit in (x,y) notation
\begin{filecontents}{test.dat}
0.2 -0.8
1 -0.2
1.6 0.2
2.5 2.5
3 5
\end{filecontents}
\documentclass{article}
\usepackage{pgfplots} %Version 1.3 or higher
\begin{document}
\begin{tikzpicture}[scale=0.8]
\begin{axis}[
name=plot,
width=1\linewidth,
xlabel={X},
ylabel={Y},
xtick={-1,0,...,3},
ytick={-1,0,...,5},
enlargelimits=false,
title=Fitting of datapoints with gnuplot,
legend pos={north west,},
ticks=both,
grid=major,
]
%First, just plot the points with marks
\addplot[only marks,mark=square*,blue] file {test.dat};
\addlegendentry{The ``measured'' points}
%
%Now call gnuplot to fit this data
%The key is the raw gnuplot option
%which allows to write a gnuplot script file
\addplot+[raw gnuplot,mark=none, line width=1.5pt] gnuplot {
%The gnuplot script
%
%fit linear function with variables a,b and c
f(x)=a*x**3+b*x+c;
%let gnuplot fit, using column 1 and 2
%of the data file
%Let a,b and c be variables
fit f(x) 'test.dat' using 1:2 via a,b,c;
%Plot the function, specify plot range
%The range should be approx. the same as your
%test.dat x range
plot [x=0:3] f(x);
};
\addlegendentry{The fitted curve}
\end{axis}
\end{tikzpicture}
\end{document}
wenn du die kommentare am anfang nicht verstehst, dann nochmal in kurzform:
verwendest du linux bist du fein raus, alles geht relativ einfach man muss nur -shell-escape an pdflatex uebergeben
in windows ist ein wenig arbeit zu tun:
1) im editor deiner wahl musst du die option --enable-write18 an pdflatex weitergeben
2) du musst sicherstellen das die ausfuehrende datei von gnuplot gnuplot.exe heisst. in aelteren versionen hiess sie wgnuplot.exe, inzwischen ist das glaube ich geaendert worden und man muss nichts mehr umbenennen.
3) du musst gnuplot in die PATH variable eintragen. das ist noetig damit es von latex aus gefunden werden kann. dazu oeffnet man die eingebeaufforderung ueber das windows-startmenu. dort gibt man einfach mal gnuplot.exe ein.
vermutlich kommt jetzt "befehl nicht gefunden", gnuplot ist also vom system nicht auffindbar.
Also auf gehts in Systemsteuerung; Systemeigenschaften, Erweitert, Umgebungsvariablen… (zumindest in XP war das so)
dort in die mit ; getrennte liste den pfad zu pnuplot eintragen. z.b. C:\Programme\gnuplot
jetzt nochmal in der eingabeaufforderung den test machen ob gnuplot gefunden wird und es sollte gehen.
mein beispiel oben fittet eine funktion zu einer handvoll datenpunkte. das wird alles in gnuplot gemacht. du siehst selbst, denke ich, wo das gnuplot script anfaengt.
viel erfolg
Lesezeichen