Linear regression with least squares for quadratic function

In summary: E = min || Ax - b || solution because the matrix is invertible, so there is only a single point that minimizes the norm of the error.If the matrix is not square or is singular, then the true least squares solution is not unique, and there is no way to find the minimum norm solution using Matlab's \ operator.But for the case where the matrix is not square, but it is still full rank (i.e. the number of rows equals the number of columns, but the rows are not all linearly independent), then the \ operator will still give you the minimum least squares solution, even though it isn't a minimum norm solution.If the matrix is rank deficient (i.e. the rows are not
  • #1
gfd43tg
Gold Member
950
50

Homework Statement


We want to determine the coefficients of a polynomial of the form:

##p(x)=c_{1}x^2 +c_{2}x+c_{3}##The polynomial ##p(x)## must satisfy the constraint ##p(1)=1##.

We would also like ##p(x)## to satisfy the following 4 constraints:

##p(−1)=5##

##p(0)=−1##

##p(2)=6##

##p(3)=12##However, this is not possible, since the system of equations is over-determined. Instead, we wish to minimize the error, ##E##, as shown below, using least squares.

##E = (p(-1)-5)^2 +(p(0)+1)^2 +(p(2)-6)^2 +(p(3)-12)^2##

part 1
Solve for ##c_{3}## in terms of ##c_{1}## and ##c_{2}## such that the constraint, ##p(1)=1##, holds. Which of the following expressions is ##c_{3}## equal to?

part 2
If you substitute the expression for ##c_{3}## into the polynomial, ##p(x)##, what is the new polynomial?

part 3
Put the new polynomial and the 4 constraints you would like to satisfy into the ##Az=b## form where ##x = \left[ \begin{array}{c} c_1 \\ c_2 \end{array} \right]## . Using Matlab find the least squares solution of this system of equations. What is the value for ##x##?

Homework Equations


The Attempt at a Solution


I am having a lot of difficulty parsing this problem. I don't really understand what to do. The equation must satisfy ##p(1) = 1## and we attempt to satisfy the following

##p(-1) = 5##
##p(0) = -1##
##p(2) = 6##
##p(3) = 12##

Since one of the equations must be satisfied, and the other ones are ''try our best to satisfy'', I don't know how to set up a least square to solve this. Do I not include the one that must be satisfied, or include all? How do I make it so that it guarantees that specific one to be satisfied, but the other ones don't have to be. Very confused about this. Even how to set up ## c_{3}## in terms of ##c_{1}## and ##c_{2}##.
##E =min \underset x \in \mathbb R] \hspace{0.05 in} \|\left[ \begin{array}{x} 1 & -1 & 1 \\ 0 & 0 & 1 \\ 4 & 2 & 1 \\ 9 & 3 & 1 \end{array} \right] \left[\begin{array}{c} c_{1} \\ c_{2} \\ c_{3} \end{array} \right] - \left[\begin{array}{y} 5 \\ -1 \\ 6 \\ 12 \end{array} \right]\|##

how do I get the x is an element of R to be under the min?? And taller || to show that it is the norm
 

Attachments

  • Quiz_ Linear regression as least squares_ quadratic functions of one variable.pdf
    87.1 KB · Views: 294
Last edited:
Physics news on Phys.org
  • #2
Maylis said:

Homework Statement


We want to determine the coefficients of a polynomial of the form:

##p(x)=c_{1}x^2 +c_{2}x+c_{3}##

The polynomial ##p(x)## must satisfy the constraint ##p(1)=1##.

We would also like ##p(x)## to satisfy the following 4 constraints:

##p(−1)=5##

##p(0)=−1##

##p(2)=6##

##p(3)=12##


However, this is not possible, since the system of equations is over-determined. Instead, we wish to minimize the error, ##E##, as shown below, using least squares.

##E = (p(-1)-5)^2 +(p(0)+1)^2 +(p(2)-6)^2 +(p(3)-12)^2] E=(p(−1)−5)2+(p(0)+1)2+(p(2)−6)2+(p(3)−12)2##
I take it there's a typo in the above line & it should read:
##E = (p(-1)-5)^2 +(p(0)+1)^2 +(p(2)-6)^2 +(p(3)-12)^2 \ .##​
part 1
Solve for ##c_{3}## in terms of ##c_{1}## and ##c_{2}## such that the constraint, ##p(1)=1##, holds. Which of the following expressions is ##c_{3}## equal to?

part 2
If you substitute the expression for ##c_{3}## into the polynomial, ##p(x)##, what is the new polynomial?

part 3
Put the new polynomial and the 4 constraints you would like to satisfy into the ##Az=b## form where ##x = \left[ \begin{array}{c} c_1 \\ c_2 \end{array} \right]## . Using Matlab find the least squares solution of this system of equations. What is the value for##x##?


Homework Equations





The Attempt at a Solution


I am having a lot of difficulty parsing this problem. I don't really understand what to do. The equation must satisfy ##p(1) = 1## and we attempt to satisfy the following

##p(-1) = 5##
##p(0) = -1##
##p(2) = 6##
##p(3) = 12##

Since one of the equations must be satisfied, and the other ones are ''try our best to satisfy'', I don't know how to set up a least square to solve this. Do I not include the one that must be satisfied, or include all? How do I make it so that it guarantees that specific one to be satisfied, but the other ones don't have to be. Very confused about this. Even how to set up ## c_{3}## in terms of ##c_{1}## and ##c_{2}##.
##E =min \underset x \in \mathbb R] \hspace{0.05 in} \|\left[ \begin{array}{x} 1 & -1 & 1 \\ 0 & 0 & 1 \\ 4 & 2 & 1 \\ 9 & 3 & 1 \end{array} \right] \left[\begin{array}{c} c_{1} \\ c_{2} \\ c_{3} \end{array} \right] - \left[\begin{array}{y} 5 \\ -1 \\ 6 \\ 12 \end{array} \right]\|##

how do I get the x is an element of R to be under the min?? And taller || to show that it is the norm
Have you answered parts 1 & 2?

They seem pretty straight forward.

What is p(1) ? Substitute 1 in for x in ##c_1x^2+c_2x+c_3\ .##
 
  • Like
Likes 1 person
  • #3
Okay, when I saw all that business about one having to be satisfied and the other not, it got me way confused. I now did part 1 and 2. It temporarily disoriented me until I saw your post about it being trivial.

I got my function into the form with the substitution

##p(x) = c_{1}(x^2-1) + c_{2}(x-1) + 1##

Here is part 3. The way I thought about it was that there should be an array in the form ##Ax = b##

Then I set it up, keeping in mind that I moved the 1 to the right hand side of the equation,
##\left [\begin{array}{x} x_{1}^2 -1 & x_{1}-1 \\ x_{2}^2 -1 & x_{2}-1 \\ x_{3}^2 -1 & x_{3}-1 \\ x_{4}^2 -1 & x_{4}-1 \end{array} \right] \left[\begin{array}{c} c_{1} \\ c_{2} \end{array} \right] = b - 1##
Code:
 A = [0 -2; -1 -1; 3 1; 8 2]
b = [5; -1; 6; 12];
x = A\(b-1);

I got it now, the wording totally disoriented me though so I didn't know what to do.
 
Last edited:
  • #4
What I don't get is how is this linear regression? All I did for this problem was what I did in the last module, least squares. With matlab, does it automatically calculate the least squares when I do A\b? Also, why was the equation for E never used??
 
Last edited:
  • #5
Maylis said:
With matlab, does it automatically calculate the least squares when I do A\b?

Yes, that's exactly what the \ operator does.

If A is a square nonsingular matrix, the "least squares" solution is the same as an "ordinary" equation solution, so you can also use the \ operator to solve problems that don't have anything to do with least squares.

If you want to minimize ##E = ||Ax - b||##, one way to do it is explicitly form the equations ##(A^TA)x = (A^Tb)## and solve them. If you solved least squares problems by hand, that's probably how you did it. Conceptually that is what the Matlab \ operator does, but it actually uses a different numerical method which is faster and avoids problems with rounding errors, etc.
 
  • Like
Likes 1 person
  • #6
Maylis said:
What I don't get is how is this linear regression? All I did for this problem was what I did in the last module, least squares. With matlab, does it automatically calculate the least squares when I do A\b? Also, why was the equation for E never used??

It's called linear because the expression you're fitting is linear in the parameters that you determine, in this case, the c1 and c2 .
 

What is linear regression with least squares for quadratic function?

Linear regression with least squares for quadratic function is a statistical method used to find the best fitting curve (quadratic function) for a given set of data points. It involves minimizing the sum of squared differences between the actual data points and the predicted values from the quadratic function.

What is the purpose of using least squares in linear regression?

The purpose of using least squares in linear regression is to find the line or curve that best fits the given data points. By minimizing the sum of squared differences between the actual data points and the predicted values, it helps to reduce the error and improve the accuracy of the regression model.

How is a quadratic function represented in linear regression with least squares?

In linear regression with least squares for quadratic function, a quadratic function is represented by the equation y = ax^2 + bx + c, where a, b, and c are the coefficients that are calculated using the least squares method.

What is the difference between linear and quadratic regression?

The main difference between linear and quadratic regression is the shape of the curve that is used to fit the data. In linear regression, a straight line is used, while in quadratic regression, a curve (specifically a parabola) is used to fit the data points.

How do you interpret the coefficients in a quadratic regression model?

The coefficient a represents the curvature of the parabola (positive value for upward-facing parabola and negative value for downward-facing parabola). The coefficient b represents the slope of the curve at the vertex, and the coefficient c represents the y-intercept of the curve. These coefficients help to determine the shape and position of the quadratic function, which in turn helps in understanding the relationship between the variables in the data set.

Similar threads

  • Calculus and Beyond Homework Help
Replies
21
Views
840
  • Calculus and Beyond Homework Help
Replies
6
Views
892
  • Calculus and Beyond Homework Help
Replies
1
Views
535
  • Calculus and Beyond Homework Help
Replies
2
Views
366
  • Calculus and Beyond Homework Help
Replies
5
Views
526
  • Calculus and Beyond Homework Help
Replies
5
Views
289
  • Calculus and Beyond Homework Help
Replies
24
Views
797
  • Calculus and Beyond Homework Help
Replies
6
Views
661
  • Advanced Physics Homework Help
2
Replies
36
Views
2K
  • Calculus and Beyond Homework Help
Replies
2
Views
92
Back
Top