home

Scientific Computing (Psychology 9040a)

Fall, 2021

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:

\[ \hat{y_{i}} = \beta_{0} + \beta_{1}x_{i} + \beta_{2}x_{i}^{2} + \beta_{3}x_{i}^{3} \]

and the cost function \(J\) is:

\[ J = \sum_{i=1}^{10} (\hat{y_{i}} - y_{i})^{2} \]

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_{0},\beta_{1})\) that minimize \(J\).


sample solution