Using the method of least squares in order to find the best approximation to a solution for the system

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite













Use the method of least squares in order to find the best approximation
to a solution for the system
$$3x + y = 1\
x − y = 2\
x + 3y = −1$$




My Try:
$$Ax=B$$
$$beginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrixbeginbmatrix x \ y endbmatrix=beginbmatrix 1 \ 2 \ -1 endbmatrix$$



First I found $A^TA$ and then $A^TB$



$$A^TA=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrix=beginbmatrix 3 & 3 \ 3 & 11 endbmatrix$$
and
$$A^TB=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 \ 2 \ -1 endbmatrix=beginbmatrix 2 \ -4 endbmatrix$$
The I used gaussian elimination for $beginbmatrix 3 & 3 & 2 \ 3 & 11 & -4 endbmatrix$ and got $x=dfrac1712,y=-dfrac34$.



Is this method of least squares correct?







share|cite|improve this question



















  • Your matrix $A$ does not match the system. I got $(frac23, frac-23)$. Your method seems fine though.
    – JJC94
    Jul 25 at 2:07














up vote
0
down vote

favorite













Use the method of least squares in order to find the best approximation
to a solution for the system
$$3x + y = 1\
x − y = 2\
x + 3y = −1$$




My Try:
$$Ax=B$$
$$beginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrixbeginbmatrix x \ y endbmatrix=beginbmatrix 1 \ 2 \ -1 endbmatrix$$



First I found $A^TA$ and then $A^TB$



$$A^TA=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrix=beginbmatrix 3 & 3 \ 3 & 11 endbmatrix$$
and
$$A^TB=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 \ 2 \ -1 endbmatrix=beginbmatrix 2 \ -4 endbmatrix$$
The I used gaussian elimination for $beginbmatrix 3 & 3 & 2 \ 3 & 11 & -4 endbmatrix$ and got $x=dfrac1712,y=-dfrac34$.



Is this method of least squares correct?







share|cite|improve this question



















  • Your matrix $A$ does not match the system. I got $(frac23, frac-23)$. Your method seems fine though.
    – JJC94
    Jul 25 at 2:07












up vote
0
down vote

favorite









up vote
0
down vote

favorite












Use the method of least squares in order to find the best approximation
to a solution for the system
$$3x + y = 1\
x − y = 2\
x + 3y = −1$$




My Try:
$$Ax=B$$
$$beginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrixbeginbmatrix x \ y endbmatrix=beginbmatrix 1 \ 2 \ -1 endbmatrix$$



First I found $A^TA$ and then $A^TB$



$$A^TA=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrix=beginbmatrix 3 & 3 \ 3 & 11 endbmatrix$$
and
$$A^TB=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 \ 2 \ -1 endbmatrix=beginbmatrix 2 \ -4 endbmatrix$$
The I used gaussian elimination for $beginbmatrix 3 & 3 & 2 \ 3 & 11 & -4 endbmatrix$ and got $x=dfrac1712,y=-dfrac34$.



Is this method of least squares correct?







share|cite|improve this question












Use the method of least squares in order to find the best approximation
to a solution for the system
$$3x + y = 1\
x − y = 2\
x + 3y = −1$$




My Try:
$$Ax=B$$
$$beginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrixbeginbmatrix x \ y endbmatrix=beginbmatrix 1 \ 2 \ -1 endbmatrix$$



First I found $A^TA$ and then $A^TB$



$$A^TA=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 & 1 \ 1 & -1 \ 1 & 3 endbmatrix=beginbmatrix 3 & 3 \ 3 & 11 endbmatrix$$
and
$$A^TB=beginbmatrix 1 & 1 & 1 \ 1 & -1 & 3 endbmatrixbeginbmatrix 1 \ 2 \ -1 endbmatrix=beginbmatrix 2 \ -4 endbmatrix$$
The I used gaussian elimination for $beginbmatrix 3 & 3 & 2 \ 3 & 11 & -4 endbmatrix$ and got $x=dfrac1712,y=-dfrac34$.



