N[…, 5] does not returns what I expected












2












$begingroup$


I have this



Xt = 
{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1.5, 1.5,1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3, 3.2, 3.3}};
Yt =
{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8, 133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};

N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]


and the last evaluation returns the same result as if there was no N[..,..]; i.e.,




{93.3422, 15.6485}




Why and how do I get output to five decimals?










share|improve this question











$endgroup$












  • $begingroup$
    Welcome to Mathematica SE! Generally we try to only use the "bugs" tag once other users have verified that a function is not working the way the documentation suggests it should.
    $endgroup$
    – MassDefect
    Feb 9 at 7:31










  • $begingroup$
    well no one told me about it.. I'll edit :).
    $endgroup$
    – user62732
    Feb 9 at 7:34






  • 2




    $begingroup$
    It's no problem! I just thought I'd leave a comment for future reference. I had no idea that's how it worked when I first started here either!
    $endgroup$
    – MassDefect
    Feb 9 at 7:48










  • $begingroup$
    One thing every Mathematica user must learn is that the 2nd argument of N has no effect on machine precision numbers, which are the kind of numbers you are using.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:07






  • 2




    $begingroup$
    I think you might find reading this answer helps your understanding of N, which is a more sophisticated function than most beginners think it is.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:21
















2












$begingroup$


I have this



Xt = 
{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1.5, 1.5,1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3, 3.2, 3.3}};
Yt =
{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8, 133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};

N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]


and the last evaluation returns the same result as if there was no N[..,..]; i.e.,




{93.3422, 15.6485}




Why and how do I get output to five decimals?










share|improve this question











$endgroup$












  • $begingroup$
    Welcome to Mathematica SE! Generally we try to only use the "bugs" tag once other users have verified that a function is not working the way the documentation suggests it should.
    $endgroup$
    – MassDefect
    Feb 9 at 7:31










  • $begingroup$
    well no one told me about it.. I'll edit :).
    $endgroup$
    – user62732
    Feb 9 at 7:34






  • 2




    $begingroup$
    It's no problem! I just thought I'd leave a comment for future reference. I had no idea that's how it worked when I first started here either!
    $endgroup$
    – MassDefect
    Feb 9 at 7:48










  • $begingroup$
    One thing every Mathematica user must learn is that the 2nd argument of N has no effect on machine precision numbers, which are the kind of numbers you are using.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:07






  • 2




    $begingroup$
    I think you might find reading this answer helps your understanding of N, which is a more sophisticated function than most beginners think it is.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:21














2












2








2





$begingroup$


I have this



Xt = 
{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1.5, 1.5,1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3, 3.2, 3.3}};
Yt =
{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8, 133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};

N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]


and the last evaluation returns the same result as if there was no N[..,..]; i.e.,




{93.3422, 15.6485}




Why and how do I get output to five decimals?










share|improve this question











$endgroup$




I have this



Xt = 
{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
{1, 1.5, 1.5,1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3, 3.2, 3.3}};
Yt =
{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8, 133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};

N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]


and the last evaluation returns the same result as if there was no N[..,..]; i.e.,




{93.3422, 15.6485}




Why and how do I get output to five decimals?







numerics output-formatting numerical-value






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Feb 9 at 9:03









m_goldberg

88.1k872199




88.1k872199










asked Feb 9 at 6:54









user62732user62732

1226




