Message Boards Message Boards

0
|
2588 Views
|
7 Replies
|
4 Total Likes
View groups...
Share
Share this post:

Plot functions and their guide function images into same coordinate system

Posted 2 years ago

In order to study characteristics such as the monotonic value range of a function, it is necessary to draw the function and its guide function into the same coordinate system. for example: use this code can plot the function

Plot[E^x (1 + x) + Cos[x], {x, -2, 2}]

enter image description here

use such code can solve its guide function

\!\(
\*SubscriptBox[\(\[PartialD]\), \(x\)]\((
\*SuperscriptBox[\(E\), \(x\)]\ \((1 + x)\) + Cos[x])\)\)

and plot it

enter image description here

but how to when i input a function then the mathematica can solve its guide function ,and last draw the two function's images into the same coordinate. thx

POSTED BY: Lee Tao
7 Replies
Posted 2 years ago

If you know how to differentiate then it is quite clear from the labels which order each curve corresponds to. Both can be displayed but the labels become long and high. The code is quite messy, good practice for you to refactor it to make it cleaner. Maybe you just want to display a number corresponding to the order rather than the differential operator, you can easily change the code to do that. Or maybe add a Tooltip to show the order, there are many possibilities....

Manipulate[
 Refresh[
  functions = Table[D[f[x], {x, n}], {n, 0, nMax, 1}];
  orders = 
   Table[D[f[x], {x, n}] // Inactivate // TraditionalForm // ToString, {n, 0, nMax, 1}];
  labels = MapThread[#1 <> " = " <> ToString[#2, TraditionalForm] &, {orders, functions}];];
 Plot[functions, {x, -2, 2},
  PlotLabels -> labels,
  PlotRange -> All,
  ImageSize -> 700,
  AspectRatio -> 1,
  PlotLabel -> Row[{"f(x) = ", f[x]}]],
 {{nMax, 1, "Order"}, 1, 5, 1, PopupMenu}]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thank you very much. That's what I want.

POSTED BY: Lee Tao
Posted 2 years ago

Specifically, it shows the function analytical expression of the derivative function in the image, and at the same time, it also shows the order of the derivative function of the original function. thx

POSTED BY: Lee Tao
Posted 2 years ago

Sure. It can be made interactive, pick the number of orders you want to show.

Manipulate[
 Plot[Evaluate@Table[D[f[x], {x, n}], {n, 0, nMax, 1}], {x, -2, 2},
  PlotLabels -> Automatic,
  PlotRange -> All,
  ImageSize -> 500],
 {{nMax, 1, "Order"}, 1, 5, 1, PopupMenu}]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thank you very much! The result is beyond imagination!

However, there is still an obvious problem: the derivatives of the original function are not identified, that is, the function signature in the image does not show that the derivative function is the derivative function of the original function. Can you display the derivative function and show which derivative function it is at the same time? Thanks again!

POSTED BY: Lee Tao
Posted 2 years ago

Hi Lee,

Something like this?

ClearAll@f;
f[x_] := E^x (1 + x) + Cos[x]

Plot[{f[x], Evaluate@D[f[x], x]}, {x, -2, 2}, PlotLabels -> Automatic]

enter image description here

POSTED BY: Rohit Namjoshi
Posted 2 years ago

Thank you! It is this effect. Further words, if the second-order guidance function of the function is to draw the same coordinate system?

POSTED BY: Lee Tao
Reply to this discussion
Community posts can be styled and formatted using the Markdown syntax.
Reply Preview
Attachments
Remove
or Discard

Group Abstract Group Abstract