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!

 채택된 답변

Image Analyst
Image Analyst 2018년 12월 9일

1 개 추천

See attached polyfit() demo and adapt as needed.
0000 Screenshot.png

추가 답변 (1개)

John D'Errico
John D'Errico 2018년 12월 8일

1 개 추천

Use the tool designed to solve that problem.
help polyfit

댓글 수: 2

if i use p=polyfit(x,y,2) i will get the equation of the best fit parabolic curve which will be in the form of f(x)=p(1)*x^2+p(2)*x+p(3). But is this the result im asking for? I dont really get what the meaning of this sum that i want to become minimum is.
John D'Errico
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!

Translated by