How can we put element of vector to symsum?












1















I am trying to use symsum using Matlab. But I get a strange error.



I am trying to put elements of a vector into symsum:



a=[1,2,3,40,51,61];

syms u n

S1(u) = symsum((a(n+1)*(-u)^n)/factorial(n),n,[0,6])


Error is:




Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.











share|improve this question





























    1















    I am trying to use symsum using Matlab. But I get a strange error.



    I am trying to put elements of a vector into symsum:



    a=[1,2,3,40,51,61];

    syms u n

    S1(u) = symsum((a(n+1)*(-u)^n)/factorial(n),n,[0,6])


    Error is:




    Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.











    share|improve this question



























      1












      1








      1








      I am trying to use symsum using Matlab. But I get a strange error.



      I am trying to put elements of a vector into symsum:



      a=[1,2,3,40,51,61];

      syms u n

      S1(u) = symsum((a(n+1)*(-u)^n)/factorial(n),n,[0,6])


      Error is:




      Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.











      share|improve this question
















      I am trying to use symsum using Matlab. But I get a strange error.



      I am trying to put elements of a vector into symsum:



      a=[1,2,3,40,51,61];

      syms u n

      S1(u) = symsum((a(n+1)*(-u)^n)/factorial(n),n,[0,6])


      Error is:




      Invalid indexing or function definition. When defining a function, ensure that the arguments are symbolic variables and the body of the function is a SYM expression. When indexing, the input must be numeric, logical, or ':'.








      matlab vector series






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 14:59









      Alex Feinman

      3,82212547




      3,82212547










      asked Nov 5 '18 at 12:36









      Hamid RezaHamid Reza

      132




      132
























          1 Answer
          1






          active

          oldest

          votes


















          1














          First, I can see a mistake where you write a(n+1), for n going from 0 to 6. When n equals 6, you will have a(7) which doesn't exist. a only has 6 elements.



          Then, you have another problem because you are indexing a with a symbol, and symbolic indexing is not allowed (see this post).



          Does n really need to be a symbol and do you really need to use symsum? If not, you can try:



          a = [1,2,3,40,51,61];
          n = 0:5;
          syms u
          S1(u) = sum( sym( (a(n+1).*(-u).^n)./factorial(n) ) )


          This returns:



          S1(u) =

          - (61*u^5)/120 + (17*u^4)/8 - (20*u^3)/3 + (3*u^2)/2 - 2*u + 1





          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%2f53154576%2fhow-can-we-put-element-of-vector-to-symsum%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, I can see a mistake where you write a(n+1), for n going from 0 to 6. When n equals 6, you will have a(7) which doesn't exist. a only has 6 elements.



            Then, you have another problem because you are indexing a with a symbol, and symbolic indexing is not allowed (see this post).



            Does n really need to be a symbol and do you really need to use symsum? If not, you can try:



            a = [1,2,3,40,51,61];
            n = 0:5;
            syms u
            S1(u) = sum( sym( (a(n+1).*(-u).^n)./factorial(n) ) )


            This returns:



            S1(u) =

            - (61*u^5)/120 + (17*u^4)/8 - (20*u^3)/3 + (3*u^2)/2 - 2*u + 1





            share|improve this answer






























              1














              First, I can see a mistake where you write a(n+1), for n going from 0 to 6. When n equals 6, you will have a(7) which doesn't exist. a only has 6 elements.



              Then, you have another problem because you are indexing a with a symbol, and symbolic indexing is not allowed (see this post).



              Does n really need to be a symbol and do you really need to use symsum? If not, you can try:



              a = [1,2,3,40,51,61];
              n = 0:5;
              syms u
              S1(u) = sum( sym( (a(n+1).*(-u).^n)./factorial(n) ) )


              This returns:



              S1(u) =

              - (61*u^5)/120 + (17*u^4)/8 - (20*u^3)/3 + (3*u^2)/2 - 2*u + 1





              share|improve this answer




























                1












                1








                1







                First, I can see a mistake where you write a(n+1), for n going from 0 to 6. When n equals 6, you will have a(7) which doesn't exist. a only has 6 elements.



                Then, you have another problem because you are indexing a with a symbol, and symbolic indexing is not allowed (see this post).



                Does n really need to be a symbol and do you really need to use symsum? If not, you can try:



                a = [1,2,3,40,51,61];
                n = 0:5;
                syms u
                S1(u) = sum( sym( (a(n+1).*(-u).^n)./factorial(n) ) )


                This returns:



                S1(u) =

                - (61*u^5)/120 + (17*u^4)/8 - (20*u^3)/3 + (3*u^2)/2 - 2*u + 1





                share|improve this answer















                First, I can see a mistake where you write a(n+1), for n going from 0 to 6. When n equals 6, you will have a(7) which doesn't exist. a only has 6 elements.



                Then, you have another problem because you are indexing a with a symbol, and symbolic indexing is not allowed (see this post).



                Does n really need to be a symbol and do you really need to use symsum? If not, you can try:



                a = [1,2,3,40,51,61];
                n = 0:5;
                syms u
                S1(u) = sum( sym( (a(n+1).*(-u).^n)./factorial(n) ) )


                This returns:



                S1(u) =

                - (61*u^5)/120 + (17*u^4)/8 - (20*u^3)/3 + (3*u^2)/2 - 2*u + 1






                share|improve this answer














                share|improve this answer



                share|improve this answer








                edited Nov 16 '18 at 10:11

























                answered Nov 15 '18 at 13:59









                BebsBebs

                1,27331424




                1,27331424
































                    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%2f53154576%2fhow-can-we-put-element-of-vector-to-symsum%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

                    Florida Star v. B. J. F.

                    Danny Elfman

                    Lugert, Oklahoma