Problem in using FindFit











up vote
4
down vote

favorite












I have the following set of data



data={{0,0,0},{0,2,1},{0,4,2.247},{0,6,3.627},{0,8,5.031},{1,0,3.346}};


where the values are {n, L,$varepsilon$} and satisfy the following equations



$E(n,L) = 2n+1 + sqrt{L(L+1)-frac{3}{4}(L)^2 + 1 + beta_0^4}$



e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]


$varepsilon = frac{E(n,L)-E(0,0)}{E(0,2)-E(0,0)}$,



where $beta_0$ should be determined. I don't know how I can use FindFit command of Mathematica to find the best value of $beta_0$ to have the best fit for $varepsilon$.










share|improve this question




























    up vote
    4
    down vote

    favorite












    I have the following set of data



    data={{0,0,0},{0,2,1},{0,4,2.247},{0,6,3.627},{0,8,5.031},{1,0,3.346}};


    where the values are {n, L,$varepsilon$} and satisfy the following equations



    $E(n,L) = 2n+1 + sqrt{L(L+1)-frac{3}{4}(L)^2 + 1 + beta_0^4}$



    e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]


    $varepsilon = frac{E(n,L)-E(0,0)}{E(0,2)-E(0,0)}$,



    where $beta_0$ should be determined. I don't know how I can use FindFit command of Mathematica to find the best value of $beta_0$ to have the best fit for $varepsilon$.










    share|improve this question


























      up vote
      4
      down vote

      favorite









      up vote
      4
      down vote

      favorite











      I have the following set of data



      data={{0,0,0},{0,2,1},{0,4,2.247},{0,6,3.627},{0,8,5.031},{1,0,3.346}};


      where the values are {n, L,$varepsilon$} and satisfy the following equations



      $E(n,L) = 2n+1 + sqrt{L(L+1)-frac{3}{4}(L)^2 + 1 + beta_0^4}$



      e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]


      $varepsilon = frac{E(n,L)-E(0,0)}{E(0,2)-E(0,0)}$,



      where $beta_0$ should be determined. I don't know how I can use FindFit command of Mathematica to find the best value of $beta_0$ to have the best fit for $varepsilon$.










      share|improve this question















      I have the following set of data



      data={{0,0,0},{0,2,1},{0,4,2.247},{0,6,3.627},{0,8,5.031},{1,0,3.346}};


      where the values are {n, L,$varepsilon$} and satisfy the following equations



      $E(n,L) = 2n+1 + sqrt{L(L+1)-frac{3}{4}(L)^2 + 1 + beta_0^4}$



      e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]


      $varepsilon = frac{E(n,L)-E(0,0)}{E(0,2)-E(0,0)}$,



      where $beta_0$ should be determined. I don't know how I can use FindFit command of Mathematica to find the best value of $beta_0$ to have the best fit for $varepsilon$.







      fitting






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited yesterday









      Coolwater

      13.9k32351




      13.9k32351










      asked yesterday









      Hadi Sobhani

      1746




      1746






















          2 Answers
          2






          active

          oldest

          votes

















          up vote
          6
          down vote



          accepted










          e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]

          FindFit[data, (e[n, L] - e[0, 0])/(e[0, 2] - e[0, 0]), b0, {n, L}]



          {b0 -> 1.3514967}




          Which seems reasonable in view of the residuals:



          Plot[Evaluate[(e[#, #2] - e[0, 0])/(e[0, 2] - e[0, 0]) - #3 & @@@ data], {b0, 0, 3}]




          The brown and purple residual has bigger slope around the roots in the plots. Hence for Mathematica to minimize the sum of squares in the y-dimension, the mean of the 2 data points that correspond to the big slopes are cared more about than the others. It is purpose specific whether this is appropriate. If it isn't you can add the NormFunction-option to FindFit.






          share|improve this answer























          • Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
            – Hadi Sobhani
            yesterday










          • Also, how does it recognize that the expr is the 3rd value of every data element?
            – J42161217
            yesterday






          • 1




            FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
            – Coolwater
            yesterday










          • Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
            – J42161217
            yesterday










          • @J42161217 It uses least squares, see edit
            – Coolwater
            yesterday


















          up vote
          2
          down vote













          You can also use NMinimize. First we need to write cost function, i.e. residual.



          data = {{0, 0, 0}, {0, 2, 1}, {0, 4, 2.247}, {0, 6, 3.627}, {0, 8, 
          5.031}, {1, 0, 3.346}};
          e[n_, L_] := 2 n + 1 + Sqrt[L (L + 1) - 3/4 L^2 + 1 + b0^4]
          cost[b0_] =Sum[(e @@data[[i, 1 ;; 2]] - (data[[i, 3]] (e[0, 2] - e[0, 0]) +
          e[0, 0]))^2, {i, 6}];
          (*or Total[(e[#1, #2] - (#3 (e[0, 2] - e[0, 0]) + e[0, 0]))^2 & @@@ data]*)

          fit = NMinimize[cost[b0] , b0]



          {0.0196376, {b0 -> 1.35462}}




          Since your cost function has only one variable you can also use grid search.



          Ordering[val,1] gives position of min value.



          b0Val = Range[0, 10, 0.0001];
          val = cost[b0Val];
          b0Val[[Ordering[val, 1]]]



          {1.3546}




          Note that there is another min at b0=-1.3546



          b0Val = Range[-1000, 1000, 0.001];    
          val = cost[b0Val];
          b0Val[[Ordering[val, 2]]]



          {-1.3546, 1.3546}




          We can plot cost function



          $text{cost}(b0)=left(-5.031 left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+25}right)^2\+left(-3.627
          left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+
          sqrt{text{b0}^4+16}right)^2\+left(2-3.346
          left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)right)^2+left(-2.247
          left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+9}right)^2$



          Plot[cost[b0], {b0, -10, 10}]


          enter image description here






          share|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: "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',
            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%2f185829%2fproblem-in-using-findfit%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
            6
            down vote



            accepted










            e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]

            FindFit[data, (e[n, L] - e[0, 0])/(e[0, 2] - e[0, 0]), b0, {n, L}]



            {b0 -> 1.3514967}




            Which seems reasonable in view of the residuals:



            Plot[Evaluate[(e[#, #2] - e[0, 0])/(e[0, 2] - e[0, 0]) - #3 & @@@ data], {b0, 0, 3}]




            The brown and purple residual has bigger slope around the roots in the plots. Hence for Mathematica to minimize the sum of squares in the y-dimension, the mean of the 2 data points that correspond to the big slopes are cared more about than the others. It is purpose specific whether this is appropriate. If it isn't you can add the NormFunction-option to FindFit.






            share|improve this answer























            • Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
              – Hadi Sobhani
              yesterday










            • Also, how does it recognize that the expr is the 3rd value of every data element?
              – J42161217
              yesterday






            • 1




              FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
              – Coolwater
              yesterday










            • Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
              – J42161217
              yesterday










            • @J42161217 It uses least squares, see edit
              – Coolwater
              yesterday















            up vote
            6
            down vote



            accepted










            e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]

            FindFit[data, (e[n, L] - e[0, 0])/(e[0, 2] - e[0, 0]), b0, {n, L}]



            {b0 -> 1.3514967}




            Which seems reasonable in view of the residuals:



            Plot[Evaluate[(e[#, #2] - e[0, 0])/(e[0, 2] - e[0, 0]) - #3 & @@@ data], {b0, 0, 3}]




            The brown and purple residual has bigger slope around the roots in the plots. Hence for Mathematica to minimize the sum of squares in the y-dimension, the mean of the 2 data points that correspond to the big slopes are cared more about than the others. It is purpose specific whether this is appropriate. If it isn't you can add the NormFunction-option to FindFit.






            share|improve this answer























            • Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
              – Hadi Sobhani
              yesterday










            • Also, how does it recognize that the expr is the 3rd value of every data element?
              – J42161217
              yesterday






            • 1




              FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
              – Coolwater
              yesterday










            • Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
              – J42161217
              yesterday










            • @J42161217 It uses least squares, see edit
              – Coolwater
              yesterday













            up vote
            6
            down vote



            accepted







            up vote
            6
            down vote



            accepted






            e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]

            FindFit[data, (e[n, L] - e[0, 0])/(e[0, 2] - e[0, 0]), b0, {n, L}]



            {b0 -> 1.3514967}




            Which seems reasonable in view of the residuals:



            Plot[Evaluate[(e[#, #2] - e[0, 0])/(e[0, 2] - e[0, 0]) - #3 & @@@ data], {b0, 0, 3}]




            The brown and purple residual has bigger slope around the roots in the plots. Hence for Mathematica to minimize the sum of squares in the y-dimension, the mean of the 2 data points that correspond to the big slopes are cared more about than the others. It is purpose specific whether this is appropriate. If it isn't you can add the NormFunction-option to FindFit.






            share|improve this answer














            e[n_, L_] = 2n + 1 + Sqrt[L(L + 1) - 3/4 L^2 + 1 + b0^4]

            FindFit[data, (e[n, L] - e[0, 0])/(e[0, 2] - e[0, 0]), b0, {n, L}]



            {b0 -> 1.3514967}




            Which seems reasonable in view of the residuals:



            Plot[Evaluate[(e[#, #2] - e[0, 0])/(e[0, 2] - e[0, 0]) - #3 & @@@ data], {b0, 0, 3}]




            The brown and purple residual has bigger slope around the roots in the plots. Hence for Mathematica to minimize the sum of squares in the y-dimension, the mean of the 2 data points that correspond to the big slopes are cared more about than the others. It is purpose specific whether this is appropriate. If it isn't you can add the NormFunction-option to FindFit.







            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited yesterday

























            answered yesterday









            Coolwater

            13.9k32351




            13.9k32351












            • Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
              – Hadi Sobhani
              yesterday










            • Also, how does it recognize that the expr is the 3rd value of every data element?
              – J42161217
              yesterday






            • 1




              FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
              – Coolwater
              yesterday










            • Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
              – J42161217
              yesterday










            • @J42161217 It uses least squares, see edit
              – Coolwater
              yesterday


















            • Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
              – Hadi Sobhani
              yesterday










            • Also, how does it recognize that the expr is the 3rd value of every data element?
              – J42161217
              yesterday






            • 1




              FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
              – Coolwater
              yesterday










            • Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
              – J42161217
              yesterday










            • @J42161217 It uses least squares, see edit
              – Coolwater
              yesterday
















            Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
            – Hadi Sobhani
            yesterday




            Thank you dear @Coolwater. How does Mathematica recognize {n,L} for each data?
            – Hadi Sobhani
            yesterday












            Also, how does it recognize that the expr is the 3rd value of every data element?
            – J42161217
            yesterday




            Also, how does it recognize that the expr is the 3rd value of every data element?
            – J42161217
            yesterday




            1




            1




            FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
            – Coolwater
            yesterday




            FindFit assumes its first argument has the form {{var1, var2, ..., varN, expr}, ... , {var1, var2, ..., varN, expr}} where {var1, var2, ..., varN} is the 4th argument of FindFit
            – Coolwater
            yesterday












            Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
            – J42161217
            yesterday




            Ok! Given b -> {1.27225, 1.29505, 1.28573, 1.40411} having Mean=1.31428 and Medean=1.29039 do you think Mathematica did a good job? Anyway +1 from me
            – J42161217
            yesterday












            @J42161217 It uses least squares, see edit
            – Coolwater
            yesterday




            @J42161217 It uses least squares, see edit
            – Coolwater
            yesterday










            up vote
            2
            down vote













            You can also use NMinimize. First we need to write cost function, i.e. residual.



            data = {{0, 0, 0}, {0, 2, 1}, {0, 4, 2.247}, {0, 6, 3.627}, {0, 8, 
            5.031}, {1, 0, 3.346}};
            e[n_, L_] := 2 n + 1 + Sqrt[L (L + 1) - 3/4 L^2 + 1 + b0^4]
            cost[b0_] =Sum[(e @@data[[i, 1 ;; 2]] - (data[[i, 3]] (e[0, 2] - e[0, 0]) +
            e[0, 0]))^2, {i, 6}];
            (*or Total[(e[#1, #2] - (#3 (e[0, 2] - e[0, 0]) + e[0, 0]))^2 & @@@ data]*)

            fit = NMinimize[cost[b0] , b0]



            {0.0196376, {b0 -> 1.35462}}




            Since your cost function has only one variable you can also use grid search.



            Ordering[val,1] gives position of min value.



            b0Val = Range[0, 10, 0.0001];
            val = cost[b0Val];
            b0Val[[Ordering[val, 1]]]



            {1.3546}




            Note that there is another min at b0=-1.3546



            b0Val = Range[-1000, 1000, 0.001];    
            val = cost[b0Val];
            b0Val[[Ordering[val, 2]]]



            {-1.3546, 1.3546}




            We can plot cost function



            $text{cost}(b0)=left(-5.031 left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+25}right)^2\+left(-3.627
            left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+
            sqrt{text{b0}^4+16}right)^2\+left(2-3.346
            left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)right)^2+left(-2.247
            left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+9}right)^2$



            Plot[cost[b0], {b0, -10, 10}]


            enter image description here






            share|improve this answer



























              up vote
              2
              down vote













              You can also use NMinimize. First we need to write cost function, i.e. residual.



              data = {{0, 0, 0}, {0, 2, 1}, {0, 4, 2.247}, {0, 6, 3.627}, {0, 8, 
              5.031}, {1, 0, 3.346}};
              e[n_, L_] := 2 n + 1 + Sqrt[L (L + 1) - 3/4 L^2 + 1 + b0^4]
              cost[b0_] =Sum[(e @@data[[i, 1 ;; 2]] - (data[[i, 3]] (e[0, 2] - e[0, 0]) +
              e[0, 0]))^2, {i, 6}];
              (*or Total[(e[#1, #2] - (#3 (e[0, 2] - e[0, 0]) + e[0, 0]))^2 & @@@ data]*)

              fit = NMinimize[cost[b0] , b0]



              {0.0196376, {b0 -> 1.35462}}




              Since your cost function has only one variable you can also use grid search.



              Ordering[val,1] gives position of min value.



              b0Val = Range[0, 10, 0.0001];
              val = cost[b0Val];
              b0Val[[Ordering[val, 1]]]



              {1.3546}




              Note that there is another min at b0=-1.3546



              b0Val = Range[-1000, 1000, 0.001];    
              val = cost[b0Val];
              b0Val[[Ordering[val, 2]]]



              {-1.3546, 1.3546}




              We can plot cost function



              $text{cost}(b0)=left(-5.031 left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+25}right)^2\+left(-3.627
              left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+
              sqrt{text{b0}^4+16}right)^2\+left(2-3.346
              left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)right)^2+left(-2.247
              left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+9}right)^2$



              Plot[cost[b0], {b0, -10, 10}]


              enter image description here






              share|improve this answer

























                up vote
                2
                down vote










                up vote
                2
                down vote









                You can also use NMinimize. First we need to write cost function, i.e. residual.



                data = {{0, 0, 0}, {0, 2, 1}, {0, 4, 2.247}, {0, 6, 3.627}, {0, 8, 
                5.031}, {1, 0, 3.346}};
                e[n_, L_] := 2 n + 1 + Sqrt[L (L + 1) - 3/4 L^2 + 1 + b0^4]
                cost[b0_] =Sum[(e @@data[[i, 1 ;; 2]] - (data[[i, 3]] (e[0, 2] - e[0, 0]) +
                e[0, 0]))^2, {i, 6}];
                (*or Total[(e[#1, #2] - (#3 (e[0, 2] - e[0, 0]) + e[0, 0]))^2 & @@@ data]*)

                fit = NMinimize[cost[b0] , b0]



                {0.0196376, {b0 -> 1.35462}}




                Since your cost function has only one variable you can also use grid search.



                Ordering[val,1] gives position of min value.



                b0Val = Range[0, 10, 0.0001];
                val = cost[b0Val];
                b0Val[[Ordering[val, 1]]]



                {1.3546}




                Note that there is another min at b0=-1.3546



                b0Val = Range[-1000, 1000, 0.001];    
                val = cost[b0Val];
                b0Val[[Ordering[val, 2]]]



                {-1.3546, 1.3546}




                We can plot cost function



                $text{cost}(b0)=left(-5.031 left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+25}right)^2\+left(-3.627
                left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+
                sqrt{text{b0}^4+16}right)^2\+left(2-3.346
                left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)right)^2+left(-2.247
                left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+9}right)^2$



                Plot[cost[b0], {b0, -10, 10}]


                enter image description here






                share|improve this answer














                You can also use NMinimize. First we need to write cost function, i.e. residual.



                data = {{0, 0, 0}, {0, 2, 1}, {0, 4, 2.247}, {0, 6, 3.627}, {0, 8, 
                5.031}, {1, 0, 3.346}};
                e[n_, L_] := 2 n + 1 + Sqrt[L (L + 1) - 3/4 L^2 + 1 + b0^4]
                cost[b0_] =Sum[(e @@data[[i, 1 ;; 2]] - (data[[i, 3]] (e[0, 2] - e[0, 0]) +
                e[0, 0]))^2, {i, 6}];
                (*or Total[(e[#1, #2] - (#3 (e[0, 2] - e[0, 0]) + e[0, 0]))^2 & @@@ data]*)

                fit = NMinimize[cost[b0] , b0]



                {0.0196376, {b0 -> 1.35462}}




                Since your cost function has only one variable you can also use grid search.



                Ordering[val,1] gives position of min value.



                b0Val = Range[0, 10, 0.0001];
                val = cost[b0Val];
                b0Val[[Ordering[val, 1]]]



                {1.3546}




                Note that there is another min at b0=-1.3546



                b0Val = Range[-1000, 1000, 0.001];    
                val = cost[b0Val];
                b0Val[[Ordering[val, 2]]]



                {-1.3546, 1.3546}




                We can plot cost function



                $text{cost}(b0)=left(-5.031 left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+25}right)^2\+left(-3.627
                left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+
                sqrt{text{b0}^4+16}right)^2\+left(2-3.346
                left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)right)^2+left(-2.247
                left(sqrt{text{b0}^4+4}-sqrt{text{b0}^4+1}right)-sqrt{text{b0}^4+1}+sqrt{text{b0}^4+9}right)^2$



                Plot[cost[b0], {b0, -10, 10}]


                enter image description here







                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited 21 hours ago

























                answered yesterday









                Okkes Dulgerci

                3,4811716




                3,4811716






























                     

                    draft saved


                    draft discarded



















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function () {
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmathematica.stackexchange.com%2fquestions%2f185829%2fproblem-in-using-findfit%23new-answer', 'question_page');
                    }
                    );

                    Post as a guest




















































































                    Popular posts from this blog

                    How to send String Array data to Server using php in android

                    Title Spacing in Bjornstrup Chapter, Removing Chapter Number From Contents

                    Is anime1.com a legal site for watching anime?