How do I add any point to a piecewise fplot?









up vote
0
down vote

favorite












I have been tasked with finding the natural cubic spline function S to interpolate a set of data I have been given. I have been given 11 data points. Essentially what this means is that I must place a cubic function between these points so that I have 10 cubic functions that flow together into something that looks like 1 function.



I have already completed this. I am new to using MatLab, so I'm not sure how I am supposed to put points on this plot.



Due to the nature of there being 10 functions I must glue together, I found a function called piecewise that works well for this. Here is how I define the function that is piecewise:



syms S(t)
S(t) = piecewise(x(1)<t<x(2), (longExpression1), x(2)<t<x(3), (longExpression2), ... x(10)<t<x(11), (longExpression10));


I then plot the function with fplot() and define the domain I want to see the plot for:



fplot(S(t), [0,100]);


I need to plot 13 points on this graph.
The first 11 points that I need to plot are the points that lie at the ends of each of these segments. The last 2 points that I need plot are not endpoints, but instead are points somewhere in the middle of two different piecewise segments.



The 11 data points have the following x and y values:



x = [0 10 20 30 40 50 60 70 80 90 100];
y = [75.995 91.972 105.711 123.203 131.669 150.697 179.323 203.212 226.505 249.633 281.422];


My plot looks like this:
enter image description here










share|improve this question

























    up vote
    0
    down vote

    favorite












    I have been tasked with finding the natural cubic spline function S to interpolate a set of data I have been given. I have been given 11 data points. Essentially what this means is that I must place a cubic function between these points so that I have 10 cubic functions that flow together into something that looks like 1 function.



    I have already completed this. I am new to using MatLab, so I'm not sure how I am supposed to put points on this plot.



    Due to the nature of there being 10 functions I must glue together, I found a function called piecewise that works well for this. Here is how I define the function that is piecewise:



    syms S(t)
    S(t) = piecewise(x(1)<t<x(2), (longExpression1), x(2)<t<x(3), (longExpression2), ... x(10)<t<x(11), (longExpression10));


    I then plot the function with fplot() and define the domain I want to see the plot for:



    fplot(S(t), [0,100]);


    I need to plot 13 points on this graph.
    The first 11 points that I need to plot are the points that lie at the ends of each of these segments. The last 2 points that I need plot are not endpoints, but instead are points somewhere in the middle of two different piecewise segments.



    The 11 data points have the following x and y values:



    x = [0 10 20 30 40 50 60 70 80 90 100];
    y = [75.995 91.972 105.711 123.203 131.669 150.697 179.323 203.212 226.505 249.633 281.422];


    My plot looks like this:
    enter image description here










    share|improve this question























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I have been tasked with finding the natural cubic spline function S to interpolate a set of data I have been given. I have been given 11 data points. Essentially what this means is that I must place a cubic function between these points so that I have 10 cubic functions that flow together into something that looks like 1 function.



      I have already completed this. I am new to using MatLab, so I'm not sure how I am supposed to put points on this plot.



      Due to the nature of there being 10 functions I must glue together, I found a function called piecewise that works well for this. Here is how I define the function that is piecewise:



      syms S(t)
      S(t) = piecewise(x(1)<t<x(2), (longExpression1), x(2)<t<x(3), (longExpression2), ... x(10)<t<x(11), (longExpression10));


      I then plot the function with fplot() and define the domain I want to see the plot for:



      fplot(S(t), [0,100]);


      I need to plot 13 points on this graph.
      The first 11 points that I need to plot are the points that lie at the ends of each of these segments. The last 2 points that I need plot are not endpoints, but instead are points somewhere in the middle of two different piecewise segments.



      The 11 data points have the following x and y values:



      x = [0 10 20 30 40 50 60 70 80 90 100];
      y = [75.995 91.972 105.711 123.203 131.669 150.697 179.323 203.212 226.505 249.633 281.422];


      My plot looks like this:
      enter image description here










      share|improve this question













      I have been tasked with finding the natural cubic spline function S to interpolate a set of data I have been given. I have been given 11 data points. Essentially what this means is that I must place a cubic function between these points so that I have 10 cubic functions that flow together into something that looks like 1 function.



      I have already completed this. I am new to using MatLab, so I'm not sure how I am supposed to put points on this plot.



      Due to the nature of there being 10 functions I must glue together, I found a function called piecewise that works well for this. Here is how I define the function that is piecewise:



      syms S(t)
      S(t) = piecewise(x(1)<t<x(2), (longExpression1), x(2)<t<x(3), (longExpression2), ... x(10)<t<x(11), (longExpression10));


      I then plot the function with fplot() and define the domain I want to see the plot for:



      fplot(S(t), [0,100]);


      I need to plot 13 points on this graph.
      The first 11 points that I need to plot are the points that lie at the ends of each of these segments. The last 2 points that I need plot are not endpoints, but instead are points somewhere in the middle of two different piecewise segments.



      The 11 data points have the following x and y values:



      x = [0 10 20 30 40 50 60 70 80 90 100];
      y = [75.995 91.972 105.711 123.203 131.669 150.697 179.323 203.212 226.505 249.633 281.422];


      My plot looks like this:
      enter image description here







      matlab matlab-figure






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 9 at 23:55









      FlamePrinz

      859




      859






















          1 Answer
          1






          active

          oldest

          votes

















          up vote
          1
          down vote



          accepted










          You may try the following:



          fplot(S(t), [0,100]);
          hold on % This will prevent the new plot from erasing the result of fplot
          plot(x,y,'or'); % 'ok' is a format identifier, the points will be plot as red(r) circles(o)
          plot([x1,X2],[S(x1),S(x2)],'or'); %Plot the two extra points





          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',
            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%2f53234753%2fhow-do-i-add-any-point-to-a-piecewise-fplot%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








            up vote
            1
            down vote



            accepted










            You may try the following:



            fplot(S(t), [0,100]);
            hold on % This will prevent the new plot from erasing the result of fplot
            plot(x,y,'or'); % 'ok' is a format identifier, the points will be plot as red(r) circles(o)
            plot([x1,X2],[S(x1),S(x2)],'or'); %Plot the two extra points





            share|improve this answer
























              up vote
              1
              down vote



              accepted










              You may try the following:



              fplot(S(t), [0,100]);
              hold on % This will prevent the new plot from erasing the result of fplot
              plot(x,y,'or'); % 'ok' is a format identifier, the points will be plot as red(r) circles(o)
              plot([x1,X2],[S(x1),S(x2)],'or'); %Plot the two extra points





              share|improve this answer






















                up vote
                1
                down vote



                accepted







                up vote
                1
                down vote



                accepted






                You may try the following:



                fplot(S(t), [0,100]);
                hold on % This will prevent the new plot from erasing the result of fplot
                plot(x,y,'or'); % 'ok' is a format identifier, the points will be plot as red(r) circles(o)
                plot([x1,X2],[S(x1),S(x2)],'or'); %Plot the two extra points





                share|improve this answer












                You may try the following:



                fplot(S(t), [0,100]);
                hold on % This will prevent the new plot from erasing the result of fplot
                plot(x,y,'or'); % 'ok' is a format identifier, the points will be plot as red(r) circles(o)
                plot([x1,X2],[S(x1),S(x2)],'or'); %Plot the two extra points






                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Nov 10 at 0:27









                Brice

                1,08810




                1,08810



























                     

                    draft saved


                    draft discarded















































                     


                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53234753%2fhow-do-i-add-any-point-to-a-piecewise-fplot%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

                    How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                    Syphilis

                    Darth Vader #20