[pstricks] General Linear Least Square Regression

Buddy Ledger buddyledger at gmail.com
Fri Feb 3 19:32:35 CET 2012


I've spent a bit of time fixing a few things:
- improved the matrix debugger and printer
- generalized the ExpFit for arbitrary base instead of only Euler original
fit model a*exp(x) changed to a*b^x.  a*exp(x) can still be fitted using
gaussian curve Gauss of PolyOrder=1.

I hope someone finds it useful.  A note on licensing - I placed a
disclaimer on my last post in haste.  Contrary to my last post I do not
restrict the use of this code in anyway, except for the fact that I except
no liability for it's use or mis-suse, accuracy or inaccuracy or any damage
resulting from it's use/mis-use.  This is strictly use at your own risk.


\documentclass{article}

\usepackage{pst-all}
\usepackage{pst-func}
\usepackage{pstricks-add}
\usepackage{filecontents}
%Exp(3*e^2x)
\begin{filecontents}{exp.dat}
1 22
2 164
3 1210
4 8943
\end{filecontents}
%Recip(100/x)
\begin{filecontents}{recip.dat}
1 100
2 50
3 33
4 25
5 20
6 12.5
\end{filecontents}
%Poly(-7.26*x^4+57.4*x^3-142.94*x^2+294.53*x-109)
\begin{filecontents}{poly.dat}
1 93
2 251
3 450
4 597
5 428
6 -498
\end{filecontents}
%Log(5+20*log(x))
\begin{filecontents}{logt.dat}
2 11
3 14.5
4 17
5 19
6 20.5
\end{filecontents}
%Log(5+20*ln(x))
\begin{filecontents}{loge.dat}
2 19
3 27
4 33
5 37
6 41
\end{filecontents}
%Power(x^3)
\begin{filecontents}{power.dat}
2 8
3 27
4 64
5 125
6 216
7 343
8 512
9 729
10 1000
\end{filecontents}
%Gauss (e^(-x^2))
\begin{filecontents}{gauss.dat}
-10 3.72008E-44
-8 1.60381E-28
-6 2.31952E-16
-4 1.12535E-07
-2 0.018315639
2 0.018315639
4 1.12535E-07
6 2.31952E-16
8 1.60381E-28
10 3.72008E-44
\end{filecontents}
%Linear (2x+2)
\begin{filecontents}{linear.dat}
1 4
2 6
3 8
4 10
5 12
6 14
7 16
8 18
9 20
10 22
\end{filecontents}
%Linear (2x 3x)
\begin{filecontents}{linearA.dat}
1 2 3
2 4 6
3 6 9
4 8 12
5 10 15
6 12 18
7 14 21
8 16 24
9 18 27
10 20 30
\end{filecontents}
%King (sqrt(5+4*V^0.5))
\begin{filecontents}{king.dat}
2 3.264483765
3 3.453723097
4 3.605551275
5 3.734202982
6 3.846811533
7 3.947531538
8 4.039023211
9 4.123105626
10 4.20108446
\end{filecontents}

\makeatletter
%New PlotStyle ErrorLine
%%%%%%%%%%%
\def\beginplot at ErrorLine{\begin at OpenObj}
\def\endplot at ErrorLine{\psErrorLine at ii}
\def\psErrorLine at ii{%
  \addto at pscode{
    \pst at cp     % current point
    \psline at iii % arc and lineto type
    \tx at ErrorLine
  }%
  \end at OpenObj%
}
%
\def\tx at ErrorLine{ErrorLine }
\pst at def{ErrorLine}<{
  /copypt { dup 3 2 roll dup 4 1 roll exch } def %copy point
  NArray n 0 eq not
    { n { \psk at relyerr\space 0 eq not
    {copypt copypt dup \psk at relyerr\space mul add ArrowA
    dup \psk at relyerr\space mul sub
    Lineto
    copypt dup \psk at relyerr\space mul sub ArrowB L} if
    \psk at relxerr\space 0 eq not
    {copypt copypt exch dup \psk at relxerr\space mul add exch ArrowA
    exch dup \psk at relxerr\space mul sub exch
    Lineto
    copypt exch dup \psk at relxerr\space mul sub exch ArrowB L pop pop }
    { pop pop } ifelse } repeat
    } if
}>

\define at boolkey[psset]{pstricks-add}[Pst@]{ScyBase}[true]{}%
\define at boolkey[psset]{pstricks-add}[Pst@]{ScxBase}[true]{}%
\psset{ScyBase=true,ScxBase=true}

