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.

$\endgroup$
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

$\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

$\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

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.