Is this method of least squares correct?









share|cite|improve this question










share|cite|improve this question




share|cite|improve this question









asked Jul 25 at 1:53









philip

1158




1158











  • Your matrix $A$ does not match the system. I got $(frac23, frac-23)$. Your method seems fine though.
    – JJC94
    Jul 25 at 2:07
















  • Your matrix $A$ does not match the system. I got $(frac23, frac-23)$. Your method seems fine though.
    – JJC94
    Jul 25 at 2:07















Your matrix $A$ does not match the system. I got $(frac23, frac-23)$. Your method seems fine though.
– JJC94
Jul 25 at 2:07




Your matrix $A$ does not match the system. I got $(frac23, frac-23)$. Your method seems fine though.
– JJC94
Jul 25 at 2:07










2 Answers
2






active

oldest

votes

















up vote
0
down vote



accepted










Yes, the method is correct. It is more common to write it as:
$$ x = (A^TA)^-1A^TB$$



Your calculations are right, except that you have a typo in the matrix $A$, as pointed out in the comments.






share|cite|improve this answer























  • To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
    – JJC94
    Jul 25 at 2:09










  • @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
    – philip
    Jul 25 at 2:12










  • @philip you have a mismatch between your system of equations and your matrix $A$.
    – pedroszattoni
    Jul 25 at 2:14










  • Can you please show where I was wrong
    – philip
    Jul 25 at 2:15










  • top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
    – pedroszattoni
    Jul 25 at 2:18

















up vote
0
down vote













Since you did not specify that matrix calculation was a requirement, admitting that you need to solve $n$ linear equations written as
$$a_ix+b_iy=c_i qquad qquad (i=1,2,cdots,n)$$ with $n>2$, by analogy with least squares method, you could simply minimize with respect to $(x,y)$ the norm
$$Phi=frac 12sum_i=1^n(a_ix+b_iy-c_i)^2$$ Computing the partial derivatives
$$fracpartial Phipartial x=sum_i=1^na_i(a_ix+b_iy-c_i)$$
$$fracpartial Phipartial y=sum_i=1^nb_i(a_ix+b_iy-c_i)$$ Setting them equal to $0$, you then end with two linear equations in $(x,y)$, namely
$$x sum_i=1^n a_i^2+y sum_i=1^n a_ib_i=sum_i=1^n a_ic_i$$
$$x sum_i=1^n a_ib_i+y sum_i=1^n b_i^2=sum_i=1^n b_ic_i$$






