Why vector don't equal when differentiating sin(pi*x)










0















I don't understand why i keep getting




Error using plot Vectors must be the same length




As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.



clc;
%differentiation and integration:
%Waveform of sine(pi*x):

sym('x');
s= sin(pi*x1);
x1= linspace(0,4);

subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);

subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line









share|improve this question

















  • 5





    Hi, you should read the documentation of diff: If x is a vector of length m, then y=diff(x) returns a vector of length m-1. One possible solution for your problem would be: s1=[0 s1]

    – Irreducible
    Nov 16 '18 at 6:31












  • The symbolic variable x is never used and x1 is defined out of order. Please provide a Rundle example.

    – Mad Physicist
    Nov 16 '18 at 7:04











  • @Irreductible, this is actually the answer to the question, you should post it as an answer

    – Brice
    Nov 16 '18 at 8:34















0















I don't understand why i keep getting




Error using plot Vectors must be the same length




As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.



clc;
%differentiation and integration:
%Waveform of sine(pi*x):

sym('x');
s= sin(pi*x1);
x1= linspace(0,4);

subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);

subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line









share|improve this question

















  • 5





    Hi, you should read the documentation of diff: If x is a vector of length m, then y=diff(x) returns a vector of length m-1. One possible solution for your problem would be: s1=[0 s1]

    – Irreducible
    Nov 16 '18 at 6:31












  • The symbolic variable x is never used and x1 is defined out of order. Please provide a Rundle example.

    – Mad Physicist
    Nov 16 '18 at 7:04











  • @Irreductible, this is actually the answer to the question, you should post it as an answer

    – Brice
    Nov 16 '18 at 8:34













0












0








0








I don't understand why i keep getting




Error using plot Vectors must be the same length




As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.



clc;
%differentiation and integration:
%Waveform of sine(pi*x):

sym('x');
s= sin(pi*x1);
x1= linspace(0,4);

subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);

subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line









share|improve this question














I don't understand why i keep getting




Error using plot Vectors must be the same length




As the data shows s1=1X100 and s2=1X99 which i don't understand why it has that data.



clc;
%differentiation and integration:
%Waveform of sine(pi*x):

sym('x');
s= sin(pi*x1);
x1= linspace(0,4);

subplot(2,1,1);
plot(x1,s)
axis([0 4 -4 4]);

subplot(2,1,2);
s1= diff(s);
plot(x1,s1) % Error at this line






matlab vector plot






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 16 '18 at 5:15









Anime LoverAnime Lover

32




32







  • 5





    Hi, you should read the documentation of diff: If x is a vector of length m, then y=diff(x) returns a vector of length m-1. One possible solution for your problem would be: s1=[0 s1]

    – Irreducible
    Nov 16 '18 at 6:31












  • The symbolic variable x is never used and x1 is defined out of order. Please provide a Rundle example.

    – Mad Physicist
    Nov 16 '18 at 7:04











  • @Irreductible, this is actually the answer to the question, you should post it as an answer

    – Brice
    Nov 16 '18 at 8:34












  • 5





    Hi, you should read the documentation of diff: If x is a vector of length m, then y=diff(x) returns a vector of length m-1. One possible solution for your problem would be: s1=[0 s1]

    – Irreducible
    Nov 16 '18 at 6:31












  • The symbolic variable x is never used and x1 is defined out of order. Please provide a Rundle example.

    – Mad Physicist
    Nov 16 '18 at 7:04











  • @Irreductible, this is actually the answer to the question, you should post it as an answer

    – Brice
    Nov 16 '18 at 8:34







5




5





Hi, you should read the documentation of diff: If x is a vector of length m, then y=diff(x) returns a vector of length m-1. One possible solution for your problem would be: s1=[0 s1]

– Irreducible
Nov 16 '18 at 6:31






Hi, you should read the documentation of diff: If x is a vector of length m, then y=diff(x) returns a vector of length m-1. One possible solution for your problem would be: s1=[0 s1]

– Irreducible
Nov 16 '18 at 6:31














The symbolic variable x is never used and x1 is defined out of order. Please provide a Rundle example.

– Mad Physicist
Nov 16 '18 at 7:04





The symbolic variable x is never used and x1 is defined out of order. Please provide a Rundle example.

– Mad Physicist
Nov 16 '18 at 7:04













@Irreductible, this is actually the answer to the question, you should post it as an answer

– Brice
Nov 16 '18 at 8:34





@Irreductible, this is actually the answer to the question, you should post it as an answer

– Brice
Nov 16 '18 at 8:34












2 Answers
2






active

oldest

votes


















0














As mentioned in the comments



You should read the documentation of diff:



If x is a vector of length m, then y=diff(x) returns a vector of length m-1. 


One possible solution for your problem would be:



s1=[0 s1] 





