Student[LinearAlgebra]
LeastSquaresPlot
plot 2-D or 3-D points and a least squares fit to those points
Calling Sequence
Parameters
Description
Examples
LeastSquaresPlot(L, var, opts)
LeastSquaresPlot(Lx, Ly, var, opts)
LeastSquaresPlot(Lx, Ly, Lz, var, opts)
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
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: a⁢x+b (2-D), a⁢x+b⁢y+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.
These are the commands to create the plots in the Plotting Guide.
with⁡StudentLinearAlgebra:
infolevelStudentLinearAlgebra≔1:
L1≔seq⁡sin⁡0.5⁢i,cos⁡0.3⁢i,i=3..12:
LeastSquaresPlot⁡L1,x,y,curve=a+b⁢x,boxoptions=color=magenta
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.
L2≔seq⁡sin⁡0.5⁢i,cos⁡0.4⁢i,cos⁡0.3⁢i⁢sin⁡0.3⁢i,i=3..15:
A≔Matrix⁡seq⁡1,i1,i1⁢i2,i2,i=L2
B≔Vector⁡seq⁡i3,i=L2
LeastSquares⁡A,B
0.3113183232−0.1089398230−0.41733429360.5661710438
LeastSquaresPlot⁡L2,x,y,surface=a+b⁢x+c⁢x⁢y+d⁢y
Fitting surface: .3113-.1089*x+.5662*y-.4173*x*y Least squares error: .3848 Maximum error: .2300
See Also
CurveFitting[LeastSquares]
plot/options
plot/typesetting
Student plot options
Student[LinearAlgebra][LeastSquares]
Download Help Document