share|cite|improve this answer





















    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["$", "$"], ["\\(","\\)"]]);
    );
    );
    , "mathjax-editing");

    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "69"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    convertImagesToLinks: true,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: 10,
    bindNavPrevention: true,
    postfix: "",
    noCode: true, onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );








     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2861949%2fusing-the-method-of-least-squares-in-order-to-find-the-best-approximation-to-a-s%23new-answer', 'question_page');

    );

    Post as a guest






























    2 Answers
    2






    active

    oldest

    votes








    2 Answers
    2






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    0
    down vote



    accepted










    Yes, the method is correct. It is more common to write it as:
    $$ x = (A^TA)^-1A^TB$$



    Your calculations are right, except that you have a typo in the matrix $A$, as pointed out in the comments.






    share|cite|improve this answer























    • To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
      – JJC94
      Jul 25 at 2:09










    • @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
      – philip
      Jul 25 at 2:12










    • @philip you have a mismatch between your system of equations and your matrix $A$.
      – pedroszattoni
      Jul 25 at 2:14










    • Can you please show where I was wrong
      – philip
      Jul 25 at 2:15










    • top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
      – pedroszattoni
      Jul 25 at 2:18














    up vote
    0
    down vote



    accepted










    Yes, the method is correct. It is more common to write it as:
    $$ x = (A^TA)^-1A^TB$$



    Your calculations are right, except that you have a typo in the matrix $A$, as pointed out in the comments.






    share|cite|improve this answer























    • To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
      – JJC94
      Jul 25 at 2:09










    • @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
      – philip
      Jul 25 at 2:12










    • @philip you have a mismatch between your system of equations and your matrix $A$.
      – pedroszattoni
      Jul 25 at 2:14










    • Can you please show where I was wrong
      – philip
      Jul 25 at 2:15










    • top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
      – pedroszattoni
      Jul 25 at 2:18












    up vote
    0
    down vote



    accepted







    up vote
    0
    down vote



    accepted






    Yes, the method is correct. It is more common to write it as:
    $$ x = (A^TA)^-1A^TB$$



    Your calculations are right, except that you have a typo in the matrix $A$, as pointed out in the comments.






    share|cite|improve this answer















    Yes, the method is correct. It is more common to write it as:
    $$ x = (A^TA)^-1A^TB$$



    Your calculations are right, except that you have a typo in the matrix $A$, as pointed out in the comments.







    share|cite|improve this answer















    share|cite|improve this answer



    share|cite|improve this answer








    edited Jul 25 at 2:08


























    answered Jul 25 at 2:01









    pedroszattoni

    14819




    14819











    • To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
      – JJC94
      Jul 25 at 2:09










    • @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
      – philip
      Jul 25 at 2:12










    • @philip you have a mismatch between your system of equations and your matrix $A$.
      – pedroszattoni
      Jul 25 at 2:14










    • Can you please show where I was wrong
      – philip
      Jul 25 at 2:15










    • top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
      – pedroszattoni
      Jul 25 at 2:18
















    • To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
      – JJC94
      Jul 25 at 2:09










    • @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
      – philip
      Jul 25 at 2:12










    • @philip you have a mismatch between your system of equations and your matrix $A$.
      – pedroszattoni
      Jul 25 at 2:14










    • Can you please show where I was wrong
      – philip
      Jul 25 at 2:15










    • top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
      – pedroszattoni
      Jul 25 at 2:18















    To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
    – JJC94
    Jul 25 at 2:09




    To be fair, for large matrices, computing the inverse is too expensive, and row reduction is preferable.
    – JJC94
    Jul 25 at 2:09












    @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
    – philip
    Jul 25 at 2:12




    @pedroszattoni when I calculated $(A^TA)^-1A^TB$ I got the matrix as $beginbmatrix frac 17 12 \ frac -3 4 endbmatrix$
    – philip
    Jul 25 at 2:12












    @philip you have a mismatch between your system of equations and your matrix $A$.
    – pedroszattoni
    Jul 25 at 2:14




    @philip you have a mismatch between your system of equations and your matrix $A$.
    – pedroszattoni
    Jul 25 at 2:14












    Can you please show where I was wrong
    – philip
    Jul 25 at 2:15




    Can you please show where I was wrong
    – philip
    Jul 25 at 2:15












    top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
    – pedroszattoni
    Jul 25 at 2:18




    top left entry of matrix $A$ is 1, whereas it should be 3 if you follow the equations of the linear system
    – pedroszattoni
    Jul 25 at 2:18










    up vote
    0
    down vote













    Since you did not specify that matrix calculation was a requirement, admitting that you need to solve $n$ linear equations written as
    $$a_ix+b_iy=c_i qquad qquad (i=1,2,cdots,n)$$ with $n>2$, by analogy with least squares method, you could simply minimize with respect to $(x,y)$ the norm
    $$Phi=frac 12sum_i=1^n(a_ix+b_iy-c_i)^2$$ Computing the partial derivatives
    $$fracpartial Phipartial x=sum_i=1^na_i(a_ix+b_iy-c_i)$$
    $$fracpartial Phipartial y=sum_i=1^nb_i(a_ix+b_iy-c_i)$$ Setting them equal to $0$, you then end with two linear equations in $(x,y)$, namely
    $$x sum_i=1^n a_i^2+y sum_i=1^n a_ib_i=sum_i=1^n a_ic_i$$
    $$x sum_i=1^n a_ib_i+y sum_i=1^n b_i^2=sum_i=1^n b_ic_i$$






    share|cite|improve this answer

























      up vote
      0
      down vote













      Since you did not specify that matrix calculation was a requirement, admitting that you need to solve $n$ linear equations written as
      $$a_ix+b_iy=c_i qquad qquad (i=1,2,cdots,n)$$ with $n>2$, by analogy with least squares method, you could simply minimize with respect to $(x,y)$ the norm
      $$Phi=frac 12sum_i=1^n(a_ix+b_iy-c_i)^2$$ Computing the partial derivatives
      $$fracpartial Phipartial x=sum_i=1^na_i(a_ix+b_iy-c_i)$$
      $$fracpartial Phipartial y=sum_i=1^nb_i(a_ix+b_iy-c_i)$$ Setting them equal to $0$, you then end with two linear equations in $(x,y)$, namely
      $$x sum_i=1^n a_i^2+y sum_i=1^n a_ib_i=sum_i=1^n a_ic_i$$
      $$x sum_i=1^n a_ib_i+y sum_i=1^n b_i^2=sum_i=1^n b_ic_i$$






      share|cite|improve this answer























        up vote
        0
        down vote










        up vote
        0
        down vote









        Since you did not specify that matrix calculation was a requirement, admitting that you need to solve $n$ linear equations written as
        $$a_ix+b_iy=c_i qquad qquad (i=1,2,cdots,n)$$ with $n>2$, by analogy with least squares method, you could simply minimize with respect to $(x,y)$ the norm
        $$Phi=frac 12sum_i=1^n(a_ix+b_iy-c_i)^2$$ Computing the partial derivatives
        $$fracpartial Phipartial x=sum_i=1^na_i(a_ix+b_iy-c_i)$$
        $$fracpartial Phipartial y=sum_i=1^nb_i(a_ix+b_iy-c_i)$$ Setting them equal to $0$, you then end with two linear equations in $(x,y)$, namely
        $$x sum_i=1^n a_i^2+y sum_i=1^n a_ib_i=sum_i=1^n a_ic_i$$
        $$x sum_i=1^n a_ib_i+y sum_i=1^n b_i^2=sum_i=1^n b_ic_i$$






        share|cite|improve this answer













        Since you did not specify that matrix calculation was a requirement, admitting that you need to solve $n$ linear equations written as
        $$a_ix+b_iy=c_i qquad qquad (i=1,2,cdots,n)$$ with $n>2$, by analogy with least squares method, you could simply minimize with respect to $(x,y)$ the norm
        $$Phi=frac 12sum_i=1^n(a_ix+b_iy-c_i)^2$$ Computing the partial derivatives
        $$fracpartial Phipartial x=sum_i=1^na_i(a_ix+b_iy-c_i)$$
        $$fracpartial Phipartial y=sum_i=1^nb_i(a_ix+b_iy-c_i)$$ Setting them equal to $0$, you then end with two linear equations in $(x,y)$, namely
        $$x sum_i=1^n a_i^2+y sum_i=1^n a_ib_i=sum_i=1^n a_ic_i$$
        $$x sum_i=1^n a_ib_i+y sum_i=1^n b_i^2=sum_i=1^n b_ic_i$$







        share|cite|improve this answer













        share|cite|improve this answer



        share|cite|improve this answer











        answered Jul 25 at 4:44









        Claude Leibovici

        111k1055126




        111k1055126






















             

            draft saved


            draft discarded


























             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f2861949%2fusing-the-method-of-least-squares-in-order-to-find-the-best-approximation-to-a-s%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What is the equation of a 3D cone with generalised tilt?

            Color the edges and diagonals of a regular polygon

            Relationship between determinant of matrix and determinant of adjoint?