Programming a simple function for estimating regression?
Show older comments
Write a MATLAB function which, given the input vectors x and y, containing the values xi and yi, respectively, and a natural number n, will find the least-squares approximation with the basis functions fj(x) = x^(i-1), j = 1,...,n, and return the vector a of the regression parameters aj and the value of the minimum total squared error E. Use your function for input variables x = l:length(vec), y = vec, and n=3. Include a plot of the input data points and the resulting estimation function y(x).
(((vec = [8 3 5 6 6 7 12 16 13 9 11 15 20] ))).
(((The data points are given by (xi,yi), i = 1,...,m in the form y(x) = sum (to n from j = 1) of ajfj(x), where fj(x) are the basis functions and aj are the regression parameters obtained by minimising the total squared error E = sum (to m from i = 1) of (yi - y(xi) )^2 ))).
Where I am struggling is that I am not allowed to use polyval or polyfit, as it needs to be as efficient as possible.
By the way, I have no idea where to start, which is why I haven't included anything else, so any help would be appreciated.
Answers (0)
Categories
Find more on Descriptive Statistics in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!