Chapter 4: Partial Differentiation
Section 4.8: Unconstrained Optimization
By minimizing the sum of squares of deviations S=∑k=15fxk−yk2 between fx=a x2+b x+c and the points 1,3,2,8,3,15,4,30,5,38, obtain the best least-squares quadratic fit to the data.
Figure 4.8.12(a) shows the least-squares quadratic in red, and the four given data points in green.
The deviation of the data point xk,yk from the graph of the function fx is measured vertically, and given by the difference fxk−yk. The sum of the squares of deviations of the given data points from the line y=a x+b is given by
use plots in
Figure 4.8.12(a) Data and least-squares line
=979⁢a2+450⁢a⁢b+110⁢a⁢c+55⁢b2+30⁢b⁢c+5⁢c2−3200 a−748 b−188 c+2642
To minimize S, solve the equations ∂S∂a=∂S∂b=∂S∂c= for a=1, b=16/5 and c=−9/5.
The least-squares quadratic is then y=x2+16 x/5−9/5.
Maple Solution - Interactive
In Table 4.8.12(a), the required least-squares quadratic is constructed from first principles. The first step is to decide an appropriate form for the data, either a list of abscissas and ordinates, or a list of data points.
Define lists of abscissas and ordinates
Context Panel: Assign Name
Context Panel: Assign Function
fx=a x2+b x+c→assign as functionf
Define S, the sum of squares of deviations
Expression palette: Summation template
Calculus palette: Partial-differentiation template
Context Panel: Solve≻Solve
Context Panel: Assign to a Name≻Q
∂∂ a S=0,∂∂ b S=0,∂∂ c S=0
→assign to a name
Obtain the least-squares quadratic
Expression palette: Evaluation template
Press the Enter key.
fxx=a|f(x)Q = −95+165⁢x+x2
Table 4.8.12(a) Construction of least-squares line from first principles.
Table 4.8.12(b) illustrates the
Assistant, accessed through the Context Panel launched on a sequence of the lists of abscissas and ordinates for the data points. Figure 4.8.12(b) shows the state of the Assistant after entering fx into the Expression box in the Least Squares section, and pressing the Plot button to its right. The expression for the least-squares quadratic appears under the graph, and either this expression or the graph can be chosen as the return when the "Done" button is clicked.
The Curve-Fitting Assistant is no longer listed in Tools≻Assistants. It is now found in Tools≻Tutors≻Statistics≻Curve Fitting.
Launch the Curve-Fitting Assistant from the Context Panel
Context Panel: Evaluate and Display Inline
Curve Fitting≻Interactive Curve Fitting
X,Y = 1,2,3,4,5,3,8,15,30,38
Figure 4.8.12(b) Least-squares line by Curve-Fitting Assistant
Table 4.8.12(b) Least-squares quadratic via the Curve-Fitting Assistant
Table 4.8.12(c) illustrates the
task template. In addition to returning the least-squares quadratic and the minimum value of S, the sum of squares of deviations, the template draws a graph of the data points and the least-squares line annotated with small squares near the data points. The area of a square is in proportion to the square of the deviation at that point.
Tools≻Tasks≻Browse: Linear Algebra≻Visualizations≻Least Squares Plot
Least Squares Plot
Data can be entered in one of the following formats:
List of lists (either 2-D or 3-D)
Two lists of coordinates (for 2-D)
Three lists of coordinates (for 3-D)
If the fitting function is linear (line in 2-D or plane in 3-D), a function need not be entered.
If a formula for a curve or surface (linear in the unknown parameters) is optionally entered, variables must be explicitly declared, below.
Line or PlaneOther
The default line will use the variables x,y.
The default plane will use the variables x,y,z.
Optionally, these defaults can be overridden.
If a fitting function has been given explicitly, variables must be declared as a sequence or list.
Click the icon below to generate the Least Squares Plot.
Fitting curve: -1.800+3.200*x+1.000*x^2
Least squares error: 3.795
Maximum error: 3.000
Table 4.8.12(c) The Least-Squares Plot task template
Maple Solution - Coded
Solution from first principles:
Enter the data
Define lists of the abscissas and ordinates.
Define the quadratic fitting function fx
Use the "arrow" notation for defining fx.
f≔x→a x2+b x+c:
Obtain S, the sum of squares of the deviations
Apply the sum command.
Use the diff command to form equations and the solve command to solve them for a,b, and c.
Insert the optimal values of a,b, and c into fx
Use the eval command.
To obtain just the least-squares quadratic:
Apply the LeastSquares command from the CurveFitting package.
To obtain a figure like the one in Table 4.8.12(c), use the LeastSquaresPlot command from the Student LinearAlgebra package. See Table 4.8.12(d).
Table 4.8.12(d) Least-squares line via the LeastSquaresPlot command
<< Previous Example Section 4.8
Next Section >>
© Maplesoft, a division of Waterloo Maple Inc., 2023. All rights reserved. This product is protected by copyright and distributed under licenses restricting its use, copying, distribution, and decompilation.
For more information on Maplesoft products and services, visit www.maplesoft.com
Download Help Document