[pstricks] Curve fit using GNUplot backend

Buddy Ledger buddyledger at gmail.com
Wed Mar 28 18:58:07 CEST 2012


Herbert,

It's just a TeX file which gnuplot generates via the code in the gnuplot
environment.  I've cleaned up the code below.


\documentclass[]{article}
%
\usepackage[miktex]{gnuplottex}
\usepackage{pst-all}
\usepackage{pst-func}
\usepackage{pstricks-add}

\makeatletter
\long\gdef\gnuplotgraphicsinclude{{\input{fit.tex}}}
\def\PsEuler{2.71828182846}
\makeatother
%
\begin{document}
\pagestyle{empty}
\pagenumbering{arabic}
\readdata[ignoreLines=1]{\NLdata}{nl.dat}
\begin{figure}
\begin{psgraph}[arrows=->,Dx=1,Dy=0.1,xsubticks=1,ysubticks=1](0,0)(0,-1)(6,1){4.5in}{4.5in}

\begin{gnuplot}
set print 'fit.tex'
f(x)=a*exp(-b*x)*sin(c*x+d)
fit f(x) 'nl.dat' using 1:2 via a,b,c,d
text1=sprintf('\psplot[algebraic]{0}{6}{%.2f*(\PsEuler^(-%.2f*x))*sin(%.2f*x+%.2f)}',a,b,c,d)
print text1
text2=sprintf('\rput[lb](3,0.4){$%.2f*exp(-%.2f*x)*sin(%.2f*x+%.2f)$}',a,b,c,d)
print text2
\end{gnuplot}

\immediate\write18{del fit.tex}
\listplot[plotstyle=dots]{\NLdata}
\rput[cb](3,0.9){Curve Fit using GNUplot as backend}
\end{psgraph}
\end{figure}

\end{document}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/pstricks/attachments/20120328/205fb760/attachment.html>


More information about the PSTricks mailing list