share|improve this answer






























    -1














    You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.



    syms x;
    s= sin(pi*x);
    x= linspace(0,4);
    subplot(2,1,1);
    sr = subs(s,x) ;
    plot(x,sr);
    axis([0 4 -4 4]);
    subplot(2,1,2);
    s1= diff(s);
    s1r = subs(s1,x) ;
    plot(x,s1r)


    YOu need not to use syms actually.



    x= linspace(0,4);
    s= sin(pi*x);
    subplot(2,1,1);

    plot(x,s);
    axis([0 4 -4 4]);
    subplot(2,1,2);
    s1= gradient(s);

    plot(x,s1)





    share|improve this answer




















    • 1





      x is never used in OP's code.

      – Mad Physicist
      Nov 16 '18 at 7:04











    • If that was the case, code would crash at the first plot attempt, not the second one

      – Brice
      Nov 16 '18 at 8:33










    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%2f53331830%2fwhy-vector-dont-equal-when-differentiating-sinpix%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









    0














    As mentioned in the comments



    You should read the documentation of diff:



    If x is a vector of length m, then y=diff(x) returns a vector of length m-1. 


    One possible solution for your problem would be:



    s1=[0 s1] 





    share|improve this answer



























      0














      As mentioned in the comments



      You should read the documentation of diff:



      If x is a vector of length m, then y=diff(x) returns a vector of length m-1. 


      One possible solution for your problem would be:



      s1=[0 s1] 





      share|improve this answer

























        0












        0








        0







        As mentioned in the comments



        You should read the documentation of diff:



        If x is a vector of length m, then y=diff(x) returns a vector of length m-1. 


        One possible solution for your problem would be:



        s1=[0 s1] 





        share|improve this answer













        As mentioned in the comments



        You should read the documentation of diff:



        If x is a vector of length m, then y=diff(x) returns a vector of length m-1. 


        One possible solution for your problem would be:



        s1=[0 s1] 






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered Nov 16 '18 at 11:08









        IrreducibleIrreducible

        668720




        668720























            -1














            You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.



            syms x;
            s= sin(pi*x);
            x= linspace(0,4);
            subplot(2,1,1);
            sr = subs(s,x) ;
            plot(x,sr);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= diff(s);
            s1r = subs(s1,x) ;
            plot(x,s1r)


            YOu need not to use syms actually.



            x= linspace(0,4);
            s= sin(pi*x);
            subplot(2,1,1);

            plot(x,s);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= gradient(s);

            plot(x,s1)





            share|improve this answer




















            • 1





              x is never used in OP's code.

              – Mad Physicist
              Nov 16 '18 at 7:04











            • If that was the case, code would crash at the first plot attempt, not the second one

              – Brice
              Nov 16 '18 at 8:33















            -1














            You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.



            syms x;
            s= sin(pi*x);
            x= linspace(0,4);
            subplot(2,1,1);
            sr = subs(s,x) ;
            plot(x,sr);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= diff(s);
            s1r = subs(s1,x) ;
            plot(x,s1r)


            YOu need not to use syms actually.



            x= linspace(0,4);
            s= sin(pi*x);
            subplot(2,1,1);

            plot(x,s);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= gradient(s);

            plot(x,s1)





            share|improve this answer




















            • 1





              x is never used in OP's code.

              – Mad Physicist
              Nov 16 '18 at 7:04











            • If that was the case, code would crash at the first plot attempt, not the second one

              – Brice
              Nov 16 '18 at 8:33













            -1












            -1








            -1







            You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.



            syms x;
            s= sin(pi*x);
            x= linspace(0,4);
            subplot(2,1,1);
            sr = subs(s,x) ;
            plot(x,sr);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= diff(s);
            s1r = subs(s1,x) ;
            plot(x,s1r)


            YOu need not to use syms actually.



            x= linspace(0,4);
            s= sin(pi*x);
            subplot(2,1,1);

            plot(x,s);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= gradient(s);

            plot(x,s1)





            share|improve this answer















            You have to substitute the value of x in the sym objects s and s1 using subs. After that it will be converted to double and then you can plot them.



            syms x;
            s= sin(pi*x);
            x= linspace(0,4);
            subplot(2,1,1);
            sr = subs(s,x) ;
            plot(x,sr);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= diff(s);
            s1r = subs(s1,x) ;
            plot(x,s1r)


            YOu need not to use syms actually.



            x= linspace(0,4);
            s= sin(pi*x);
            subplot(2,1,1);

            plot(x,s);
            axis([0 4 -4 4]);
            subplot(2,1,2);
            s1= gradient(s);

            plot(x,s1)






            share|improve this answer














            share|improve this answer



            share|improve this answer








            edited Nov 16 '18 at 8:38

























            answered Nov 16 '18 at 7:01









            Siva Srinivas KolukulaSiva Srinivas Kolukula

            1,1351613




            1,1351613







            • 1





              x is never used in OP's code.

              – Mad Physicist
              Nov 16 '18 at 7:04











            • If that was the case, code would crash at the first plot attempt, not the second one

              – Brice
              Nov 16 '18 at 8:33












            • 1





              x is never used in OP's code.

              – Mad Physicist
              Nov 16 '18 at 7:04











            • If that was the case, code would crash at the first plot attempt, not the second one

              – Brice
              Nov 16 '18 at 8:33







            1




            1





            x is never used in OP's code.

            – Mad Physicist
            Nov 16 '18 at 7:04





            x is never used in OP's code.

            – Mad Physicist
            Nov 16 '18 at 7:04













            If that was the case, code would crash at the first plot attempt, not the second one

            – Brice
            Nov 16 '18 at 8:33





            If that was the case, code would crash at the first plot attempt, not the second one

            – Brice
            Nov 16 '18 at 8:33

















            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%2f53331830%2fwhy-vector-dont-equal-when-differentiating-sinpix%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

            Top Tejano songwriter Luis Silva dead of heart attack at 64

            ReactJS Fetched API data displays live - need Data displayed static

            Evgeni Malkin