8.4: Practice Curve Fitting Example
- Page ID
- 64250
Consider the following polynomial with constant scalars \(a\), \(b\), and \(c\), that falls on the \(xy\)-plane:
\[f(x) = ax^2 + bx + c \nonumber \]
Is this function linear? Why or why not?
Assume that we do not know the values of \(a\), \(b\) and \(c\), but we do know that the points (1,2), (-1,12), and (2,3) are on the polynomial. We can substitute the known points into the equation above. For eample, using point (1,2) we get the following equation:
\[2 = a1^2 + b1 + c \nonumber \]
\[\text{or} \nonumber \]
\[2 = a + b + c \nonumber \]
Generate two more equations by substituting points (-1,12) and (2,3) into the above equation:
If we did this right, we should have three equations and three unknowns (\(a\),\(b\),\(c\)). Note also that these equations are linear (how did that happen?). Transform this system of equations into two matrices \(A\) and \(b\) like we did above.
Write the code to solve for \(x\) (i.e., (\(a\),\(b\),\(c\))) using numpy
.
Given the value of your x
matrix derived in the previous question, what are the values for \(a\), \(b\), and \(c\)?
Assuming the above is correct, the following code will print your 2nd order polynomial and plot the original points:
The following program is intended to take four points as inputs (\(p1\), \(p2\), \(p3\), \(p4\) \( \in R^2 \)) and calculate the coefficients \(a\), \(b\), \(c\), and \(d\) so that the graph of \(f(x) = ax^3 + bx^2 + cx + d\) passes smoothly through the points. Test the function with the following points (1,2), (-1,6), (2,3), (3,2) as inputs and print the values for \(a\), \(b\), \(c\), and \(d\).
Modify the above fitpoly3
function to also generate a figure of the input points and the resulting polynomial in range x=(-3,3)
.
Give any four \(R^2\) input points to fitPoly3
, is there always a unique solution? Explain your answer.