1226












  • $begingroup$
    Welcome to Mathematica SE! Generally we try to only use the "bugs" tag once other users have verified that a function is not working the way the documentation suggests it should.
    $endgroup$
    – MassDefect
    Feb 9 at 7:31










  • $begingroup$
    well no one told me about it.. I'll edit :).
    $endgroup$
    – user62732
    Feb 9 at 7:34






  • 2




    $begingroup$
    It's no problem! I just thought I'd leave a comment for future reference. I had no idea that's how it worked when I first started here either!
    $endgroup$
    – MassDefect
    Feb 9 at 7:48










  • $begingroup$
    One thing every Mathematica user must learn is that the 2nd argument of N has no effect on machine precision numbers, which are the kind of numbers you are using.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:07






  • 2




    $begingroup$
    I think you might find reading this answer helps your understanding of N, which is a more sophisticated function than most beginners think it is.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:21


















  • $begingroup$
    Welcome to Mathematica SE! Generally we try to only use the "bugs" tag once other users have verified that a function is not working the way the documentation suggests it should.
    $endgroup$
    – MassDefect
    Feb 9 at 7:31










  • $begingroup$
    well no one told me about it.. I'll edit :).
    $endgroup$
    – user62732
    Feb 9 at 7:34






  • 2




    $begingroup$
    It's no problem! I just thought I'd leave a comment for future reference. I had no idea that's how it worked when I first started here either!
    $endgroup$
    – MassDefect
    Feb 9 at 7:48










  • $begingroup$
    One thing every Mathematica user must learn is that the 2nd argument of N has no effect on machine precision numbers, which are the kind of numbers you are using.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:07






  • 2




    $begingroup$
    I think you might find reading this answer helps your understanding of N, which is a more sophisticated function than most beginners think it is.
    $endgroup$
    – m_goldberg
    Feb 9 at 9:21
















$begingroup$
Welcome to Mathematica SE! Generally we try to only use the "bugs" tag once other users have verified that a function is not working the way the documentation suggests it should.
$endgroup$
– MassDefect
Feb 9 at 7:31




$begingroup$
Welcome to Mathematica SE! Generally we try to only use the "bugs" tag once other users have verified that a function is not working the way the documentation suggests it should.
$endgroup$
– MassDefect
Feb 9 at 7:31












$begingroup$
well no one told me about it.. I'll edit :).
$endgroup$
– user62732
Feb 9 at 7:34




$begingroup$
well no one told me about it.. I'll edit :).
$endgroup$
– user62732
Feb 9 at 7:34




2




2




$begingroup$
It's no problem! I just thought I'd leave a comment for future reference. I had no idea that's how it worked when I first started here either!
$endgroup$
– MassDefect
Feb 9 at 7:48




$begingroup$
It's no problem! I just thought I'd leave a comment for future reference. I had no idea that's how it worked when I first started here either!
$endgroup$
– MassDefect
Feb 9 at 7:48












$begingroup$
One thing every Mathematica user must learn is that the 2nd argument of N has no effect on machine precision numbers, which are the kind of numbers you are using.
$endgroup$
– m_goldberg
Feb 9 at 9:07




$begingroup$
One thing every Mathematica user must learn is that the 2nd argument of N has no effect on machine precision numbers, which are the kind of numbers you are using.
$endgroup$
– m_goldberg
Feb 9 at 9:07




2




2




$begingroup$
I think you might find reading this answer helps your understanding of N, which is a more sophisticated function than most beginners think it is.
$endgroup$
– m_goldberg
Feb 9 at 9:21




$begingroup$
I think you might find reading this answer helps your understanding of N, which is a more sophisticated function than most beginners think it is.
$endgroup$
– m_goldberg
Feb 9 at 9:21










3 Answers
3






active

oldest

votes


















6












$begingroup$

Here is one solution.



Xt = Rationalize@{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
1}, {1, 1.5, 1.5, 1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3,
3.2, 3.3}};
Yt = Rationalize@{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8,
133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};
Inverse[Xt.Transpose[Xt]].Xt.Yt



$left{frac{892351}{9560},frac{3740}{239}right}$




N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



{93.342, 15.649}




N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 10]



{93.34215481, 15.64853556}







share|improve this answer









