Curve fitting, including linear regression, is a powerful way to assess whether signals you observe behave in a predictable manner.
At the end of this module, you will be able to
- Determine the correlation between measurements and independent variables
- Fit data to any function
- Use a general linear model to analyze data
- The main MLX
./docs/curveFitting.mlxexplains various approaches to curve fitting in Matlab. ./docs/errorSurface.mlxvisualizes a so-called error surface associated with curve fitting.
As discussed in ./docs/curveFitting.mlx for nonlinear curve fitting there is no guarantee that the fit function finds the global optimum. While there are some fancy tools (e.g. simulated annealing) to improve the likelihood of finding a global optimum, in this assignment you'll create a function that uses a brute-force technique.
Your assignment is to write a function that runs a nonlinear fit (using the fit.m function in the Curve Fitting Toolbox) from a range of starting positions and returns the best overall fit.
Start from the ./code/iterateFit.m function in the code folder.
Steps:
- The function should be documented and commented appropriately.
iterateFitshould return the same output asfititerateFitshould accept the same inputs asfit(including all its parameter/value pairs)iterateFitshould also accept the following parameter/value pair:
min(a vector with the lowest starting point for each parameter)max(a vector with largest starting point for each parameter )n(the total number of starting points to try).
iterateFitshould generatenrandom starting positions distributed randomly betweenminandmaxfor each parameter, loop over those, and return the best overall solution. Hint userand.