UP | HOME

Exercise 28

Curve fitting

Here are 10 pairs of (x,y) data:

x = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10];
y = [18, 5, 17, 38, 40, 106, 188, 234, 344, 484];

Your task is to fit a function to the data. The function has the form:

\begin{equation} \hat{y_{i}} = \beta_{0} + \beta_{1}x_{i} + \beta_{2}x_{i}^{2} + \beta_{3}x_{i}^{3} \end{equation}

and the cost function \(J\) is:

\begin{equation} J = \sum_{i=1}^{10} (\hat{y_{i}} - y_{i})^{2} \end{equation}

Use whatever optimizer you wish. Plot the data as a scatter plot of x vs y, and plot the function that corresponds to the parameter values \(\beta\) that minimize \(J\).

solutions


Paul Gribble | fall 2014
This work is licensed under a Creative Commons Attribution 4.0 International License
Creative Commons License