How can I make a general plot like this in Mathematica?












2












$begingroup$


I want to make two general graphics something like the following.



enter image description here



I want to illustrate the approach to the function by means of a polynomial. I have tried the following.



Plot[{Sin[x] + 2,  Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
Ticks -> {{0.8, 2.4, 4, 5.5, 7.1}, {0, 1, 2, 3}}]


I also want to put $ x_{0}, x_{1}, x_{2},...,x_{n} $ in the points where the graphs differ the most. I appreciate any help.










share|improve this question









$endgroup$

















    2












    $begingroup$


    I want to make two general graphics something like the following.



    enter image description here



    I want to illustrate the approach to the function by means of a polynomial. I have tried the following.



    Plot[{Sin[x] + 2,  Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
    Ticks -> {{0.8, 2.4, 4, 5.5, 7.1}, {0, 1, 2, 3}}]


    I also want to put $ x_{0}, x_{1}, x_{2},...,x_{n} $ in the points where the graphs differ the most. I appreciate any help.










    share|improve this question









    $endgroup$















      2












      2








      2





      $begingroup$


      I want to make two general graphics something like the following.



      enter image description here



      I want to illustrate the approach to the function by means of a polynomial. I have tried the following.



      Plot[{Sin[x] + 2,  Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
      Ticks -> {{0.8, 2.4, 4, 5.5, 7.1}, {0, 1, 2, 3}}]


      I also want to put $ x_{0}, x_{1}, x_{2},...,x_{n} $ in the points where the graphs differ the most. I appreciate any help.










      share|improve this question









      $endgroup$




      I want to make two general graphics something like the following.



      enter image description here



      I want to illustrate the approach to the function by means of a polynomial. I have tried the following.



      Plot[{Sin[x] + 2,  Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
      Ticks -> {{0.8, 2.4, 4, 5.5, 7.1}, {0, 1, 2, 3}}]


      I also want to put $ x_{0}, x_{1}, x_{2},...,x_{n} $ in the points where the graphs differ the most. I appreciate any help.







      plotting graphics






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Feb 5 at 6:55









      Jacob SchwartzJacob Schwartz

      475




      475






















          2 Answers
          2






          active

          oldest

          votes


















          3












          $begingroup$

          f[x_] := 1 + x + Sin[10 Sqrt[1 + x]];
          g[x_] := 1 + x + Cos[10 Sqrt[2 + x]];
          xx = x /. NSolve[{f'[x] == g'[x], 0 <= x <= 8}, x];
          ticks = MapIndexed[{#, Style[ Subscript["x", ToString@ #2[[1]]], 16]} &, xx];
          Plot[{f[x], g[x]}, {x, 0, 3 Pi}, AxesLabel -> {x, y},
          MeshFunctions -> {f'[#] - g'[#] &}, Mesh -> {{0}},
          MeshStyle -> Directive[Red, PointSize[Large]],
          GridLines -> {xx, None}, Ticks -> {ticks, Automatic},
          AxesOrigin -> {0, 0}]


          enter image description here






          share|improve this answer









          $endgroup$













          • $begingroup$
            How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 8:10










          • $begingroup$
            @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
            $endgroup$
            – kglr
            Feb 5 at 8:19



















          2












          $begingroup$

          Something like this?



              Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[3]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          PlotLabels -> Placed[{"y=f(x)", "y=p(x)"}, {Scaled[5], Above}],
          AxesStyle -> Arrowheads[{0.0, 0.05}]]


          enter image description here



          Or



          Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[2]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          AxesStyle -> Arrowheads[{0.0, 0.05}],
          Epilog -> {Text[Style["y=f(x)", 22], Scaled[{0.5, 0.9}]],
          Text[Style["y=p(x)", 22], Scaled[{0.25, 0.97}]]}]


          enter image description here






          share|improve this answer











          $endgroup$













          • $begingroup$
            I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 7:56











          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',
          autoActivateHeartbeat: false,
          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%2f190905%2fhow-can-i-make-a-general-plot-like-this-in-mathematica%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









          3












          $begingroup$

          f[x_] := 1 + x + Sin[10 Sqrt[1 + x]];
          g[x_] := 1 + x + Cos[10 Sqrt[2 + x]];
          xx = x /. NSolve[{f'[x] == g'[x], 0 <= x <= 8}, x];
          ticks = MapIndexed[{#, Style[ Subscript["x", ToString@ #2[[1]]], 16]} &, xx];
          Plot[{f[x], g[x]}, {x, 0, 3 Pi}, AxesLabel -> {x, y},
          MeshFunctions -> {f'[#] - g'[#] &}, Mesh -> {{0}},
          MeshStyle -> Directive[Red, PointSize[Large]],
          GridLines -> {xx, None}, Ticks -> {ticks, Automatic},
          AxesOrigin -> {0, 0}]


          enter image description here






          share|improve this answer









          $endgroup$













          • $begingroup$
            How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 8:10










          • $begingroup$
            @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
            $endgroup$
            – kglr
            Feb 5 at 8:19
















          3












          $begingroup$

          f[x_] := 1 + x + Sin[10 Sqrt[1 + x]];
          g[x_] := 1 + x + Cos[10 Sqrt[2 + x]];
          xx = x /. NSolve[{f'[x] == g'[x], 0 <= x <= 8}, x];
          ticks = MapIndexed[{#, Style[ Subscript["x", ToString@ #2[[1]]], 16]} &, xx];
          Plot[{f[x], g[x]}, {x, 0, 3 Pi}, AxesLabel -> {x, y},
          MeshFunctions -> {f'[#] - g'[#] &}, Mesh -> {{0}},
          MeshStyle -> Directive[Red, PointSize[Large]],
          GridLines -> {xx, None}, Ticks -> {ticks, Automatic},
          AxesOrigin -> {0, 0}]


          enter image description here






          share|improve this answer









          $endgroup$













          • $begingroup$
            How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 8:10










          • $begingroup$
            @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
            $endgroup$
            – kglr
            Feb 5 at 8:19














          3












          3








          3





          $begingroup$

          f[x_] := 1 + x + Sin[10 Sqrt[1 + x]];
          g[x_] := 1 + x + Cos[10 Sqrt[2 + x]];
          xx = x /. NSolve[{f'[x] == g'[x], 0 <= x <= 8}, x];
          ticks = MapIndexed[{#, Style[ Subscript["x", ToString@ #2[[1]]], 16]} &, xx];
          Plot[{f[x], g[x]}, {x, 0, 3 Pi}, AxesLabel -> {x, y},
          MeshFunctions -> {f'[#] - g'[#] &}, Mesh -> {{0}},
          MeshStyle -> Directive[Red, PointSize[Large]],
          GridLines -> {xx, None}, Ticks -> {ticks, Automatic},
          AxesOrigin -> {0, 0}]


          enter image description here






          share|improve this answer









          $endgroup$



          f[x_] := 1 + x + Sin[10 Sqrt[1 + x]];
          g[x_] := 1 + x + Cos[10 Sqrt[2 + x]];
          xx = x /. NSolve[{f'[x] == g'[x], 0 <= x <= 8}, x];
          ticks = MapIndexed[{#, Style[ Subscript["x", ToString@ #2[[1]]], 16]} &, xx];
          Plot[{f[x], g[x]}, {x, 0, 3 Pi}, AxesLabel -> {x, y},
          MeshFunctions -> {f'[#] - g'[#] &}, Mesh -> {{0}},
          MeshStyle -> Directive[Red, PointSize[Large]],
          GridLines -> {xx, None}, Ticks -> {ticks, Automatic},
          AxesOrigin -> {0, 0}]


          enter image description here







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 5 at 7:25









          kglrkglr

          183k10202417




          183k10202417












          • $begingroup$
            How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 8:10










          • $begingroup$
            @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
            $endgroup$
            – kglr
            Feb 5 at 8:19


















          • $begingroup$
            How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 8:10










          • $begingroup$
            @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
            $endgroup$
            – kglr
            Feb 5 at 8:19
















          $begingroup$
          How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
          $endgroup$
          – Jacob Schwartz
          Feb 5 at 8:10




          $begingroup$
          How could you put $x_{0}, x_{1}, ..., x_{6}$ instead $x_{1}, x_{2}, ..., x_{7}$?
          $endgroup$
          – Jacob Schwartz
          Feb 5 at 8:10












          $begingroup$
          @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
          $endgroup$
          – kglr
          Feb 5 at 8:19




          $begingroup$
          @JacobSchwartz, replace ToString@#2[[1]] with ToString[#2[[1]] - 1].
          $endgroup$
          – kglr
          Feb 5 at 8:19











          2












          $begingroup$

          Something like this?



              Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[3]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          PlotLabels -> Placed[{"y=f(x)", "y=p(x)"}, {Scaled[5], Above}],
          AxesStyle -> Arrowheads[{0.0, 0.05}]]


          enter image description here



          Or



          Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[2]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          AxesStyle -> Arrowheads[{0.0, 0.05}],
          Epilog -> {Text[Style["y=f(x)", 22], Scaled[{0.5, 0.9}]],
          Text[Style["y=p(x)", 22], Scaled[{0.25, 0.97}]]}]


          enter image description here






          share|improve this answer











          $endgroup$













          • $begingroup$
            I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 7:56
















          2












          $begingroup$

          Something like this?



              Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[3]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          PlotLabels -> Placed[{"y=f(x)", "y=p(x)"}, {Scaled[5], Above}],
          AxesStyle -> Arrowheads[{0.0, 0.05}]]


          enter image description here



          Or



          Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[2]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          AxesStyle -> Arrowheads[{0.0, 0.05}],
          Epilog -> {Text[Style["y=f(x)", 22], Scaled[{0.5, 0.9}]],
          Text[Style["y=p(x)", 22], Scaled[{0.25, 0.97}]]}]


          enter image description here






          share|improve this answer











          $endgroup$













          • $begingroup$
            I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 7:56














          2












          2








          2





          $begingroup$

          Something like this?



              Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[3]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          PlotLabels -> Placed[{"y=f(x)", "y=p(x)"}, {Scaled[5], Above}],
          AxesStyle -> Arrowheads[{0.0, 0.05}]]


          enter image description here



          Or



          Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[2]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          AxesStyle -> Arrowheads[{0.0, 0.05}],
          Epilog -> {Text[Style["y=f(x)", 22], Scaled[{0.5, 0.9}]],
          Text[Style["y=p(x)", 22], Scaled[{0.25, 0.97}]]}]


          enter image description here






          share|improve this answer











          $endgroup$



          Something like this?



              Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[3]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          PlotLabels -> Placed[{"y=f(x)", "y=p(x)"}, {Scaled[5], Above}],
          AxesStyle -> Arrowheads[{0.0, 0.05}]]


          enter image description here



          Or



          Plot[{Sin[x] + 2, Sin[2 x] + 2}, {x, 0, 8}, AxesLabel -> {x, y}, 
          Ticks -> {{{1, "x[0]"}, {2, "x[1]"}, {3, ""}, {4, "x[2]"}, {5,
          ""}, {6, ""}, {7, "x[n]"}}, None},
          AxesStyle -> Arrowheads[{0.0, 0.05}],
          Epilog -> {Text[Style["y=f(x)", 22], Scaled[{0.5, 0.9}]],
          Text[Style["y=p(x)", 22], Scaled[{0.25, 0.97}]]}]


          enter image description here







          share|improve this answer














          share|improve this answer



          share|improve this answer








          edited Feb 5 at 7:41

























          answered Feb 5 at 7:24









          zhkzhk

          9,14911433




          9,14911433












          • $begingroup$
            I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 7:56


















          • $begingroup$
            I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
            $endgroup$
            – Jacob Schwartz
            Feb 5 at 7:56
















          $begingroup$
          I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
          $endgroup$
          – Jacob Schwartz
          Feb 5 at 7:56




          $begingroup$
          I put the functions Sin [x] +2, Sin [2x] +2 because I did not find others, but I would like others different from mine.
          $endgroup$
          – Jacob Schwartz
          Feb 5 at 7:56


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Mathematica Stack Exchange!


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


          Use MathJax to format equations. MathJax reference.


          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%2fmathematica.stackexchange.com%2fquestions%2f190905%2fhow-can-i-make-a-general-plot-like-this-in-mathematica%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

          Biblatex bibliography style without URLs when DOI exists (in Overleaf with Zotero bibliography)

          ComboBox Display Member on multiple fields

          Is it possible to collect Nectar points via Trainline?