$endgroup$





















    8












    $begingroup$

    The documentation for N says that N[expr, n] attempts to give a result with n-digit precision. In the Wolfram Language, or any language, precision is not the same as decimal places. While it might seem like N is there to give us results with a certain number of decimal places, it actually has more to do with the amount of precision used in calculations behind the scenes. It can be especially confusing as sometimes N does close to what we expect as in N[Pi, 10] which gives us $pi$ with 10 digits (9 decimal places).



    There is a different function called NumberForm that is designed to let us have more control over the display of numbers.



    We can use:



    NumberForm[Inverse[Xt.Transpose[Xt].Xt.Yt, {20, 5}]


    yields




    {93.34215, 15.64854}




    The first number in NumberForm (i.e. 20) is the total number of digits. We can set this to Infinity and it won't make a difference, but it shouldn't be less than the total number of digits you want to display. The second number (i.e. 5) is the number of decimal places.






    share|improve this answer









    $endgroup$





















      4












      $begingroup$

      According to this tutorial:




      MachinePrecision is considered less precise than any other precision. This is because, while machine-precision numbers always store slightly under 16 digits, no specific number of those digits are known to be correct.




      We're working with MachinePrecision, i.e.



      Precision[Inverse[Xt.Transpose[Xt]].Xt.Yt]



      MachinePrecision



      and so N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5] needs to somehow upsample the precision of the result and that is an ill-defined operation.



      In fact the ref page for N states




      Unless numbers in expr are exact, or of sufficiently high precision, N[expr, n] may not be able to give results with n-digit precision.




      To see why this is ill-defined, consider the reverse. Let's go from higher precision to lower precision.



      x1 = N[Pi, 10]



      $3.1415926{color{red}5}4$




      x2 = N[Pi + 10^-8, 10]



      $3.1415926{color{red}6}4$




      N[{x1, x2}, 5]



      {3.1416, 3.1416}




      So we see if we reverse this example, going from precision 5 to precision 10 is ambiguous in the choices of the 6th - 10th digits.





      If you'd like to upsample in a consistent way, use SetPrecision:




      When SetPrecision is used to increase the precision of a number, the number is padded with zeros. The zeros are taken to be in base 2. In base 10, the additional digits are usually not zeros.




      SetPrecision[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



      {93.342, 15.649}



      If you only care about the display of the answer, consider using NumberForm:



      NumberForm[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



      {93.342, 15.649}






      share|improve this answer









      $endgroup$














        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: "387"
        };
        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',
        autoActivateHeartbeat: false,
        convertImagesToLinks: false,
        noModals: true,
        showLowRepImageUploadWarning: true,
        reputationToPostImages: null,
        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
        },
        onDemand: true,
        discardSelector: ".discard-answer"
        ,immediatelyShowMarkdownHelp:true
        });


        }
        });














        draft saved

        draft discarded


















        StackExchange.ready(
        function () {
        StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191178%2fn-5-does-not-returns-what-i-expected%23new-answer', 'question_page');
        }
        );

        Post as a guest















        Required, but never shown

























        3 Answers
        3






        active

        oldest

        votes








        3 Answers
        3






        active

        oldest

        votes









        active

        oldest

        votes






        active

        oldest

        votes









        6












        $begingroup$

        Here is one solution.



        Xt = Rationalize@{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
        1}, {1, 1.5, 1.5, 1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3,
        3.2, 3.3}};
        Yt = Rationalize@{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8,
        133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};
        Inverse[Xt.Transpose[Xt]].Xt.Yt



        $left{frac{892351}{9560},frac{3740}{239}right}$




        N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



        {93.342, 15.649}




        N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 10]



        {93.34215481, 15.64853556}







        share|improve this answer









        $endgroup$


















          6












          $begingroup$

          Here is one solution.



          Xt = Rationalize@{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
          1}, {1, 1.5, 1.5, 1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3,
          3.2, 3.3}};
          Yt = Rationalize@{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8,
          133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};
          Inverse[Xt.Transpose[Xt]].Xt.Yt



          $left{frac{892351}{9560},frac{3740}{239}right}$




          N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



          {93.342, 15.649}




          N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 10]



          {93.34215481, 15.64853556}







          share|improve this answer









          $endgroup$
















            6












            6








            6





            $begingroup$

            Here is one solution.



            Xt = Rationalize@{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
            1}, {1, 1.5, 1.5, 1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3,
            3.2, 3.3}};
            Yt = Rationalize@{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8,
            133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};
            Inverse[Xt.Transpose[Xt]].Xt.Yt



            $left{frac{892351}{9560},frac{3740}{239}right}$




            N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



            {93.342, 15.649}




            N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 10]



            {93.34215481, 15.64853556}







            share|improve this answer









            $endgroup$



            Here is one solution.



            Xt = Rationalize@{{1., 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 
            1}, {1, 1.5, 1.5, 1.5, 2, 2, 2.2, 2.4, 2.5, 2.5, 2.8, 2.8, 3, 3,
            3.2, 3.3}};
            Yt = Rationalize@{101.4, 117.4, 117.1, 106.2, 131.9, 146.9, 146.8,
            133.9, 111.3, 123, 125.1, 145.2, 134.3, 144.5, 143.7, 146.9};
            Inverse[Xt.Transpose[Xt]].Xt.Yt



            $left{frac{892351}{9560},frac{3740}{239}right}$




            N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



            {93.342, 15.649}




            N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 10]



            {93.34215481, 15.64853556}








            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Feb 9 at 7:10









            Okkes DulgerciOkkes Dulgerci

            5,4241919




            5,4241919























                8












                $begingroup$

                The documentation for N says that N[expr, n] attempts to give a result with n-digit precision. In the Wolfram Language, or any language, precision is not the same as decimal places. While it might seem like N is there to give us results with a certain number of decimal places, it actually has more to do with the amount of precision used in calculations behind the scenes. It can be especially confusing as sometimes N does close to what we expect as in N[Pi, 10] which gives us $pi$ with 10 digits (9 decimal places).



                There is a different function called NumberForm that is designed to let us have more control over the display of numbers.



                We can use:



                NumberForm[Inverse[Xt.Transpose[Xt].Xt.Yt, {20, 5}]


                yields




                {93.34215, 15.64854}




                The first number in NumberForm (i.e. 20) is the total number of digits. We can set this to Infinity and it won't make a difference, but it shouldn't be less than the total number of digits you want to display. The second number (i.e. 5) is the number of decimal places.






                share|improve this answer









                $endgroup$


















                  8












                  $begingroup$

                  The documentation for N says that N[expr, n] attempts to give a result with n-digit precision. In the Wolfram Language, or any language, precision is not the same as decimal places. While it might seem like N is there to give us results with a certain number of decimal places, it actually has more to do with the amount of precision used in calculations behind the scenes. It can be especially confusing as sometimes N does close to what we expect as in N[Pi, 10] which gives us $pi$ with 10 digits (9 decimal places).



                  There is a different function called NumberForm that is designed to let us have more control over the display of numbers.



                  We can use:



                  NumberForm[Inverse[Xt.Transpose[Xt].Xt.Yt, {20, 5}]


                  yields




                  {93.34215, 15.64854}




                  The first number in NumberForm (i.e. 20) is the total number of digits. We can set this to Infinity and it won't make a difference, but it shouldn't be less than the total number of digits you want to display. The second number (i.e. 5) is the number of decimal places.






                  share|improve this answer









                  $endgroup$
















                    8












                    8








                    8





                    $begingroup$

                    The documentation for N says that N[expr, n] attempts to give a result with n-digit precision. In the Wolfram Language, or any language, precision is not the same as decimal places. While it might seem like N is there to give us results with a certain number of decimal places, it actually has more to do with the amount of precision used in calculations behind the scenes. It can be especially confusing as sometimes N does close to what we expect as in N[Pi, 10] which gives us $pi$ with 10 digits (9 decimal places).



                    There is a different function called NumberForm that is designed to let us have more control over the display of numbers.



                    We can use:



                    NumberForm[Inverse[Xt.Transpose[Xt].Xt.Yt, {20, 5}]


                    yields




                    {93.34215, 15.64854}




                    The first number in NumberForm (i.e. 20) is the total number of digits. We can set this to Infinity and it won't make a difference, but it shouldn't be less than the total number of digits you want to display. The second number (i.e. 5) is the number of decimal places.






                    share|improve this answer









                    $endgroup$



                    The documentation for N says that N[expr, n] attempts to give a result with n-digit precision. In the Wolfram Language, or any language, precision is not the same as decimal places. While it might seem like N is there to give us results with a certain number of decimal places, it actually has more to do with the amount of precision used in calculations behind the scenes. It can be especially confusing as sometimes N does close to what we expect as in N[Pi, 10] which gives us $pi$ with 10 digits (9 decimal places).



                    There is a different function called NumberForm that is designed to let us have more control over the display of numbers.



                    We can use:



                    NumberForm[Inverse[Xt.Transpose[Xt].Xt.Yt, {20, 5}]


                    yields




                    {93.34215, 15.64854}




                    The first number in NumberForm (i.e. 20) is the total number of digits. We can set this to Infinity and it won't make a difference, but it shouldn't be less than the total number of digits you want to display. The second number (i.e. 5) is the number of decimal places.







                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Feb 9 at 7:29









                    MassDefectMassDefect

                    2,120311




                    2,120311























                        4












                        $begingroup$

                        According to this tutorial:




                        MachinePrecision is considered less precise than any other precision. This is because, while machine-precision numbers always store slightly under 16 digits, no specific number of those digits are known to be correct.




                        We're working with MachinePrecision, i.e.



                        Precision[Inverse[Xt.Transpose[Xt]].Xt.Yt]



                        MachinePrecision



                        and so N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5] needs to somehow upsample the precision of the result and that is an ill-defined operation.



                        In fact the ref page for N states




                        Unless numbers in expr are exact, or of sufficiently high precision, N[expr, n] may not be able to give results with n-digit precision.




                        To see why this is ill-defined, consider the reverse. Let's go from higher precision to lower precision.



                        x1 = N[Pi, 10]



                        $3.1415926{color{red}5}4$




                        x2 = N[Pi + 10^-8, 10]



                        $3.1415926{color{red}6}4$




                        N[{x1, x2}, 5]



                        {3.1416, 3.1416}




                        So we see if we reverse this example, going from precision 5 to precision 10 is ambiguous in the choices of the 6th - 10th digits.





                        If you'd like to upsample in a consistent way, use SetPrecision:




                        When SetPrecision is used to increase the precision of a number, the number is padded with zeros. The zeros are taken to be in base 2. In base 10, the additional digits are usually not zeros.




                        SetPrecision[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                        {93.342, 15.649}



                        If you only care about the display of the answer, consider using NumberForm:



                        NumberForm[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                        {93.342, 15.649}






                        share|improve this answer









                        $endgroup$


















                          4












                          $begingroup$

                          According to this tutorial:




                          MachinePrecision is considered less precise than any other precision. This is because, while machine-precision numbers always store slightly under 16 digits, no specific number of those digits are known to be correct.




                          We're working with MachinePrecision, i.e.



                          Precision[Inverse[Xt.Transpose[Xt]].Xt.Yt]



                          MachinePrecision



                          and so N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5] needs to somehow upsample the precision of the result and that is an ill-defined operation.



                          In fact the ref page for N states




                          Unless numbers in expr are exact, or of sufficiently high precision, N[expr, n] may not be able to give results with n-digit precision.




                          To see why this is ill-defined, consider the reverse. Let's go from higher precision to lower precision.



                          x1 = N[Pi, 10]



                          $3.1415926{color{red}5}4$




                          x2 = N[Pi + 10^-8, 10]



                          $3.1415926{color{red}6}4$




                          N[{x1, x2}, 5]



                          {3.1416, 3.1416}




                          So we see if we reverse this example, going from precision 5 to precision 10 is ambiguous in the choices of the 6th - 10th digits.





                          If you'd like to upsample in a consistent way, use SetPrecision:




                          When SetPrecision is used to increase the precision of a number, the number is padded with zeros. The zeros are taken to be in base 2. In base 10, the additional digits are usually not zeros.




                          SetPrecision[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                          {93.342, 15.649}



                          If you only care about the display of the answer, consider using NumberForm:



                          NumberForm[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                          {93.342, 15.649}






                          share|improve this answer









                          $endgroup$
















                            4












                            4








                            4





                            $begingroup$

                            According to this tutorial:




                            MachinePrecision is considered less precise than any other precision. This is because, while machine-precision numbers always store slightly under 16 digits, no specific number of those digits are known to be correct.




                            We're working with MachinePrecision, i.e.



                            Precision[Inverse[Xt.Transpose[Xt]].Xt.Yt]



                            MachinePrecision



                            and so N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5] needs to somehow upsample the precision of the result and that is an ill-defined operation.



                            In fact the ref page for N states




                            Unless numbers in expr are exact, or of sufficiently high precision, N[expr, n] may not be able to give results with n-digit precision.




                            To see why this is ill-defined, consider the reverse. Let's go from higher precision to lower precision.



                            x1 = N[Pi, 10]



                            $3.1415926{color{red}5}4$




                            x2 = N[Pi + 10^-8, 10]



                            $3.1415926{color{red}6}4$




                            N[{x1, x2}, 5]



                            {3.1416, 3.1416}




                            So we see if we reverse this example, going from precision 5 to precision 10 is ambiguous in the choices of the 6th - 10th digits.





                            If you'd like to upsample in a consistent way, use SetPrecision:




                            When SetPrecision is used to increase the precision of a number, the number is padded with zeros. The zeros are taken to be in base 2. In base 10, the additional digits are usually not zeros.




                            SetPrecision[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                            {93.342, 15.649}



                            If you only care about the display of the answer, consider using NumberForm:



                            NumberForm[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                            {93.342, 15.649}






                            share|improve this answer









                            $endgroup$



                            According to this tutorial:




                            MachinePrecision is considered less precise than any other precision. This is because, while machine-precision numbers always store slightly under 16 digits, no specific number of those digits are known to be correct.




                            We're working with MachinePrecision, i.e.



                            Precision[Inverse[Xt.Transpose[Xt]].Xt.Yt]



                            MachinePrecision



                            and so N[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5] needs to somehow upsample the precision of the result and that is an ill-defined operation.



                            In fact the ref page for N states




                            Unless numbers in expr are exact, or of sufficiently high precision, N[expr, n] may not be able to give results with n-digit precision.




                            To see why this is ill-defined, consider the reverse. Let's go from higher precision to lower precision.



                            x1 = N[Pi, 10]



                            $3.1415926{color{red}5}4$




                            x2 = N[Pi + 10^-8, 10]



                            $3.1415926{color{red}6}4$




                            N[{x1, x2}, 5]



                            {3.1416, 3.1416}




                            So we see if we reverse this example, going from precision 5 to precision 10 is ambiguous in the choices of the 6th - 10th digits.





                            If you'd like to upsample in a consistent way, use SetPrecision:




                            When SetPrecision is used to increase the precision of a number, the number is padded with zeros. The zeros are taken to be in base 2. In base 10, the additional digits are usually not zeros.




                            SetPrecision[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                            {93.342, 15.649}



                            If you only care about the display of the answer, consider using NumberForm:



                            NumberForm[Inverse[Xt.Transpose[Xt]].Xt.Yt, 5]



                            {93.342, 15.649}







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Feb 9 at 16:23









                            Chip HurstChip Hurst

                            23k15893




                            23k15893






























                                draft saved

                                draft discarded




















































                                Thanks for contributing an answer to Mathematica Stack Exchange!


                                • Please be sure to answer the question. Provide details and share your research!

                                But avoid



                                • Asking for help, clarification, or responding to other answers.

                                • Making statements based on opinion; back them up with references or personal experience.


                                Use MathJax to format equations. MathJax reference.


                                To learn more, see our tips on writing great answers.




                                draft saved


                                draft discarded














                                StackExchange.ready(
                                function () {
                                StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f191178%2fn-5-does-not-returns-what-i-expected%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

                                Human spaceflight

                                Can not write log (Is /dev/pts mounted?) - openpty in Ubuntu-on-Windows?

                                張江高科駅