 LeastSquaresPlot - Maple Help

Student[LinearAlgebra]

 LeastSquaresPlot
 plot 2-D or 3-D points and a least squares fit to those points Calling Sequence LeastSquaresPlot(L, var, opts) LeastSquaresPlot(Lx, Ly, var, opts) LeastSquaresPlot(Lx, Ly, Lz, var, opts) Parameters

 L - list of lists of pairs or list of triples of algebraic values Lx, Ly, Lz - lists of algebraic values var - (optional) name or list of 1 name (2-D case); list of 2 names (3-D case) opts - plotting options or equation(s) of the form option=value where option is one of showboxes, boxoptions, showcurve or showsurface, curveoptions or surfaceoptions, showpoints, pointoptions, curve or surface, or Student plot options; specify options for the plot Description

 • The LeastSquaresPlot(L) command plots the points specified by L, the least squares fit curve or surface, and the errors associated with this fit.  Errors are represented as squares (2-D) or rectangular solids (3-D). The area or volume of these boxes is equal to the square of the error between the approximating curve or surface and the data point to which the box is attached.
 • The points can be given as either a list of lists of 2- or 3-element points, or as two lists representing the components of 2-D points, or three lists representing the components of 3-D points.
 Note: This command takes a slightly different approach to solving the least squares problem than does the LeastSquares command.  The latter command solves a linear system, as represented by a Matrix and a right-hand side Vector, in the least squares sense.  The relation between the two approaches is that the Matrix and Vector arguments to the LeastSquares command are obtained by evaluating the model curve or surface (as specified by the curve or surface argument) at each of the points given in the list argument(s) to this command.
 • The names of the independent variables can be given as an optional argument var.  Otherwise the variables x, or x and y are used.  If the curve or surface option is given, the variable name(s) must also be explicitly given.
 • The opts argument can contain any of the Student plot options or any of the following equations that set plot options.
 showboxes = true or false
 Select whether the boxes representing the errors are plotted.  [Default: true]
 boxoptions = list
 A list of options for the plot of the boxes representing the errors. For more information on plot options, see plot/options. [Default: solid blue squares or rectangular solids]
 showcurve = true or false or showsurface = true or false
 Select whether the fitting curve or surface is plotted.  [Default: true]
 curveoptions = list or surfaceoptions = list
 A list of options for the plot of the fitting curve or surface. For more information on plot options, see plot/options. [Default: red curve (2-D), red wire frame (3-D)]
 showpoints = true or false
 Select whether the points being fitted are plotted.  [Default: true]
 pointoptions = list
 A list of options for plotting the points being fitted. For more information on plot options, see plot/options. [Default: black circles]
 curve = algebraic or surface = algebraic
 An expression in the variables that specifies the curve or surface to which to fit the data. This curve or surface must be linear in the unknown parameter(s), and the variable names must be given in the var parameter.  For example, the curve a*x^2+b*x*y+c is acceptable because it is linear in the parameters $a$, $b$, and $c$. [Default: $ax+b$ (2-D), $ax+by+c$ (3-D)]
 caption = anything
 A caption for the plot.
 The default caption is constructed from the parameters and the command options. caption = "" disables the default caption. For more information about specifying a caption, see plot/typesetting. Examples

These are the commands to create the plots in the Plotting Guide.

 > $\mathrm{with}\left(\mathrm{Student}\left[\mathrm{LinearAlgebra}\right]\right):$
 > $\mathrm{infolevel}\left[\mathrm{Student}\left[\mathrm{LinearAlgebra}\right]\right]≔1:$
 > $\mathrm{L1}≔\left[\mathrm{seq}\left(\left[\mathrm{sin}\left(0.5i\right),\mathrm{cos}\left(0.3i\right)\right],i=3..12\right)\right]:$
 > $\mathrm{LeastSquaresPlot}\left(\mathrm{L1},\left[x,y\right],\mathrm{curve}=a+bx,\mathrm{boxoptions}=\left[\mathrm{color}=\mathrm{magenta}\right]\right)$
 Fitting curve: -.3148+.7556*x Least squares error: .4979 Maximum error: .3708 Compare the use of the LeastSquaresPlot command with that of the LeastSquares command, which solves a linear system in the least-squares sense.

 > $\mathrm{L2}≔\left[\mathrm{seq}\left(\left[\mathrm{sin}\left(0.5i\right),\mathrm{cos}\left(0.4i\right),\mathrm{cos}\left(0.3i\right)\mathrm{sin}\left(0.3i\right)\right],i=3..15\right)\right]:$
 > $A≔\mathrm{Matrix}\left(\left[\mathrm{seq}\left(\left[1,i\left[1\right],i\left[1\right]i\left[2\right],i\left[2\right]\right],i=\mathrm{L2}\right)\right]\right)$
 ${A}{≔}\begin{array}{c}\left[\begin{array}{cccc}{1}& {0.9974949866}& {0.3614500435}& {0.3623577545}\\ {1}& {0.9092974268}& {-0.02655105049}& {-0.02919952230}\\ {1}& {0.5984721441}& {-0.2490522895}& {-0.4161468365}\\ {1}& {0.1411200081}& {-0.1040610071}& {-0.7373937155}\\ {1}& {-0.3507832277}& {0.3305157939}& {-0.9422223407}\\ {1}& {-0.7568024953}& {0.7555119774}& {-0.9982947758}\\ {1}& {-0.9775301177}& {0.8766083602}& {-0.8967584163}\\ {1}& {-0.9589242747}& {0.6267947351}& {-0.6536436209}\\ {1}& {-0.7055403256}& {0.2168357332}& {-0.3073328700}\\ {1}& {-0.2794154982}& {-0.02444857205}& {0.08749898344}\\ {⋮}& {⋮}& {⋮}& {⋮}\end{array}\right]\\ \hfill {\text{13 × 4 Matrix}}\end{array}$ (1)
 > $B≔\mathrm{Vector}\left(\left[\mathrm{seq}\left(i\left[3\right],i=\mathrm{L2}\right)\right]\right)$
 ${B}{≔}\begin{array}{c}\left[\begin{array}{c}{0.4869238154}\\ {0.3377315903}\\ {0.07056000403}\\ {-0.2212602217}\\ {-0.4357878862}\\ {-0.4980823044}\\ {-0.3863822437}\\ {-0.1397077491}\\ {0.1557706817}\\ {0.3968339319}\\ {⋮}\end{array}\right]\\ \hfill {\text{13 element Vector[column]}}\end{array}$ (2)
 > $\mathrm{LeastSquares}\left(A,B\right)$
 $\left[\begin{array}{c}{0.3113183232}\\ {-0.1089398230}\\ {-0.4173342936}\\ {0.5661710438}\end{array}\right]$ (3)
 > $\mathrm{LeastSquaresPlot}\left(\mathrm{L2},\left[x,y\right],\mathrm{surface}=a+bx+cxy+dy\right)$
 Fitting surface: .3113-.1089*x+.5662*y-.4173*x*y Least squares error: .3848 Maximum error: .2300 