517
517
let d1 = sin(x), cos(x) from 0 to 2*pi
520
\item[{\sf let {\it dn} = [routine] {\it dm} [options]}]
520
\item[{\sf let {\it dn} = [routine] {\it dm} [options] [{\it slopevar}] [{\it offsetvar}] [{\it rsqvar}]}]
522
GLE includes several fitting routines that allow an equation to be fit to a data series. These routines can be included in a `let' expression as shown above, where {\it dn} will contain results of fitting {\sf routine} to the data in {\it dm}, and the {\sf [options]} control the limits to which the data in {\it dn} extends.
522
GLE includes several fitting routines that allow an equation to be fit to a data series. These routines can be included in a `let' expression as shown above, where {\it dn} will contain results of fitting {\sf routine} to the data in {\it dm}.
524
524
The following routines are available :
529
529
\item \texttt{powxfit}\index{powxfit}: fits the data in \textit{dm} to the equation $y = a \cdot x^b$.
532
The value for $a$ is stored in `{\it slopevar}' and the value for $b$ is stored in `{\it offsetvar}'. The $r^2$ value of the fit is stored in `{\it rsqvar}'. Note that these variables are optional.
532
534
The following options are available :
536
\item \texttt{from {\it xmin} to {\it xmax}} The range of the data in \textit{dn} extends from the \textit{xmin} to \textit{xmax} as specified by the user.
538
\item \texttt{step {\it xstep}} Specifies the x-resolution of the fitted equation. Similar to the \texttt{step} option of the \texttt{let} command.
540
\item \texttt{rsq {\it var}} The $r^2$ value of the fit will be stored in {\it var}.
542
\item \texttt{xmin {\it x1}}, \texttt{xmax {\it x2}}, \texttt{ymin {\it y1}}, \texttt{ymax {\it y2}} Only use data points from dm in the given window to fit the equation. That is, only data points $(x,y)$ from dm are used for which $x_1 \le x \le x_2$ and $y_1 \le y \le y_2$.
534
544
\item \texttt{limit\_data\_x} The range of the data in \textit{dn} extends from the minimum $x$ value in \textit{dm} to the maximum $x$ value in \textit{dm}.
536
546
\item \texttt{limit\_data\_y} The range of the data in \texttt{dn} extends from the $x$ value of the minimum $y$ value in \textit{dm} to the $x$ value of the maximum $y$ value in \textit{dm}.
538
548
\item \texttt{limit\_data} The range of the data in \textit{dn} extends from the greater of the $x$ value of the minimum $y$ value or the minimum $x$ value in \textit{dm} to the greater of the $x$ value of the maximum $y$ value or the maximum $x$ value in \textit{dm}.
540
\item \texttt{from {\it xmin} to {\it xmax}} The range of the data in \textit{dn} extends from the \textit{xmin} to \textit{xmax} as specified by the user.
543
\begin{minipage}[c]{8cm}
552
\begin{minipage}[c]{9.2cm}
554
slope = 0; offs = 0; rsquare = 0
550
560
ytitle "$y = ax + b$"
552
let d2 = linfit d1 from 0 to 10 slope offs
562
let d2 = linfit d1 from 0 to 10 slope offset rsquare
563
d1 marker circle color blue
558
amove xg(xgmax)-0.25 yg(2)
559
tex "$y = " + format$(slope,"fix 2") +
560
"x + " + format$(offs,"fix 2") + "$"
569
text "$y = "+format$(slope,"fix 2")+"x + "+format$(offset,"fix 2")+"$"
570
text "$r^2 = "+format$(rsquare,"fix 2")+"$"
564
575
\begin{minipage}[c]{7cm}
565
576
\mbox{\input{graph/fig/gc_fit.inc}}
578
\caption{\label{fig:fitlin}Fitting linear equations `let d2 = fitlin d1'.}
582
\begin{minipage}[c]{8cm}
584
a = 0; b = 0; c = 0; d = 0; r = 0
590
title "$f(x) = a\sin(bx)+cx^2+d$"
592
let d2 = fit d1 with a*sin(b*x)+c*x^2+d rsq r
593
d1 marker circle color blue
597
fct$ = "$f(x) = "+format$(a,"fix 2")+ &
598
"\sin("+format$(b,"fix 2")+"x)+"+ &
599
format$(c,"fix 2")+"x^2+"+ &
600
format$(d,"fix 2")+"$"
605
text "$r^2$ = "+format$(r,"fix 3")
610
\begin{minipage}[c]{7cm}
611
\mbox{\input{graph/fig/gc_fitfct.inc}}
613
\caption{\label{fig:fitfct}Fitting arbitrary curves `let d2 = fit d1 with $\ldots$'.}
616
\item[{\sf let {\it dn} = fit {\it dm} with {\it eqn} [options]}]
618
Fit the coefficients of a given equation so that it best fits the data in dataset dm. Fig.~\ref{fig:fitfct} shows an example. The equation to fit is given by the `\texttt{with}' option. In this example, it is $a\sin(bx)+cx^2+d$. GLE will search for values for the coefficients $a$, $b$, $c$, and $d$ such that the given equation fits dm best. Note that all used coefficients must be initialized to zero before the graph block (see figure).
620
The fit command has the same options as the linfit command. In addition, it has the following settings.
623
\item \texttt{with {\it eqn}} Gives the equation to fit.
625
\item \texttt{eqstr {\it strvar\$}} Sets the string variable in which the string representation of the fitted equation is to be stored.
627
\item \texttt{format {\it fmt\$}} Sets the numeric format to use while converting the fitted equation into its string representation. See the documentation of {\sf format\$} on page~\pageref{formatnum:pg} for a description of the syntax.
568
630
\item[{\sf let ds = hist dm [from {\it x1}] [to {\it x2}] [bins {\it n}] [step {\it n}]}]
569
631
\index{histogram}\index{let!hist}