Quadratic Regression Find Fit

Description

Here, we will plot a quadratic regression and scatter plot for the following data:

(1)
\begin{align} \{ \ (0, 2.3), \ (1, 11.5), \ (2, 24.7), \ (3, 37.8), \ (4, 55.6), \ (5, 70.0) \} \end{align}

Sage has no default model for find_fit(), so we must set one using other letters as constants, declaring them with var(). In order to perform a quadratic regression, the model we pass to find_fit() is the standard expanded quadratic form, $ax^2 + bx + c$. This can be done with any polynomial (for example, a quartic regression would use $ax^4 + bx^3 + cx^2 + dx + e$. Just make sure to define your constant variables with var())

Sage Cell

Code

var('a b c')

dataset = [ (0, 2.3), (1, 11.5), (2, 24.7), (3, 37.8), (4, 55.6), (5, 70.0) ]
model(x) = a*x^2 + b*x + c
find_fit(dataset, model)
[[/code]]
r(x) = 0.7928*x^2 + 9.8614*x + 1.7285
p1 = scatter_plot( dataset )
p2 = plot(r(x), -1, 6)
(p1 + p2).show()

Options

none

Tags

Primary Tags:

Secondary Tags:

A list of possible tags can be found at The WeBWorK Open Problem Library. For linear algebra tags see the Curated Courses Project.

Related Cells

Any related cells go here. Provide a link to the page containing the information about the cell.

Attribute

Permalink:

Author:

Date: 06 Mar 2019 22:58

Submitted by: Zane Corbiere

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-ShareAlike 3.0 License