Application Center - Maplesoft

App Preview:

Regression and Data Fitting in Maple

You can switch back to the summary page by clicking here.

Learn about Maple
Download Application


 

Image 

 

Regression and Data Fitting 

? 2008 Waterloo Maple Inc. 

Introduction 

 

This worksheet contains examples using the function LeastSquares from the "CurveFitting" package to perform linear, polynomial, and non-linear regression. It is important to load this package before you attempt to perform these calculations. The package has been loaded in the Startup Code (Edit>Startup Code). 

 

 

Defining the Data 

 

Create a set of data, X values and Y values, in separate lists: 

 

`:=`(Xvals, [3.80, 4.11, 5.18, 4.52, 5.49, 4.89, 1.11, 5.35, 2.09, .60, 6.53, 1.40]) 

[3.80, 4.11, 5.18, 4.52, 5.49, 4.89, 1.11, 5.35, 2.09, .60, 6.53, 1.40] (2.1)
 

 

 

`:=`(Yvals, [56.1, 56.2, 40.0, 45.9, 45.3, 38.5, 32.4, 31.0, 50.0, 18.2, 30.1, 45.8]) 

[56.1, 56.2, 40.0, 45.9, 45.3, 38.5, 32.4, 31.0, 50.0, 18.2, 30.1, 45.8] (2.2)
 

 

 

Linear Regression 

 

This example will fit a linear equation to the data represented. 

 

`:=`(points, ScatterPlot(Xvals, Yvals)); -1 

 

LeastSquares(Xvals, Yvals, x); 1 

`+`(37.68335454, `*`(.8275958630, `*`(x))) (3.1)
 

`:=`(curve1, plot(`+`(37.68335454, `*`(.8275958630, `*`(x))), x = 0 .. 6)); -1 

 

display([points, curve1], title =  

Plot_2d
 

 

 

Polynomial Regression 

 

The mathematics below show examples using Maple for polynomial regression. An equation of a given form is produced for the data defined above and then plotted on a graph. 

 

 

LeastSquares(Xvals, Yvals, x, curve = `+`(`*`(a, `*`(`^`(x, 2))), `*`(b, `*`(x)), c)) 

`+`(12.84503218, `*`(22.56550378, `*`(x)), `-`(`*`(3.217983236, `*`(`^`(x, 2))))) (4.1)
 

 

 

`:=`(curve2, plot(`+`(12.84503218, `*`(22.56550378, `*`(x)), `-`(`*`(3.217983236, `*`(`^`(x, 2))))), x = 0 .. 6)); -1 

display([points, curve2], title =  

Plot_2d
 

 

LeastSquares(Xvals, Yvals, x, curve = `+`(`*`(a, `*`(`^`(x, 4))), `*`(b, `*`(`^`(x, 3))), `*`(c, `*`(`^`(x, 2))), `*`(d, `*`(x)), e)) 

`+`(`-`(5.887569813), `*`(44.95857773, `*`(x)), `-`(`*`(7.601618663, `*`(`^`(x, 2)))), `-`(`*`(.3470329692, `*`(`^`(x, 3)))), `*`(0.9006372002e-1, `*`(`^`(x, 4)))) (4.2)
 

 

`:=`(curve3, plot(`+`(`-`(5.887569813), `*`(44.95857773, `*`(x)), `-`(`*`(7.601618663, `*`(`^`(x, 2)))), `-`(`*`(.3470329692, `*`(`^`(x, 3)))), `*`(0.9006372002e-1, `*`(`^`(x, 4)))), x = 0 .. 6)); -1 

display([points, curve3], title =  

Plot_2d
 

 

 

 

 

Non-Linear Regression 

 

The following examples show how to fit non-linear equations to the data defined above. The equations will be of type logarithmic and exponential. 

 

LeastSquares(Xvals, Yvals, x, curve = `+`(a, `*`(b, `*`(exp(x))))) 

`+`(43.05427411, `-`(`*`(0.1632296059e-1, `*`(exp(x))))) (5.1)
 

`:=`(curve4, plot(`+`(43.05427411, `-`(`*`(0.1632296059e-1, `*`(exp(x))))), x = 0 .. 6)); -1 

display([points, curve4], title =  

Plot_2d
 

 

 

LeastSquares(Xvals, Yvals, x, curve = `+`(a, `*`(b, `*`(ln(x))))) 

`+`(34.67301471, `*`(5.474268555, `*`(ln(x)))) (5.2)
 

`:=`(curve5, plot(`+`(34.67301471, `*`(5.474268555, `*`(ln(x)))), x = 0 .. 6)); -1 

display([points, curve5], title =  

Plot_2d
 

 

 

NOTE: The previous examples illustrate Maple's built-in functional capabilities. However, it is important to note that Maple is a programming language and can be used to implement different algorithms or methods 

 

Legal Notice: The copyright for this application is owned by Maplesoft. The application is intended to demonstrate the use of Maple to solve a particular problem. It has been made available for product evalution purposes only and may not be used in any other context without the express permission of Maplesoft.