Student[LinearAlgebra] - Maple Programming Help

Home : Support : Online Help : Education : Student Packages : Linear Algebra : Visualization : Student/LinearAlgebra/LeastSquaresPlot

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)$
  (1)
 > $B≔\mathrm{Vector}\left(\left[\mathrm{seq}\left(i\left[3\right],i=\mathrm{L2}\right)\right]\right)$
  (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