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!

 Respuesta aceptada

Image Analyst
Image Analyst el 9 de Dic. de 2018

1 voto

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

Más respuestas (1)

John D'Errico
John D'Errico el 8 de Dic. de 2018
Use the tool designed to solve that problem.
help polyfit

2 comentarios

apostolos georgantopoulos
apostolos georgantopoulos el 9 de Dic. de 2018
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 el 9 de Dic. de 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.

Iniciar sesión para comentar.

Categorías

Más información sobre Communications Toolbox en Centro de ayuda y File Exchange.

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by