Chapter 4: Partial Differentiation
Section 4.8: Unconstrained Optimization
|
Example 4.8.12
|
|
By minimizing the sum of squares of deviations between and the points , obtain the best least-squares quadratic fit to the data.
|
|
|
|
Solution
|
|
|
Mathematical Solution
|
|
•
|
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 from the graph of the function is measured vertically, and given by the difference . The sum of the squares of deviations of the given data points from the line is given by
|
|
>
|
use plots in
module()
local p1,p2,p3:
p1:=pointplot([1,2,3,4,5],[3,8,15,30,38],symbol=solidcircle,symbolsize=15,color=green);
p2:=plot(-9/5+(16/5)*x+x^2,x=0..6,0..40,color=red);
p3:=display(p1,p2,scaling=constrained);
print(p3);
end module:
end use:
|
|
Figure 4.8.12(a) Data and least-squares line
|
|
|
|
|
|
•
|
To minimize , solve the equations for , and .
|
•
|
The least-squares quadratic is then .
|
|
|
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 Name
|
|
|
•
|
Context Panel: Assign Function
|
|
|
Define , the sum of squares of deviations
|
•
|
Expression palette: Summation template
|
•
|
Context Panel: Assign Name
|
|
|
Minimize
|
•
|
Calculus palette: Partial-differentiation template
|
•
|
Context Panel: Solve≻Solve
|
•
|
Context Panel: Assign to a Name≻
|
|
|
Obtain the least-squares quadratic
|
•
|
Expression palette: Evaluation template
Press the Enter key.
|
|
=
|
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 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
|
•
|
Context Panel:
Curve Fitting≻Interactive Curve Fitting
|
|
=
|
|
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 , 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 Entry
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)
|
|
|
Fitting Function
•
|
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.
|
|
|
Variables
•
|
The default line will use the variables .
|
•
|
The default plane will use the variables
|
•
|
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.
|
|
|
|
|
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
|
•
|
Use the "arrow" notation for defining .
|
|
|
Obtain , the sum of squares of the deviations
|
|
|
Minimize
|
Use the diff command to form equations and the solve command to solve them for , and .
|
|
Insert the optimal values of , and into
|
|
|
|
|
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).
|
|
|
<< Previous Example Section 4.8
Next Section >>
© Maplesoft, a division of Waterloo Maple Inc., 2024. 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
|