Linear Program to find line that best fits a set of points











up vote
0
down vote

favorite












Given a set of points $(x1,y1),(x2,y2),...,(xn,yn)$ the following is supposed to be a linear program that finds a line$ $ax+by=c that minimizes $max|ax_i+by_i-c|$.



Let $z=max|ax_i+by_i-c|$

This implies $zge|ax_i+by_i-c|$

or $-zle ax_i+by_i-cle z$



The LP is:

Maximize : -z

subject to:

1) $-z-ax_i-by_i+c le 0$

2) $-z+ax_i+by_i-c le 0$

3) $z,a,b,c ge 0$



I don't understand why this is correct since:



1) the coefficient of z in the objective function is negative which would mean the max value is achieved at $z=0$

2) $a,b,c ge 0$. Rewriting the line as $y=-frac{a}{b}x+c$
we see that this means that we are restricting ourselves to lines of -ve slope.
So, this can't be right either.



I'm looking on clarification on what I'm missing?










share|cite|improve this question




























    up vote
    0
    down vote

    favorite












    Given a set of points $(x1,y1),(x2,y2),...,(xn,yn)$ the following is supposed to be a linear program that finds a line$ $ax+by=c that minimizes $max|ax_i+by_i-c|$.



    Let $z=max|ax_i+by_i-c|$

    This implies $zge|ax_i+by_i-c|$

    or $-zle ax_i+by_i-cle z$



    The LP is:

    Maximize : -z

    subject to:

    1) $-z-ax_i-by_i+c le 0$

    2) $-z+ax_i+by_i-c le 0$

    3) $z,a,b,c ge 0$



    I don't understand why this is correct since:



    1) the coefficient of z in the objective function is negative which would mean the max value is achieved at $z=0$

    2) $a,b,c ge 0$. Rewriting the line as $y=-frac{a}{b}x+c$
    we see that this means that we are restricting ourselves to lines of -ve slope.
    So, this can't be right either.



    I'm looking on clarification on what I'm missing?










    share|cite|improve this question


























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      Given a set of points $(x1,y1),(x2,y2),...,(xn,yn)$ the following is supposed to be a linear program that finds a line$ $ax+by=c that minimizes $max|ax_i+by_i-c|$.



      Let $z=max|ax_i+by_i-c|$

      This implies $zge|ax_i+by_i-c|$

      or $-zle ax_i+by_i-cle z$



      The LP is:

      Maximize : -z

      subject to:

      1) $-z-ax_i-by_i+c le 0$

      2) $-z+ax_i+by_i-c le 0$

      3) $z,a,b,c ge 0$



      I don't understand why this is correct since:



      1) the coefficient of z in the objective function is negative which would mean the max value is achieved at $z=0$

      2) $a,b,c ge 0$. Rewriting the line as $y=-frac{a}{b}x+c$
      we see that this means that we are restricting ourselves to lines of -ve slope.
      So, this can't be right either.



      I'm looking on clarification on what I'm missing?










      share|cite|improve this question















      Given a set of points $(x1,y1),(x2,y2),...,(xn,yn)$ the following is supposed to be a linear program that finds a line$ $ax+by=c that minimizes $max|ax_i+by_i-c|$.



      Let $z=max|ax_i+by_i-c|$

      This implies $zge|ax_i+by_i-c|$

      or $-zle ax_i+by_i-cle z$



      The LP is:

      Maximize : -z

      subject to:

      1) $-z-ax_i-by_i+c le 0$

      2) $-z+ax_i+by_i-c le 0$

      3) $z,a,b,c ge 0$



      I don't understand why this is correct since:



      1) the coefficient of z in the objective function is negative which would mean the max value is achieved at $z=0$

      2) $a,b,c ge 0$. Rewriting the line as $y=-frac{a}{b}x+c$
      we see that this means that we are restricting ourselves to lines of -ve slope.
      So, this can't be right either.



      I'm looking on clarification on what I'm missing?







      linear-programming






      share|cite|improve this question















      share|cite|improve this question













      share|cite|improve this question




      share|cite|improve this question








      edited Nov 17 at 19:57

























      asked Nov 16 at 22:55









      user137481

      1,7582920




      1,7582920






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          1) $z=0$ is a perfect match, so indeed that is optimal.



          2) the part $z,a,b,c=0$ is obviously wrong. You should not constrain these variables (although you could add $zgeq 0$ without changing the formulation), and constraint $b=1$ as a normalization.






          share|cite|improve this answer























          • Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
            – user137481
            Nov 17 at 3:10










          • As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
            – user137481
            Nov 17 at 3:25










          • @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
            – LinAlg
            Nov 17 at 17:52










          • If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
            – user137481
            Nov 17 at 20:01










          • @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
            – LinAlg
            Nov 17 at 20:11


















          up vote
          1
          down vote













          Consider the problem of $$max -z$$



          where $$-z+1 le 0$$
          $$-z-1 le 0$$
          $$z ge 0$$



          Having the coefficient of $z$ being negative in your constraint doesn't mean that $z=0$. In fact $z=0$ is not feasible for the first costraint. My constraints sets is actually equivalent to $z ge 1$.



          Also, there is no sign constraint on $a,b,c$.






          share|cite|improve this answer





















          • You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
            – user137481
            Nov 17 at 20:06











          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: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          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%2f3001736%2flinear-program-to-find-line-that-best-fits-a-set-of-points%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          1
          down vote



          accepted










          1) $z=0$ is a perfect match, so indeed that is optimal.



          2) the part $z,a,b,c=0$ is obviously wrong. You should not constrain these variables (although you could add $zgeq 0$ without changing the formulation), and constraint $b=1$ as a normalization.






          share|cite|improve this answer























          • Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
            – user137481
            Nov 17 at 3:10










          • As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
            – user137481
            Nov 17 at 3:25










          • @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
            – LinAlg
            Nov 17 at 17:52










          • If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
            – user137481
            Nov 17 at 20:01










          • @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
            – LinAlg
            Nov 17 at 20:11















          up vote
          1
          down vote



          accepted










          1) $z=0$ is a perfect match, so indeed that is optimal.



          2) the part $z,a,b,c=0$ is obviously wrong. You should not constrain these variables (although you could add $zgeq 0$ without changing the formulation), and constraint $b=1$ as a normalization.






          share|cite|improve this answer























          • Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
            – user137481
            Nov 17 at 3:10










          • As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
            – user137481
            Nov 17 at 3:25










          • @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
            – LinAlg
            Nov 17 at 17:52










          • If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
            – user137481
            Nov 17 at 20:01










          • @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
            – LinAlg
            Nov 17 at 20:11













          up vote
          1
          down vote



          accepted







          up vote
          1
          down vote



          accepted






          1) $z=0$ is a perfect match, so indeed that is optimal.



          2) the part $z,a,b,c=0$ is obviously wrong. You should not constrain these variables (although you could add $zgeq 0$ without changing the formulation), and constraint $b=1$ as a normalization.






          share|cite|improve this answer














          1) $z=0$ is a perfect match, so indeed that is optimal.



          2) the part $z,a,b,c=0$ is obviously wrong. You should not constrain these variables (although you could add $zgeq 0$ without changing the formulation), and constraint $b=1$ as a normalization.







          share|cite|improve this answer














          share|cite|improve this answer



          share|cite|improve this answer








          edited Nov 17 at 20:11

























          answered Nov 17 at 1:52









          LinAlg

          7,6141520




          7,6141520












          • Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
            – user137481
            Nov 17 at 3:10










          • As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
            – user137481
            Nov 17 at 3:25










          • @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
            – LinAlg
            Nov 17 at 17:52










          • If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
            – user137481
            Nov 17 at 20:01










          • @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
            – LinAlg
            Nov 17 at 20:11


















          • Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
            – user137481
            Nov 17 at 3:10










          • As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
            – user137481
            Nov 17 at 3:25










          • @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
            – LinAlg
            Nov 17 at 17:52










          • If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
            – user137481
            Nov 17 at 20:01










          • @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
            – LinAlg
            Nov 17 at 20:11
















          Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
          – user137481
          Nov 17 at 3:10




          Apologies, I made a typo. I meant $z, a, b, c ge 0$. But, $a, b ge 0$ means that we are restricting our solution to lines with -ve slope. That does not sound right.
          – user137481
          Nov 17 at 3:10












          As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
          – user137481
          Nov 17 at 3:25




          As well, given that $z=0$ is already optimal, the LP will simply terminate. In that case, what are the values of $a$ and $b$ that result in $z = 0$?
          – user137481
          Nov 17 at 3:25












          @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
          – LinAlg
          Nov 17 at 17:52




          @user137481 $z=0$ is probably infeasible, unless you can find a matching pair $(a,b)$.
          – LinAlg
          Nov 17 at 17:52












          If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
          – user137481
          Nov 17 at 20:01




          If I understand you correctly, there should be no non-negativity constraints on $a$ and $c$. However, since the line we are looking for is $ax+by=c$, $b$ must be strictly greater than zero. Could you tell me how we express such a constraint? Thanks.
          – user137481
          Nov 17 at 20:01












          @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
          – LinAlg
          Nov 17 at 20:11




          @user137481 you cannot have strict inequalities in linear optimization, but you can set $b=1$, since $a$ and $c$ can simply rescale. That also avoids all coefficients from becoming close to $0$ (which in turn reduces $z$).
          – LinAlg
          Nov 17 at 20:11










          up vote
          1
          down vote













          Consider the problem of $$max -z$$



          where $$-z+1 le 0$$
          $$-z-1 le 0$$
          $$z ge 0$$



          Having the coefficient of $z$ being negative in your constraint doesn't mean that $z=0$. In fact $z=0$ is not feasible for the first costraint. My constraints sets is actually equivalent to $z ge 1$.



          Also, there is no sign constraint on $a,b,c$.






          share|cite|improve this answer





















          • You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
            – user137481
            Nov 17 at 20:06















          up vote
          1
          down vote













          Consider the problem of $$max -z$$



          where $$-z+1 le 0$$
          $$-z-1 le 0$$
          $$z ge 0$$



          Having the coefficient of $z$ being negative in your constraint doesn't mean that $z=0$. In fact $z=0$ is not feasible for the first costraint. My constraints sets is actually equivalent to $z ge 1$.



          Also, there is no sign constraint on $a,b,c$.






          share|cite|improve this answer





















          • You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
            – user137481
            Nov 17 at 20:06













          up vote
          1
          down vote










          up vote
          1
          down vote









          Consider the problem of $$max -z$$



          where $$-z+1 le 0$$
          $$-z-1 le 0$$
          $$z ge 0$$



          Having the coefficient of $z$ being negative in your constraint doesn't mean that $z=0$. In fact $z=0$ is not feasible for the first costraint. My constraints sets is actually equivalent to $z ge 1$.



          Also, there is no sign constraint on $a,b,c$.






          share|cite|improve this answer












          Consider the problem of $$max -z$$



          where $$-z+1 le 0$$
          $$-z-1 le 0$$
          $$z ge 0$$



          Having the coefficient of $z$ being negative in your constraint doesn't mean that $z=0$. In fact $z=0$ is not feasible for the first costraint. My constraints sets is actually equivalent to $z ge 1$.



          Also, there is no sign constraint on $a,b,c$.







          share|cite|improve this answer












          share|cite|improve this answer



          share|cite|improve this answer










          answered Nov 17 at 3:48









          Siong Thye Goh

          93.1k1462114




          93.1k1462114












          • You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
            – user137481
            Nov 17 at 20:06


















          • You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
            – user137481
            Nov 17 at 20:06
















          You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
          – user137481
          Nov 17 at 20:06




          You're right. There should be no sign constraints (i.e. non-negativity constraints) on $a$, $b$ or $c$. However, given that the equation of the line is $ax+by=c$ this means we cannot have $b=0$. Could you tell me how you express such a constraint?
          – user137481
          Nov 17 at 20:06


















           

          draft saved


          draft discarded



















































           


          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmath.stackexchange.com%2fquestions%2f3001736%2flinear-program-to-find-line-that-best-fits-a-set-of-points%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Willebadessen

          Ida-Boy-Ed-Garten

          Residenzschloss Arolsen