\def\pstScalePoints(#1,#2)#3#4{%
%  xScale | yScale | xOperator | yOperator
% the operators can be any Postscript code
\pst at def{ScalePoints}<%
    /y ED /x ED
    /yOper { #4\space y mul #2\space mul } def
    /xOper { #3\space x mul #1\space mul } def
    counttomark dup dup cvi eq not { exch pop } if
    /m exch def /n m 2 div cvi def
    n {
      #4\space y mul #2\space mul m 1 roll
      #3\space x mul #1\space mul m 1 roll
      /m m 2 sub
      def } repeat>%
}
\def\psLineToXAxis at ii{%
\addto at pscode{\pst at cp \psline at iii \tx at LineToXAxis}%
\end at OpenObj}

\def\tx at LineToXAxis{LineToXAxis }

\pst at def{LineToXAxis}<{%
NArray
n 0 eq not
  { %n 1 eq { 0 0 /n 2 def } if
    %ArrowA
    %/n n 2 sub def
    %2 copy pop 0 \ifPst at ScyBase yOper \fi moveto Lineto
    n { 2 copy 2 copy pop 0 \ifPst at ScyBase yOper \fi 4 2 roll ArrowA Lineto
        2 copy pop 0 \ifPst at ScyBase yOper \fi ArrowB L pop pop
    } repeat
    %2 copy moveto pop 0 \ifPst at ScyBase yOper \fi
    %L
    %pop pop
} if}>

\def\psLineToYAxis at ii{%
\addto at pscode{\pst at cp \psline at iii \tx at LineToYAxis}%
\end at OpenObj}
\def\tx at LineToYAxis{LineToYAxis }
\pst at def{LineToYAxis}<{
NArray
n 0 eq not
  { %n 1 eq { 0 0 /n 2 def } if
    %ArrowA
    %/n n 2 sub def
    %CP 2 copy moveto exch pop 0 \ifPst at ScxBase xOper \fi exch Lineto
    n { 2 copy 2 copy exch pop 0 \ifPst at ScxBase xOper \fi exch 4 2 roll
ArrowA Lineto
        2 copy exch pop 0 \ifPst at ScxBase xOper \fi exch ArrowB L pop pop
    } repeat
    %2 copy moveto exch pop 0 \ifPst at ScxBase xOper \fi exch
    %L
    %pop pop
} if}>
%
%%%%%%PREPAREPOINTS
\define at key[psset]{pstricks-add}{plotNoTwo}{\def\psk at plotNoTwo{#1}}%
\define at key[psset]{pstricks-add}{plotNoTwoFunc}{\def\psk at plotNoTwoFunc{#1}}
%Must operate on two stack elements and return one
\psset{plotNoTwo=0,plotNoTwoFunc=dup mul exch dup mul add sqrt}

%\def\tx at PreparePoints{PreparePoints }
\pst at def{PreparePoints}<{%
  counttomark /m exch def
  \ifPsk at xyValues\else % we have only y values
    /mm m def
    /M m 1 add def
    m { mm exch M 2 roll /M M 1 add def /mm mm 1 sub def } repeat
    /m m dup add def
  \fi
  \ifPst at ChangeOrder
    /m0 m def
    m \psk at plotNoMax\space 1 add div 1 sub cvi {
      m0 \psk at plotNoMax\space 1 add roll /m0 m0 \psk at plotNoMax\space 1 add
sub def
    } repeat
  \fi
  /n m \psk at plotNoMax\space 1 add div cvi def
  \psk at plotNoMax\space 1 gt {% multiple data files?
    n {
      \psk at plotNoTwo\space 0 gt {
        \psk at plotNoMax\space copy
        \psk at plotNoMax\space \psk at plotNoTwo\space 1 sub neg roll % x yNo y
yNoTwo y [yNo y yNoTwo y]
        \psk at plotNoMax\space 1 sub { pop } repeat % x yNo y yNoTwo y yNoTwo
        \psk at plotNoMax\space 1 add 1 roll } if
      \psk at plotNoMax\space \psk at plotNo\space 1 sub neg roll % x yNo y y y
...
      \psk at plotNoMax\space 1 sub { pop } repeat % x [yNoTwo] yNo
      \psk at plotNoTwo\space 0 gt {
          \psk at plotNoTwoFunc\space } if %x f(yNo,yNoTwo)
      /m m \psk at plotNoMax\space 1 sub sub def
      m 2 roll
    } repeat
  } if % no multiple data files
%    counttomark /m exch def
%    /n m 2 div cvi def
  /xMax -99999 def /yMax -99999 def
  /xP 0 def /yP 0 def
  m copy
  n {
    /y exch def /x exch def
    xMax x lt { /xMax x def } if
    yMax y lt {/yMax y def } if
    xP x gt { /xP x def } if
    yP y gt { /yP y def } if
  } repeat
%    m 2 roll
  \psk at xStep\space 0 gt \psk at yStep\space 0 gt or (\psk at xStart) length 0 gt
or
  (\psk at yStart) length 0 gt or (\psk at xEnd) length 0 gt or (\psk at yEnd)
length 0 gt or {
%
    (\psk at xStart) length 0 gt {\psk at xStart\space }{ xP } ifelse /xStart
exch def
    (\psk at yStart) length 0 gt {\psk at yStart\space }{ yP } ifelse /yStart
exch def
    (\psk at xEnd) length 0 gt { \psk at xEnd\space }{ xMax } ifelse /xEnd exch
def
    (\psk at yEnd) length 0 gt { \psk at yEnd\space }{ yMax } ifelse /yEnd exch
def
    n {
      m -2 roll
      2 copy /yVal exch def /xVal exch def
      xVal xP ge
      yVal yP ge and
      xVal xEnd le and
      yVal yEnd le and
      xVal xStart ge and
      yVal yStart ge and {
        /xP xP \psk at xStep\space add def
        /yP yP \psk at yStep\space add def
      }{%
        pop pop
        /m m 2 sub def
      } ifelse
    } repeat
  }{%
    /ncount 0 def
    (\psk at nEnd) length 0 gt { \psk at nEnd\space }{ m } ifelse
    /nEnd exch def
    n {
      m -2 roll
      \psk at nStep\space 1 gt {
        ncount \psk at nStart\space sub \psk at nStep\space mod 0 eq }{ true }
ifelse
        ncount nEnd le and
        ncount \psk at nStart\space ge and not {
          pop pop
          /m m 2 sub def
        } if
        /ncount ncount 1 add def
      } repeat
  } ifelse
}>
%

\def\beginplot at PrintCoor{\begin at SpecialObj}
\def\endplot at PrintCoor{%
  \psPrintCoor at ii %\psk at fillstyle\ifpsshadow\pst at closedshadow\fi%
  %\pst at stroke
  \end at SpecialObj%
}
\define at key[psset]{pstricks-add}{relxerr}{\def\psk at relxerr{#1}}
\define at key[psset]{pstricks-add}{relyerr}{\def\psk at relyerr{#1}}
\define at key[psset]{pstricks-add}{yShift}{\def\psk at yShift{#1}}
\define at boolkey[psset]{pstricks-add}[Pst@]{science}[true]{}%
\psset[pstricks-add]{science=false,relxerr=0.1,relyerr=0.1,yShift=0}
%Following is new pst-func.tex key which conflicts with mine.
%Must specify [pstricks-add] in psset to correct.
%\define at boolkey[psset]{pst-add}[Pst@]{science}[true]{%
%  \ifPst at science\def\psk at Scin{true }\else\def\psk at Scin{false }\fi}

\def\psPrintCoor at ii{%
   \addto at pscode{%
      false
      \tx at NArray
      \pst at number\psxunit
      \pst at number\psyunit
      \psPrintCoor at iii
}}

\def\psPrintCoor at iii{%
     /mfont { \psk at PSfont\space findfont \psk at fontscale\space scalefont
setfont } bind def
     /mfontexp { \psk at PSfont findfont \psk at fontscale 1.2 div scalefont
setfont } bind def
     /s1 { /Symbol findfont \psk at fontscale\space scalefont setfont } bind
def
     /ttxspc \psk at fontscale\space 4 div def
     /txspc ttxspc 4 div def
     %pop
     /ysc ED
     /xsc ED
     n 0 eq not {%
     n {%
     ysc div /Yval ED
     xsc div /Xval ED
   \ifPst at science
     %X Coordinate
     Xval 0 gt { Xval log floor }{ Xval 0 lt { Xval -1 mul log floor }{ 0 }
ifelse } ifelse
     cvi /xcoorexp ED
     Xval 10 xcoorexp exp div
     \psk at decimals\space -1 gt {%
     10 \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq { cvi } if /xcoor ED
     %Y Coordinate
     Yval 0 gt { Yval log floor }{ Yval 0 lt { Yval -1 mul log floor }{ 0 }
ifelse } ifelse
     cvi /ycoorexp ED
     Yval 10 ycoorexp exp div
     \psk at decimals\space -1 gt {%
     10 \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq { cvi } if /ycoor exch def
     %Prep Strings
     xcoorexp \psk at valuewidth\space string cvs /xcoorexp ED
     ycoorexp \psk at valuewidth\space string cvs /ycoorexp ED
     xcoor \psk at valuewidth\space string cvs /xcoor ED
     ycoor \psk at valuewidth\space string cvs /ycoor ED
     %X Error
     \psk at relxerr\space Xval mul /delx ED \psk at relxerr\space 0 ne {%
     delx 0 gt { delx log floor }{ delx 0 lt { delx -1 mul log floor }{ 0 }
ifelse } ifelse
     cvi /delxexp ED
     delx 10 delxexp exp div dup mul sqrt
     \psk at decimals\space -1 gt {%
     10 \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq { cvi } if /delx ED
     %Prep Strings
     delxexp \psk at valuewidth\space string cvs /delxexp ED
     delx \psk at valuewidth\space string cvs /delx ED } if
     %Y Error
     \psk at relyerr\space Yval mul /dely ED \psk at relyerr\space 0 ne {%
     dely 0 gt { dely log floor }{ dely 0 lt { dely -1 mul log floor }{ 0 }
ifelse } ifelse
     cvi /delyexp ED
     dely 10 delyexp exp div dup mul sqrt
     \psk at decimals\space -1 gt {%
     10 \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq { cvi } if /dely ED
     %Prep Strings
     delyexp \psk at valuewidth\space string cvs /delyexp ED
     dely \psk at valuewidth\space string cvs /dely ED } if
   \else
     Xval \psk at decimals\space -1 gt
     { 10 \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq {cvi} if /xcoor ED
     Yval \psk at decimals\space -1 gt
     { 10 \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq {cvi} if /ycoor ED
     xcoor \psk at valuewidth\space string cvs /xcoor ED
     ycoor \psk at valuewidth\space string cvs /ycoor ED
     %
     \psk at relxerr\space Xval mul dup mul sqrt
     \psk at decimals\space -1 gt
     { 10   \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq {cvi} if /delx ED
     \psk at relyerr\space Yval mul dup mul sqrt
     \psk at decimals\space -1 gt
     { 10   \psk at decimals\space exp dup 3 1 roll mul round exch div } if
     \psk at decimals\space 0 eq {cvi} if /dely ED
     delx \psk at valuewidth\space string cvs /delx ED
     dely \psk at valuewidth\space string cvs /dely ED
   \fi
%
     newpath
     Xval xsc mul %\psk at xShift\space xsc mul add
     Yval ysc mul %\psk at yShift\space ysc mul add
     moveto
     \Pst at Debug\space 0 gt {
     mfont
     Xval \psk at valuewidth\space string cvs show (,) show
     Yval \psk at valuewidth\space string cvs show }
     {s1 (\string\050) show
     mfont xcoor show
       \ifPst at science
       mfont (x) show
       mfont (10) show
       0 ttxspc rmoveto mfontexp xcoorexp show
       \fi
     \psk at relxerr\space 0 ne
     { \ifPst at science
       0 ttxspc neg rmoveto s1 (\string\261) show
       mfont delx show
       mfont (x) show
       mfont (10) show
       0 ttxspc rmoveto mfontexp delxexp show
       0 ttxspc neg rmoveto s1 (,) show
       \else
       s1 (\string\261) show
       mfont delx show
       s1 (,) show
       \fi }
     { \ifPst at science
       0 ttxspc neg rmoveto s1 (,) show
       \else
       s1 (,) show
       \fi } ifelse
%start on ycoor
     mfont ycoor show
       \ifPst at science
       mfont (x) show
       mfont (10) show
       0 ttxspc rmoveto mfontexp ycoorexp show
       \fi
     \psk at relyerr\space 0 ne
     { \ifPst at science
       0 ttxspc neg rmoveto s1 (\string\261) show
       mfont dely show
       mfont (x) show
       mfont (10) show
       0 ttxspc rmoveto mfontexp delyexp show
       0 ttxspc neg rmoveto s1 (\string\051) show
       \else
       s1 (\string\261) show
       mfont dely show
       s1 (\string\051) show
       \fi }
       { s1 (\string\051) show } ifelse } ifelse
 } repeat } if }

%%%POLY FIT
\define at key[psset]{pstricks-add}{EqPos}[{}]{\def\psk at EqPos{#1}}
\define at key[psset]{pstricks-add}{MaPos}[{}]{\def\psk at MaPos{#1}}%added Feb3,
2012 Matrix out
\define at key[psset]{pstricks-add}{MaScale}[{}]{\def\psk at MaScale{#1}}%added
Feb3, 2012 Matrix out
\define at boolkey[psset]{pstricks-add}[Pst@]{ShowEq}[true]{}%
\psset{EqPos=,ShowEq=true,MaPos=0 0,MaScale=1}

\define at key[psset]{pstricks-add}{PolyOrder}[{}]{\def\psk at PolyOrder{#1}}
\define at boolkey[psset]{pstricks-add}[Pst@]{ReduceOrder}[true]{%these
percents are critical removal results in shift to in x-dir
\ifPst at ReduceOrder%
\def\psk at ReduceOrder{true}\else\def\psk at ReduceOrder{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{PowerFit}[true]{%these percents
are critical removal results in shift to in x-dir
\ifPst at PowerFit%
\def\psk at PowerFit{true}\def\psk at LogEFit{false}%
\def\psk at LogTFit{false}\def\psk at ExpFit{false}%
\def\psk at GaussFit{false}\def\psk at CustomFit{false}\def\psk at RecipFit{false}%
\else\def\psk at PowerFit{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{LogEFit}[true]{%
\ifPst at LogEFit%
\def\psk at PowerFit{false}\def\psk at LogEFit{true}%
\def\psk at LogTFit{false}\def\psk at ExpFit{false}%
\def\psk at GaussFit{false}\def\psk at CustomFit{false}\def\psk at RecipFit{false}%
\else\def\psk at LogEFit{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{LogTFit}[true]{%
\ifPst at LogTFit%
\def\psk at PowerFit{false}\def\psk at LogEFit{false}%
\def\psk at LogTFit{true}\def\psk at ExpFit{false}%
\def\psk at GaussFit{false}\def\psk at CustomFit{false}\def\psk at RecipFit{false}%
\else\def\psk at LogTFit{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{ExpFit}[true]{%
\ifPst at ExpFit%
\def\psk at PowerFit{false}\def\psk at LogEFit{false}%
\def\psk at LogTFit{false}\def\psk at ExpFit{true}%
\def\psk at GaussFit{false}\def\psk at CustomFit{false}\def\psk at RecipFit{false}%
\else\def\psk at ExpFit{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{GaussFit}[true]{%
\ifPst at GaussFit%
\def\psk at PowerFit{false}\def\psk at LogEFit{false}%
\def\psk at LogTFit{false}\def\psk at ExpFit{false}%
\def\psk at GaussFit{true}\def\psk at CustomFit{false}\def\psk at RecipFit{false}%
\else\def\psk at GaussFit{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{RecipFit}[true]{%
\ifPst at RecipFit%
\def\psk at PowerFit{false}\def\psk at LogEFit{false}%
\def\psk at LogTFit{false}\def\psk at ExpFit{false}%
\def\psk at GaussFit{false}\def\psk at CustomFit{false}\def\psk at RecipFit{true}%
\else\def\psk at RecipFit{false}\fi}%
\define at boolkey[psset]{pstricks-add}[Pst@]{CustomFit}[true]{%
\ifPst at CustomFit%
\def\psk at PowerFit{false}\def\psk at LogEFit{false}%
\def\psk at LogTFit{false}\def\psk at ExpFit{false}%
\def\psk at GaussFit{false}\def\psk at CustomFit{true}\def\psk at RecipFit{false}%
\else\def\psk at CustomFit{false}\fi}%
\define at key[psset]{pstricks-add}{FXtrans}[{}]{\def\psk at FXtrans{#1}}
\define at key[psset]{pstricks-add}{FYtrans}[{}]{\def\psk at FYtrans{#1}}
\define at key[psset]{pstricks-add}{RYtrans}[{}]{\def\psk at RYtrans{#1}}
\define at key[psset]{pstricks-add}{Yint}[{}]{\def\psk at Yint{#1}}
\define at key[psset]{pstricks-add}{CheckZeroX}[{}]{\def\psk at CheckZeroX{#1}}
\define at key[psset]{pstricks-add}{CheckZeroY}[{}]{\def\psk at CheckZeroY{#1}}
\psset{PolyOrder=1,ReduceOrder=false,PowerFit=false,LogEFit=false,LogTFit=false,%
      ExpFit=false,GaussFit=false,RecipFit=false,CustomFit=false,%
        FXtrans=,FYtrans=,RYtrans=,Yint=,CheckZeroX=,CheckZeroY=}

\def\beginplot at GLLSR{\begin at SpecialObj}
\def\endplot at GLLSR{%
  \psGLLSR at ii\psk at fillstyle\ifpsshadow\pst at closedshadow\fi%
  \pst at stroke
  \end at SpecialObj%
}
\def\psGLLSR at ii{\addto at pscode{false \tx at NArray \psGLLSR at iii }}
\def\psGLLSR at iii{%
  %General Fit Model: y = a0 + a1*x + a2*x^2 + ... + an*x^n
  %Define Fonts
  /mfont { \psk at PSfont\space findfont \psk at fontscale\space scalefont
setfont } bind def
  /mfontbig { \psk at PSfont\space findfont \psk at fontscale\space 2 mul
scalefont setfont } bind def
  /mfontexp { \psk at PSfont\space findfont \psk at fontscale\space 2 div
scalefont setfont } bind def
   mfont
  %Default parameters
  (\psk at PolyOrder) length 0 gt { \psk at PolyOrder\space /order ED }{ /order 1
def } ifelse
  /PolyEq true def
  (\psk at Yint) length 0 gt
    {\psk at Yint\space /Yint ED /setYint true def /ReduceOrder true def }
    { /Yint 0 def /setYint false def /ReduceOrder false def} ifelse
  /CheckZeroX false def
  /CheckZeroY false def
  /FXtrans {1 mul} def
  /FYtrans { Yint sub } def
  /RYtrans {1 mul} def
  /xPr {(x) show} def
  %Special Fit Functions (Linear Transforms)
  \psk at PowerFit\space { /order 1 def /CheckZeroX true def /CheckZeroY true
def /PolyEq false def
       /FXtrans {log} def /FYtrans {Yint sub log} def /RYtrans {10 exch exp
Yint add} def /ReduceOrder false def } if
  \psk at LogTFit\space { /order 1 def /CheckZeroX true def /PolyEq true def
       /xPr { (log) show (\string\050) show (x) show (\string\051) show }
def
       /FXtrans {log} def /FYtrans {1 mul} def /RYtrans {1 mul} def } if %
  \psk at LogEFit\space { /order 1 def /CheckZeroX true def /PolyEq true def
        /xPr { (ln) show (\string\050) show (x) show (\string\051) show }
def
       /FXtrans {ln} def /FYtrans {1 mul} def /RYtrans {1 mul} def } if %
  \psk at ExpFit\space { /order 1 def /CheckZeroY true def /PolyEq false def
       /FXtrans {1 mul} def /FYtrans {Yint sub ln} def /RYtrans {Euler exch
exp Yint add} def  /ReduceOrder false def } if %
  \psk at GaussFit\space { /order 2 def /CheckZeroY true def /PolyEq false def
       /FXtrans {1 mul} def /FYtrans {Yint sub ln} def /RYtrans {Euler exch
exp Yint add} def  /ReduceOrder false def } if %
  \psk at RecipFit\space { /order 1 def /CheckZeroX true def /PolyEq true def
        /xPr { (\string\050) show (1) show (\string\244) show (x) show
(\string\051) show } def
       /FXtrans { 1 exch div } def /FYtrans {1 mul} def /RYtrans {1 mul}
def } if
  \psk at CustomFit\space { /PolyFit false def
       (\psk at FXtrans) length 0 gt { {\psk at FXtrans\space} /FXtrans ED } if
       (\psk at FYtrans) length 0 gt { {\psk at FYtrans\space} /FYtrans ED } if
       (\psk at RYtrans) length 0 gt { {\psk at RYtrans\space} /RYtrans ED } if
       (\psk at CheckZeroX) length 0 gt { {\psk at CheckZeroX\space} /CheckZeroX
ED } if
       (\psk at CheckZeroY) length 0 gt { {\psk at CheckZeroY\space} /CheckZeroY
ED } if
       (\psk at ReduceOrder) length 0 gt { {\psk at ReduceOrder\space}
/ReduceOrder ED } if } if %
  %Initialize Arrays
  /A order 1 add order 1 add mul array def
  /B order 1 add array def
  /ai order 1 add array def
  %Coordinate Conversion Operators X Y PLU -> Plot Units (pts), X Y RLU ->
Real Units (arbitrary)
  /PLU {exch \pst at number\psxunit\space mul exch \pst at number\psyunit\space
mul } def
  /RLU {exch \pst at number\psxunit\space div exch \pst at number\psyunit\space
div } def
  /PRA { %Inputs: Array [ #rows #cols X Y Scale boolean(print equal sign)
boolean(return) ]
         %"pra" prefix has been added to all variables to minimize chance
of naming conflicts
%         /praSc exch def /praYc exch def /praXc exch def
%         /praCol exch def /praRow exch def /praARY exch def
         /praTemp exch def /praARY exch def
         praTemp length 7 eq {%
         %praTemp 4 get /praSc exch def
         %praTemp 3 get /praYc exch def
         %praTemp 2 get /praXc exch def
         %praTemp 1 get /praCol exch def
         %praTemp 0 get /praRow exch def pop
         /tempfontscale \psk at fontscale praTemp 4 get mul def
         %/praXc praTemp 2 get \pst at number\psxunit\space mul def
         /praYc praTemp 3 get \pst at number\psyunit\space mul def
         /praXmax -999999 def
         /praYmin 999999 def
         /prafont {\psk at PSfont\space findfont tempfontscale scalefont
setfont} bind def
         /prasym { /Symbol findfont tempfontscale 2 mul scalefont setfont}
bind def
         prafont
         praTemp 2 get \pst at number\psxunit\space mul praTemp 3 get
\pst at number\psyunit\space mul moveto
         praARY length praTemp 1 get praTemp 0 get mul eq not { (Row x Col
> Vector Dim) show }{%
         /praXstart praTemp 2 get \pst at number\psxunit\space mul def
         0 1 praTemp 1 get 1 sub {/praj ED
         0 1 praTemp 0 get 1 sub {/prai ED /prak praj praTemp 1 get prai
mul add def
         praARY prak get \psk at valuewidth string cvs show
         currentpoint pop dup praXmax gt { /praXmax ED }{ pop } ifelse
         currentpoint pop praXstart sub neg tempfontscale 1.5 mul neg
rmoveto
         } for
         currentpoint exch pop dup praYmin lt { /praYmin ED }{ pop } ifelse
         /praXstart praXmax tempfontscale 0.75 mul add def
         praXstart praTemp 3 get \pst at number\psyunit\space mul moveto
         } for
         %Brackets
          newpath
          praTemp 2 get \pst at number\psxunit\space mul tempfontscale 0.125
mul add
          praTemp 3 get \pst at number\psyunit\space mul tempfontscale add
moveto
          praTemp 2 get \pst at number\psxunit\space mul tempfontscale 0.125
mul sub
          praTemp 3 get \pst at number\psyunit\space mul tempfontscale add
lineto
          praTemp 2 get \pst at number\psxunit\space mul tempfontscale 0.125
mul sub
          praYmin tempfontscale add lineto
          praTemp 2 get \pst at number\psxunit\space mul tempfontscale 0.125
mul add
          praYmin tempfontscale add lineto
          stroke
          newpath
          praXmax tempfontscale 0.125 mul sub
          praTemp 3 get \pst at number\psyunit\space mul tempfontscale add
moveto
          praXmax tempfontscale 0.125 mul add
          praTemp 3 get \pst at number\psyunit\space mul tempfontscale add
lineto
          praXmax tempfontscale 0.125 mul add
          praYmin tempfontscale add lineto
          praXmax tempfontscale 0.125 mul sub
          praYmin tempfontscale add lineto
          stroke
          praTemp 5 get {
          praXmax tempfontscale add
          praTemp 3 get \pst at number\psyunit\space mul tempfontscale add
praYmin add 2 div moveto
          prasym (=) show currentpoint pop /praXmax ED} if
         %Left Bracket
         praTemp 2 get \pst at number\psxunit\space mul praYmin tempfontscale
2 mul sub moveto %Return to bottom left
         %the following are defined for use with cascade calls to PRA
         % (Xl,Yb) - Print next matrix below last
         % (Xr,Yt) - Print next matrix beside last
         % (Xr,Yb) - Print next matrix beside and below last
         tx at Dict /praYb known {
         praYmin tempfontscale 1.5 mul sub \pst at number\psyunit\space div
praYb lt {
         /praYb praYmin tempfontscale 1.5 mul sub \pst at number\psyunit\space
div def } if }
         { /praYb praYmin tempfontscale 1.5 mul sub \pst at number\psyunit\space
div def } ifelse
         /praYb praYmin tempfontscale 1.5 mul sub \pst at number\psyunit\space
div def
         %
         tx at Dict /praXl known not {/praXl praTemp 2 get def } if
        % { praTemp 6 get {/praXl praTemp 2 get def} if } ifelse
         tx at Dict /praYt known not {/praYt praTemp 3 get def }
         { praTemp 6 get {/praYt praYb def} if } ifelse
         %
         tx at Dict /praXr known {
         praTemp 6 get { /praXr praXl def }{ /praXr praXmax tempfontscale
add \pst at number\psxunit\space div def } ifelse }{%
         /praXr praXmax tempfontscale add \pst at number\psxunit\space div def
} ifelse
         \psk at PSfont\space findfont \psk at fontscale\space scalefont setfont
} ifelse
         }{ \psk at PSfont\space findfont \psk at fontscale\space scalefont
setfont
         0 0 moveto (PRA Error Not Enough Parameters) show } ifelse } def
  0 1 A length 1 sub { A exch 0 put } for
  0 1 B length 1 sub { B exch 0 put } for
  0 1 ai length 1 sub { ai exch 0 put } for
  %%%%%%%%
  %Remove Zero Data (As Required By Transformation Functions)
  CheckZeroX CheckZeroY or {
  n { /tmpx false def /tmpy false def
    CheckZeroY { dup \pst at number\psyunit\space div Yint sub 0 le { /tmpy
true def  } if } if
    CheckZeroX { exch dup \pst at number\psxunit\space div 0 le { /tmpx true
def } if exch } if
    tmpx tmpy or { pop pop /n n 1 sub def }{ n 2 mul 2 roll } ifelse
    } repeat } if
  %%%
  %%%%
  %Determine Max/Min X for Plotting
  exch dup dup
  \pst at number\psxunit\space div /xEnd ED
  \pst at number\psxunit\space div /xStart ED
  exch
  /ybar 0 def
  n {                         % number of data pairs
    dup \pst at number\psyunit\space div ybar add /ybar ED
    2 copy      %copy point
    \pst at number\psyunit\space div /Yval ED
    \pst at number\psxunit\space div /Xval ED
    Xval xStart lt { /xStart Xval def } if    % find the lowest xi
    Xval xEnd gt { /xEnd Xval def } if        % find the largest xi
    n 2 mul 2 roll    %roll the original point to the bottom of the stack
  } repeat
  ybar n div /ybar ED
  %Scale X & Y variables and apply Linear Transform if applicable
  n {
    \pst at number\psyunit\space div FYtrans
    n 2 mul 1 roll
    \pst at number\psxunit\space div FXtrans
    n 2 mul 1 roll
  } repeat
  %START ASSEMBLY OF LEAST SQUARES MATRIX
  1 1 order 1 add { /ci exch def
    1 1 ci { /cj exch def
      /epk ci cj add 2 sub def
      /sum 0 def
      n { n 2 mul 1 roll
        dup epk exp sum add /sum ED
        n 2 mul 1 roll
      } repeat
      A
      ci 1 sub order 1 add mul cj add 1 sub
      sum put %i row, j col standard
      A
      cj 1 sub order 1 add mul ci add 1 sub
      sum put %j row, i col reversed
    } for
    /sum 0 def
    1 1 n { /cl exch def
      2 copy
      exch
      ci 1 sub exp mul sum add /sum ED
      n 2 mul 2 roll
    } for
    B
    ci 1 sub
    sum put
  } for
  \Pst at Debug\space 1 eq {
  %A [ order 1 add order 1 add 5 20 0.5 false false ] PRA
  A [ order 1 add order 1 add \psk at MaPos\space \psk at MaScale\space true
false ] PRA
  B [ order 1 add 1 praXr praYt \psk at MaScale\space false true ] PRA
  } if
  %END OF ASSEMBLE MATRIX
 %REDUCE ORDER FOR Y INTERCEPT FOR MODELS WHICH ARE APPROPRIATE
  ReduceOrder {
    /elemOld { exch 1 sub order 1 add mul add 1 sub } def
    /elemNew { exch 2 sub order mul add 2 sub  } def
    /dummyA order order mul array def
    0 1 dummyA length 1 sub { dummyA exch 0 put } for
    /dummyB order array def
    0 1 dummyB length 1 sub { dummyB exch 0 put } for
    /ai order array def
    0 1 ai length 1 sub { ai exch 0 put } for
    %Translate A to dummyA
    2 1 order 1 add {/ci ED
      2 1 order 1 add {/cj ED
        dummyA ci cj elemNew
        A ci cj elemOld get
        put
      } for
      dummyB ci 2 sub
      B ci 1 sub get
      put
    } for
  /order order 1 sub def
%temporarily reduce system order
  /A order 1 add order 1 add mul array def 0 1 A length 1 sub {/ci ED A ci
dummyA ci get put } for  %put dummyA in new A
  /B order 1 add array def 0 1 B length 1 sub {/ci ED B ci dummyB ci get
put } for                  %put dummyB in new B
  \Pst at Debug\space 1 eq {
  A [ order 1 add order 1 add praXr praYt \psk at MaScale\space true false ]
PRA
  B [ order 1 add 1 praXr praYt \psk at MaScale\space false true ] PRA } if
  \tx at GaussSolve
  /order order 1 add def
%restore system order
  /m m 1 add def
  % \Pst at Debug\space 1 eq {
  %ai [ order 1 add 1 praXr praYt \psk at MaScale\space false false ] PRA } if
  /dummyai order 1 add array def
  0 1 dummyai length 1 sub {/ci ED dummyai ci 0 put } for
  0 1 ai length 1 sub {/ci ED dummyai ci 1 add ai ci get put } for
  /ai dummyai def
  ai 0 Yint put
  %ai [ order 2 sub 1 0 0 \psk at MaScale\space true false ] PRA
  }{ \tx at GaussSolve } ifelse
  %\Pst at Debug\space 1 eq {
  %ai [ order 1 add 1 praXr praYt \psk at MaScale\space false false ] PRA } if
  %%%%%%%%%%%%%%%%%%%%%%%%%%
  %% END SOLVE CURVE FITS %%
  %%%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%
  %% PLOT CURVE FITS %%
  %%%%%%%%%%%%%%%%%%%%%
  newpath
  (\psk at xStart) length 0 gt             % special start value?
  { \psk at xStart\space /xStart ED } if
  (\psk at xEnd) length 0 gt             % special end value?
  { \psk at xEnd\space /xEnd ED } if
  /xStep xEnd xStart sub \psk at plotpoints\space div def
  /Xnow xStart def
  /Ynow 0 def
  1 1 m { /ci exch def ai ci 1 sub get ci 1 sub { Xnow FXtrans mul } repeat
Ynow add /Ynow exch def } for
  Xnow Ynow RYtrans PLU moveto
  \psk at plotpoints\space cvi
  { /Xnow Xnow xStep add def
  /Ynow 0 def
  1 1 m { /ci exch def ai ci 1 sub get ci 1 sub { Xnow FXtrans mul } repeat
Ynow add /Ynow exch def } for
  Xnow Ynow RYtrans PLU lineto
  } repeat
  %
  /yminusdot 0 def
  /yminusbar 0 def
  n {
    2 copy
    /Ynow ED
    /Xnow ED
    /Ydot 0 def
    1 1 m { /ci exch def
     ai ci 1 sub get ci 1 sub { Xnow mul } repeat Ydot add /Ydot exch def }
for %
    Ynow Ydot sub dup mul yminusdot add /yminusdot ED
    Ynow ybar sub dup mul yminusbar add /yminusbar ED
    n 2 mul 2 roll
  } repeat
  1 yminusdot yminusbar div sub /rsquared ED
  %%%%%%%%%%%%%%%%%%%%%%%%%
  %% END PLOT CURVE FITS %%
  %%%%%%%%%%%%%%%%%%%%%%%%%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%
  %% START PRINT EQUATIONS %%
  %%%%%%%%%%%%%%%%%%%%%%%%%%%
  \ifPst at ShowEq
  % Setup Cursor
  (\psk at EqPos) length 0 gt
  {\psk at EqPos\space PLU }
  {2 -5 PLU } ifelse moveto
 % Power Fit Equation %
  \psk at PowerFit\space {
  10 ai 0 get exp
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpA exch def
  ai 1 get
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpB exch def
  (y = ) show
  tmpA  \psk at valuewidth string cvs show
  (x) show
  0 \psk at fontscale 4 div rmoveto
  mfontexp tmpB \psk at valuewidth string cvs show mfont
  0 \psk at fontscale 4 div neg rmoveto
  setYint Yint 0 ne and { Yint 0 gt { (+) show } if Yint
\psk at valuewidthstring cvs show } if } if
 % Exponential Fit Equation %
  \psk at ExpFit\space {
  Euler ai 0 get exp
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpA exch def
  Euler ai 1 get exp
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpB exch def
  (y = ) show
  (\string\050) show tmpA \psk at valuewidth string cvs show (\string\051) show
  %(e) show
  (\string\264) show
  %0 \psk at fontscale 4 div rmoveto
  %mfontexp tmpB \psk at valuewidth string cvs show
  (\string\050) show tmpB \psk at valuewidth string cvs show (\string\051) show
  0 \psk at fontscale 2 div rmoveto
  mfontexp (x) show mfont
  0 \psk at fontscale 2 div neg rmoveto
  setYint Yint 0 ne and { Yint 0 gt { (+) show } if Yint
\psk at valuewidthstring cvs show } if} if
  % Gaussian Fit Equation %
  \psk at GaussFit\space {
  /tmpA Euler ai 0 get ai 1 get dup mul 4 div ai 2 get div sub exp def
  /tmpB ai 1 get 2 div ai 2 get div def
  /tmpC ai 2 get def
  tmpA
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpA exch def
  tmpB
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpB exch def
  tmpC
  \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if  /tmpC exch def
  (y = ) show
  tmpA 30 string cvs show
  (e) show
  0 \psk at fontscale 4 div rmoveto
  mfontexp tmpC \psk at valuewidth string cvs show
  (\string\(x) show
  tmpB 0 ne { tmpB 0 ge { (+) show } if tmpB \psk at valuewidth string cvs
show } if
  (\string\)) show
  0 \psk at fontscale 4 div rmoveto (2) show mfont
  0 \psk at fontscale 2 div neg rmoveto
  setYint Yint 0 ne and { Yint 0 gt { (+) show } if Yint
\psk at valuewidthstring cvs show } if } if
  %%%%%%%%%%%%%%%
  % Round Coeff %
  %%%%%%%%%%%%%%%
  0 1 ai length 1 sub {/ci exch def
    ai ci get
    \psk at decimals\space -1 gt
    { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
    \psk at decimals\space 0 eq { cvi } if
  ai ci 3 -1 roll put } for
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  % Plot Polynomial (including Linear) Fit %
  %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  PolyEq { (y =) show
  1 1 m { /ci exch def
          ai ci 1 sub get 30 string cvs show
          ci 1 sub 0 gt { xPr } if
          ci 1 sub 1 gt {%
             0 \psk at fontscale 4 div rmoveto ci 1 sub 30 string cvs show
             0 \psk at fontscale 4 div neg rmoveto } if
          ci m eq not { ai ci get 0 lt {}{ (+) show } ifelse } if
  } for } if
  %Print Rsquared
  rsquared
  \psk at decimals\space -1 gt
  { 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
  \psk at decimals\space 0 eq { cvi } if  /rsquared exch def
  \psk at EqPos\space PLU moveto
  0 \psk at fontscale 1.5 mul neg rmoveto
  (R) show
  0 \psk at fontscale 2 div rmoveto
  mfontexp (2) show mfont
  0 \psk at fontscale 2 div neg rmoveto
  ( = ) show
  rsquared \psk at valuewidth string cvs show
  \fi
}
%
\def\tx at GaussSolve{GaussSolve }
\pst at def{GaussSolve}<{%
%Required Variables
%order,A,B,ai
  /er 1 def  %
  /tol 0.00001 def %
  /m order 1 add def %number of equations
  /Aout m m mul array def %This is for printing the scaled identity matrix
which A becomes
  0 1 Aout length 1 sub { Aout exch 0 put } for
  /elem { exch 1 sub m mul add 1 sub } def %Array i j
  %DETERMINE SCALE FACTORS
  /sc m array def %row scale factors
  0 1 sc length 1 sub { sc exch 0 put } for
  1 1 m { /ci exch def
    sc
    ci 1 sub
    A ci 1 elem get
    dup mul sqrt
    put
    2 1 m { /cj exch def
      A ci cj elem get
      dup mul sqrt
      sc ci 1 sub get gt {%
      sc
      ci 1 sub
      A ci cj elem get
      dup mul sqrt
      put } if
    } for
  % 1 ci mul 1 sc ci 1 sub get 30 string cvs show
  } for
  %END OF SCALE FACTORS
  %CALL ELIMINATE
  order 1 ge {%
  1 1 m 1 sub { /ck exch def
    %Call Pivot
    /p ck def
    A ck ck elem get
    sc ck 1 sub get div
    dup mul sqrt
    /big exch def
    ck 1 add 1 m {/cii exch def
      A cii ck elem get
      sc cii 1 sub get div
      dup mul sqrt
      /dummy exch def
      dummy big gt { /big dummy def /p cii def } if
    } for
    p ck eq not {
    ck 1 m {/cjj exch def
      A p cjj elem get
      /dummy exch def
      A p cjj elem
      A ck cjj elem get
      put
      A ck cjj elem
      dummy
      put
    } for
    B p 1 sub get
    /dummy exch def
    B p 1 sub
    B ck 1 sub get
    put
    B ck 1 sub
    dummy
    put
    sc p 1 sub get
    /dummy exch def
    sc p 1 sub
    sc ck 1 sub get
    put
    sc ck 1 sub
    dummy
    put
    } if
    %End Pivot
    %Back to Eliminate
    A ck ck elem get
    sc ck 1 sub get div
    dup mul sqrt tol lt { /er -1 def } if
    ck 1 add 1 m { /ci exch def
      A ci ck elem get
      A ck ck elem get div
      /factor exch def
      %ck 1 add 1 m { /cj exch def
      1 1 m { /cj exch def  %Line Changed from above, requires more calcs
but allows debugging of matrix ops.
        A ci cj elem %index
        A ci cj elem get
        A ck cj elem get
        factor
        mul sub %value
        put
      } for
      B ci 1 sub %index
      B ci 1 sub get
      B ck 1 sub get
      factor
      mul sub %value
      put
    } for
  } for
    \Pst at Debug\space 1 eq {
    A [ order 1 add order 1 add praXr praYt \psk at MaScale\space true false ]
PRA
    B [ order 1 add 1 praXr praYt \psk at MaScale\space false true ] PRA
  } if
  } if
  %Start Back Substitution
  %Add Error check for er -1
  ai m 1 sub
  B m 1 sub get
  A m m elem get
  div put
  %%%%Added for debug
  Aout m m elem
  A m m elem get dup div
  put
  %%%%
  order 1 ge {%
  m 1 sub -1 1 { /ci exch def
    /sum 0 def
    ci 1 add 1 m { /cj exch def
      A ci cj elem get
      ai cj 1 sub get
      mul sum add
      /sum exch def
    } for
    ai ci 1 sub
    B ci 1 sub get
    sum sub
    A ci ci elem get
    div put
    %%%%Added for debug
    Aout ci ci elem
    A ci ci elem get dup div
    put
    %%%%
  } for
  A ck ck elem get
  sc ck 1 sub get div
  dup mul sqrt tol lt { /er -1 def } if
  } if
  \Pst at Debug\space 1 eq {
  Aout [ order 1 add order 1 add praXr praYt \psk at MaScale\space true false
] PRA
  ai [ order 1 add 1 praXr praYt \psk at MaScale\space false false ] PRA } if}>

\makeatother

\begin{document}
\pagestyle{empty}
\pagenumbering{arabic}
%
\readdata[ignoreLines=0]{\Gauss}{gauss.dat}
\readdata[ignoreLines=0]{\Power}{power.dat}
\readdata[ignoreLines=0]{\King}{king.dat}
\readdata[ignoreLines=0]{\Exp}{exp.dat}
\readdata[ignoreLines=0]{\Linear}{linear.dat}
\readdata[ignoreLines=0]{\LinearA}{linearA.dat}
\readdata[ignoreLines=0]{\Recip}{recip.dat}
\readdata[ignoreLines=0]{\Poly}{poly.dat}
\readdata[ignoreLines=0]{\Logt}{logt.dat}
\readdata[ignoreLines=0]{\Loge}{loge.dat}
%
%
\psset{xAxisLabel=x, %Setup for psgraph env
        yAxisLabel=y,
        xAxisLabelPos=,
        yAxisLabelPos=}
\psset{xunit=1,yunit=1}

%Fit of Linear Function
%Replaces LSM using default options
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=2,xsubticks=1,ysubticks=1](0,0)(0,0)(10,30){4.5in}{4.5in}
\listplot[decimals=2,EqPos=3 15,plotstyle=GLLSR]{\Linear}
\listplot[plotstyle=dots]{\Linear}
\end{psgraph}
\end{figure}

%Fit of Power Function
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=50,xsubticks=1,ysubticks=1](0,0)(0,0)(10,1000){4.5in}{4.5in}
\listplot[decimals=2,EqPos=1 800,plotstyle=GLLSR,PowerFit]{\Power}
\listplot[plotstyle=dots]{\Power}
%\listplot[EqPos=5
4,plotstyle=GLLSR,CustomFit,CheckZeroX=true,CheckZeroY=true,FYtrans=log,RYtrans=10
exch %exp,FXtrans=log]{\Power}
\end{psgraph}
\end{figure}

%Fit of exp Function
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=1000,xsubticks=1,ysubticks=1](0,0)(0,0)(10,10000){4.5in}{4.5in}
\listplot[PstDebug=1,decimals=2,EqPos=4 2000,MaPos=5
7000,plotstyle=GLLSR,ExpFit]{\Exp}
\listplot[plotstyle=dots]{\Exp}
\end{psgraph}
\end{figure}

%Fit of Log10/Loge Functions
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=2,xsubticks=1,ysubticks=1](0,0)(0,0)(10,50){4.5in}{4.5in}
\listplot[decimals=2,EqPos=5 10,plotstyle=GLLSR,LogTFit]{\Logt}
\listplot[decimals=2,plotstyle=dots]{\Logt}
\listplot[decimals=2,EqPos=5 28,plotstyle=GLLSR,LogEFit]{\Loge}
\listplot[decimals=2,plotstyle=dots]{\Loge}
%\listplot[EqPos=5
4,plotstyle=GLLSR,CustomFit,CheckZeroX=true,CheckZeroY=true,FYtrans=Yint
dup mul sub %log,RYtrans=10 exch exp Yint dup mul add,FXtrans=log]{\Linear}
\end{psgraph}
\end{figure}

%Fit of Recip
\begin{figure}
\centering
\begin{psgraph}[arrows=<->,Dx=1,Dy=10,xsubticks=1,ysubticks=1](0,0)(0,0)(10,100){4.5in}{4.5in}
\listplot[decimals=2,EqPos=5 2,plotstyle=GLLSR,RecipFit]{\Recip}
\listplot[plotstyle=dots]{\Recip}
\end{psgraph}
\end{figure}

%Fit of Kings Law data
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=1,xsubticks=1,ysubticks=1](0,0)(0,0)(10,20){4.5in}{4.5in}
\pstScalePoints(1,1){}{dup mul}
\listplot[decimals=2,EqPos=5 2,plotstyle=GLLSR,PowerFit,Yint=5]{\King}
\listplot[plotstyle=dots]{\King}
\pstScalePoints(1,1){}{}
\end{psgraph}
\end{figure}

%Fit of Guassian
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=0.1,xsubticks=1,ysubticks=1](0,0)(-10,0)(10,1){4.5in}{4.5in}
\listplot[plotstyle=dots]{\Gauss}
\listplot[decimals=2,EqPos=5
0.4,plotstyle=GLLSR,GaussFit,plotpoints=400]{\Gauss}
\end{psgraph}
\end{figure}

%Fit of 4th Order Polynomial
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=100,xsubticks=1,ysubticks=1](0,0)(0,-600)(10,600){4.5in}{4.5in}
\listplot[plotstyle=dots]{\Poly}
%note that the valuewidth needs to be large for debugging matrices
\listplot[valuewidth=20,PstDebug=1,decimals=2,EqPos=0.5
-200,plotstyle=GLLSR,MaPos=7
500,MaScale=0.5,PolyOrder=4,plotpoints=400,Yint=500]{\Poly}
\listplot[linestyle=dashed,decimals=2,EqPos=0.5
-400,plotstyle=GLLSR,PolyOrder=4,plotpoints=400]{\Poly}
%\listplot[decimals=2,EqPos=0.5
-200,plotstyle=GLLSR,PolyOrder=10,plotpoints=400]{\Power}
\end{psgraph}
\end{figure}

%LinetoXAxis respects scalepoints.
\begin{figure}
\centering
\begin{psgraph}[arrows=<->,Dx=1,Dy=1,xsubticks=1,ysubticks=1](0,0)(0,0)(10,10){4in}{4in}
\pstScalePoints(0.5,0.25){2 add}{16 add}
\listplot[plotstyle=line]{\Linear}
\listplot[arrows=<-,plotstyle=LineToXAxis]{\Linear}
\pstScalePoints(1,1){}{}
\rput[lb](1,2){Scaled fluid velocity distribution on a plot of the physical
system.}
\end{psgraph}
\end{figure}

%Prepare Points Modification
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=1,xsubticks=1,ysubticks=1](0,0)(0,0)(15,30){4.5in}{4.5in}
\listplot[plotstyle=line,plotNoMax=2,plotNo=1]{\LinearA}
\listplot[plotstyle=line,plotNoMax=2,plotNo=2]{\LinearA}
\listplot[plotstyle=line,linestyle=dashed,plotNoMax=2,plotNo=1,plotNoTwo=2,plotNoTwoFunc=add
2 div]{\LinearA}
\rput[lb](10,18){1st Column}
\rput[lb](10,29){2nd Column}
\rput[lb](10,24){Average of 1st and 2nd Columns}
\end{psgraph}
\end{figure}

%PrintCoor Demo
\begin{figure}
\centering
\begin{psgraph}[arrows=->,Dx=1,Dy=1,xsubticks=1,ysubticks=1](0,0)(0,0)(10,15){4.5in}{4.5in}
%PrintCoor Demo
\psset{xEnd=,xStart=,decimals=2,valuewidth=50,fontscale=10,PstDebug=1}
\pstScalePoints(1,1){0.75 mul}{0.5 exp 3 mul}
\listplot[plotstyle=PrintCoor,plotNoMax=1,plotNo=1,PstDebug=0,relxerr=0,relyerr=0.1]{\Linear}
\listplot[plotstyle=dots,plotNoMax=1,plotNo=1]{\Linear}
\pstScalePoints(1,1){}{}
\end{psgraph}
\end{figure}
\end{document}
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://tug.org/pipermail/pstricks/attachments/20120203/9b83dbef/attachment-0001.html>


More information about the PSTricks mailing list