# How can I plot a function defined as a derivative of another function?

How can I plot a function defined as a derivative of another function?

For example,

y[x_] := Sin[x]

y1[x_] := D[y[x], x]

Plot[y1[x], {x, 0, 2 Pi}]


doesn't work. What is wrong with this? (y[x_] may of course be a much more complicated function!)

• Like this: Plot[y'[x], {x, 0, 2 π}]. – J. M.'s torpor Jun 22 '16 at 6:00
• Welcome! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2) Take the tour and check the faqs! 3) When you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge. Remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign! – user9660 Jun 22 '16 at 7:52

You should pay attention to the differece of "=" and ":="

y[x_] := Sin[x]
y1[x_] = D[y[x], x]
Plot[y1[m], {m, 0, 2 Pi}]


then you can get the result

If you write in the form of

 y1[x_] := D[y[x], x]


the mathematica will calculate y[x] firstly to get a number, then the derivative will make no sense.

• Using := one should evaluate the right-hand side y1[x_] := Evaluate[D[y[x], x]]. – BoLe Jun 22 '16 at 9:23
• Or just Plot[y'[x], {x, 0, 2 \[Pi]}]. – murray Jun 22 '16 at 19:49

y[x_] := Sin[x]/x


Define a function as:

z = Function[x, Sin[x]/x]


Then plot:

Plot[{z[x], z'[x]}, {x, 0, 6 Pi},
PlotRange -> All]