Can anyone please help with this?
4 views (last 30 days)
Show older comments
apostolos georgantopoulos
on 8 Dec 2018
Answered: Image Analyst
on 9 Dec 2018
x=linspace(-5, 5,100);
y = [-ones(1,50) + 0.2*rand(1,50), ones(1,50)-0.2*rand(1,50)];
f(x) = a2*x^ 2 + a1*x + a0;
where ai, i=0,1,2... are real parameters
I have to find ai so that Sum(i=1:100) (yi − f(xi))^2 becomes minimum, using least squares method. Thanks!
0 Comments
Accepted Answer
More Answers (1)
John D'Errico
on 8 Dec 2018
Use the tool designed to solve that problem.
help polyfit
2 Comments
John D'Errico
on 9 Dec 2018
I would strongly recommend you do some reading about regression modeling, etc., because I won't spend hours writing an in depth explanation of these concepts from statistics. That is not the scope of Answers, since it is not about MATLAB.
But, yes, polyfit does indeed minimze the sum of squares of the residual errors. And what is that sum? What is
y(i) - f(x(i))
Since f(x(i)) would be the model prediction at point x(i), then y(i) - f(x(i)) is the error at that point, of the model prediction compared to the corresponding value of y. Squaring that error at each point, and then forming the sum of squares of all those residuals, yields the sum you ask about. Why is that a good metric to minimize to fit a model? Again, this starts to delve more deeply into statistics, and I won't teach a statistics course in the comments.
See Also
Categories
Find more on Regression 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!