Derivation of Line of Best Fit

Click For Summary

Homework Help Overview

The discussion revolves around deriving the coefficients A and B for the line of best fit, represented by the equation f(x) = Ax + B, using a set of data points. The goal is to minimize the sum of squared vertical distances, denoted as D, which is defined as D = ∑[yi - f(xi)]². Participants are exploring the differentiation of D with respect to A and B to find the optimal values of these coefficients.

Discussion Character

  • Exploratory, Mathematical reasoning, Problem interpretation

Approaches and Questions Raised

  • Participants are attempting to differentiate the expression for D and are questioning how to express D in a simpler form. There are discussions about the necessity of using the least squares method for only two data points and whether the problem has been copied correctly. Some participants are also exploring the implications of combining the equations derived from the partial derivatives.

Discussion Status

The discussion is ongoing, with participants providing guidance on how to express D and differentiate it. Some participants have shared their results from differentiation, while others are questioning the feasibility of solving for A and B from the resulting equations. There is no explicit consensus yet, but several productive lines of reasoning are being explored.

Contextual Notes

Participants are working under the constraints of a homework assignment, which may limit the depth of exploration. There are also discussions about the assumptions involved in using the least squares method for a small number of data points.

tmobilerocks
Messages
25
Reaction score
0

Homework Statement


Consider a set of data points: (x1, y1), (x2,y2). One seeks to find the best coefficients A and B such that the sum of squared vertical distances of the data f(x) = Ax + B is minimized. Let D = ∑[yi - f(xi]2. By requiring the derivatives of D respect to both A and B each to vanish, find expressions for the values of A and B in terms of the data points. Why are these derivatives made to vanish?

Homework Equations


Line of best fit is a linear equation: f(x) = Ax + B
D must be a minimum

The Attempt at a Solution


I am totally lost by this question. I do not understand how to differentiate D with respect to these parameters (maybe implicit differentiation?)
 
Physics news on Phys.org
You have ##D(A, B) = [y_1 - f(A, B, x_1)]^2 + [y_2 - f(A, B, x_2)]^2 ##. ##x_1, x_2, y_1, y_2## are all known and constant, ##A, B## are unknown variables.
 
Am I supposed to differentiate D? How would I go about doing that?
 
tmobilerocks said:
Am I supposed to differentiate D? How would I go about doing that?

Yes, that is what you are supposed to do. First, though, you need to express ##D## in more explicit form; just use the equation for ##f(x)## at ##x = x_1## and ##x = x_2## to get a sum that contains ##A, B## in fairly simple form. At that point you are supposed to know what to do next, using what you learned in calculus 101.

Are you sure you copied the problem correctly? For just two points you don't need to bother with this "least squares" method; it works, but is unnecessary. However, if you had more than two points you would soon discover the value of the method. BTW: it is almost as easy to do with 1000 points as with two points; all that happens is that you need to evaluate bigger sums. Try it out to see what I mean.
 
Consider the following: If f(x) = Ax + B and D = ∑[yi - f(xi]2, then

D=\sum_{i=1}^n(y_i-Ax_i-B)^2
Take the partial derivative of D with respect to A and set it equal to zero.
Take the partial derivative of D with respect to B, and set it equal to zero.
Combine the coefficients of A and of B in the resulting equations.
Solve for A and B.

What you are doing is minimizing the deviation of the straight line from the data points (where the data points have experimental error, and thus do not all lie on anyone straight line).
 
Is this correct?

I took the partial of D with respect to A, and set it equal to zero. I obtained the result

0 = -2xiyi + 2Axixi - 2Bxi

I then took the partial of D with respect to B, and set it equal to zero. The result I obtained was

0 = -2yi + 2Axi + 2B

After combining these two expressions, and solving for A and B I obtained:

A = (-xiyi + yi -Bx - B)/(xi-xixi)

B = (-xiyi + yi - Axi + Axixi)/(1+x)
 
I do not see how you solved for A and B if both sides of the equation contain them.
 
Am I on the right track? Is there a simpler way to solve this? Combining both of them makes it nearly impossible to solve
 
What is so impossible about that?

The first equation can be rewritten as ## 0 = p + q A + r B ##, where ##p, q, r ## are all made of the known ##x_i, y_i## values. The second equation can be rewritten as ## 0 = u +v A + w B ## in a similar way. Surely you can then solve two linear equations for A and B.
 
  • #10
tmobilerocks said:
Is this correct?

I took the partial of D with respect to A, and set it equal to zero. I obtained the result

0 = -2xiyi + 2Axixi - 2Bxi

I then took the partial of D with respect to B, and set it equal to zero. The result I obtained was

0 = -2yi + 2Axi + 2B

After combining these two expressions, and solving for A and B I obtained:

A = (-xiyi + yi -Bx - B)/(xi-xixi)

B = (-xiyi + yi - Axi + Axixi)/(1+x)

In the following two equations, you need to have summation signs on each of the terms, where the summations are over all the data points.

0 = -2xiyi + 2Axixi - 2Bxi

0 = -2yi + 2Axi + 2B

Once you get the summations in there, you factor out the A and B, and solve these two equations for the two unknowns A and B.

Chet
 

Similar threads

Replies
2
Views
2K
Replies
3
Views
2K
Replies
22
Views
3K
  • · Replies 4 ·
Replies
4
Views
3K
  • · Replies 24 ·
Replies
24
Views
3K
  • · Replies 1 ·
Replies
1
Views
1K
  • · Replies 14 ·
Replies
14
Views
4K
  • · Replies 2 ·
Replies
2
Views
2K
Replies
17
Views
3K
Replies
12
Views
5K