Can anyone please help with this?
이전 댓글 표시
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!
채택된 답변
추가 답변 (1개)
John D'Errico
2018년 12월 8일
Use the tool designed to solve that problem.
help polyfit
댓글 수: 2
apostolos georgantopoulos
2018년 12월 9일
John D'Errico
2018년 12월 9일
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.
카테고리
도움말 센터 및 File Exchange에서 Communications Toolbox에 대해 자세히 알아보기
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!
