Is there a way I can fix my data/code to fit this NonLinearModelFit?












1















When I tried to run this code:



Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
86400}, #2} & @@@ Data1};
Data3 = Data2 //. {x_List} :> x;
Data4 = Data3 //. {x_List} :> x;
Data5 = Data4 //. {x_List} :> x;
Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
NonlinearModelFit[Data6, {10^(a + b u^z +
c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
[Omega], [Phi]}, u]


I get these following error messages:




The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.




What is causing this?










share|improve this question





























    1















    When I tried to run this code:



    Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
    Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
    86400}, #2} & @@@ Data1};
    Data3 = Data2 //. {x_List} :> x;
    Data4 = Data3 //. {x_List} :> x;
    Data5 = Data4 //. {x_List} :> x;
    Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
    NonlinearModelFit[Data6, {10^(a + b u^z +
    c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
    0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
    [Omega], [Phi]}, u]


    I get these following error messages:




    The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
    Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.




    What is causing this?










    share|improve this question



























      1












      1








      1








      When I tried to run this code:



      Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
      Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
      86400}, #2} & @@@ Data1};
      Data3 = Data2 //. {x_List} :> x;
      Data4 = Data3 //. {x_List} :> x;
      Data5 = Data4 //. {x_List} :> x;
      Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
      NonlinearModelFit[Data6, {10^(a + b u^z +
      c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
      0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
      [Omega], [Phi]}, u]


      I get these following error messages:




      The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
      Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.




      What is causing this?










      share|improve this question
















      When I tried to run this code:



      Data1 = FinancialData["^DJI", {{2003, 10, 21}, {2007, 10, 09}}];
      Data2 = {{{{AbsoluteTime[#1] - AbsoluteTime[{2003, 10, 21}]}/
      86400}, #2} & @@@ Data1};
      Data3 = Data2 //. {x_List} :> x;
      Data4 = Data3 //. {x_List} :> x;
      Data5 = Data4 //. {x_List} :> x;
      Data6 = ArrayReshape[Data5 = Data4 //. {x_List} :> x, {1000, 2}];
      NonlinearModelFit[Data6, {10^(a + b u^z +
      c u^z Cos[[Phi] + [Omega] Log10[u]]), {b < 0, -1 < c < 1, 0.1` <= z <=
      0.9`, 4.8` <= [Omega] <= 13,0 <= [Phi] <= 2 [Pi]}}, {a, b, c, z,
      [Omega], [Phi]}, u]


      I get these following error messages:




      The gradient is not a vector of real numbers at {a,b,c,z,[Omega],[Phi]} = {1.,-1.,0.8,0.82,5.62,0.628319}.
      Evaluation of the gradient of function Experimental`NumericalFunction[<<1>>] failed at {1.,-1.,0.8,0.82,5.62,0.628319}.




      What is causing this?







      wolfram-mathematica






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 1 at 15:49









      SandPiper

      2,17931730




      2,17931730










      asked Jan 1 at 15:43









      Lim Yang ShengLim Yang Sheng

      61




      61
























          1 Answer
          1






          active

          oldest

          votes


















          1














          First[Data6]
          (* {0, 9747.64} *}


          Has u = 0 and the function being fitted has Log10[u]. Shift the u values by 1.



          Data7 = {First[#] + 1, Last[#]} & /@ Data6


          Add a constraint on a and fit



          fit = NonlinearModelFit[
          Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
          10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
          4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
          z, [Omega], [Phi]}, u]


          Plot data and fit



          Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]


          It is a pretty poor fit. May be able to get a better fit by altering the constraints.



          enter image description here






          share|improve this answer























            Your Answer






            StackExchange.ifUsing("editor", function () {
            StackExchange.using("externalEditor", function () {
            StackExchange.using("snippets", function () {
            StackExchange.snippets.init();
            });
            });
            }, "code-snippets");

            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "1"
            };
            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: 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
            },
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            });


            }
            });














            draft saved

            draft discarded


















            StackExchange.ready(
            function () {
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53996771%2fis-there-a-way-i-can-fix-my-data-code-to-fit-this-nonlinearmodelfit%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            First[Data6]
            (* {0, 9747.64} *}


            Has u = 0 and the function being fitted has Log10[u]. Shift the u values by 1.



            Data7 = {First[#] + 1, Last[#]} & /@ Data6


            Add a constraint on a and fit



            fit = NonlinearModelFit[
            Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
            10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
            4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
            z, [Omega], [Phi]}, u]


            Plot data and fit



            Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]


            It is a pretty poor fit. May be able to get a better fit by altering the constraints.



            enter image description here






            share|improve this answer




























              1














              First[Data6]
              (* {0, 9747.64} *}


              Has u = 0 and the function being fitted has Log10[u]. Shift the u values by 1.



              Data7 = {First[#] + 1, Last[#]} & /@ Data6


              Add a constraint on a and fit



              fit = NonlinearModelFit[
              Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
              10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
              4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
              z, [Omega], [Phi]}, u]


              Plot data and fit



              Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]


              It is a pretty poor fit. May be able to get a better fit by altering the constraints.



              enter image description here






              share|improve this answer


























                1












                1








                1







                First[Data6]
                (* {0, 9747.64} *}


                Has u = 0 and the function being fitted has Log10[u]. Shift the u values by 1.



                Data7 = {First[#] + 1, Last[#]} & /@ Data6


                Add a constraint on a and fit



                fit = NonlinearModelFit[
                Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
                10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
                4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
                z, [Omega], [Phi]}, u]


                Plot data and fit



                Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]


                It is a pretty poor fit. May be able to get a better fit by altering the constraints.



                enter image description here






                share|improve this answer













                First[Data6]
                (* {0, 9747.64} *}


                Has u = 0 and the function being fitted has Log10[u]. Shift the u values by 1.



                Data7 = {First[#] + 1, Last[#]} & /@ Data6


                Add a constraint on a and fit



                fit = NonlinearModelFit[
                Data7, {10^(a + b u^z + c u^z Cos[[Phi] + [Omega] Log10[u]]), {a <
                10, b < 0, -1 < c < 1, 0.1` <= z <= 0.9`,
                4.8` <= [Omega] <= 13, 0 <= [Phi] <= 2 [Pi]}}, {a, b, c,
                z, [Omega], [Phi]}, u]


                Plot data and fit



                Show[Plot[fit[u], {u, 1, 1450}], ListPlot[Data7]]


                It is a pretty poor fit. May be able to get a better fit by altering the constraints.



                enter image description here







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Jan 1 at 21:24









                Rohit NamjoshiRohit Namjoshi

                31718




                31718
































                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Stack Overflow!


                    • 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.


                    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%2fstackoverflow.com%2fquestions%2f53996771%2fis-there-a-way-i-can-fix-my-data-code-to-fit-this-nonlinearmodelfit%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

                    Monofisismo

                    Angular Downloading a file using contenturl with Basic Authentication

                    Olmecas