MathGroup Archive 2004

[Date Index] [Thread Index] [Author Index]

Search the Archive

AW: Plotting a function and its derivative

  • To: mathgroup at
  • Subject: [mg49507] AW: [mg49478] Plotting a function and its derivative
  • From: Matthias.Bode at
  • Date: Thu, 22 Jul 2004 02:45:40 -0400 (EDT)
  • Sender: owner-wri-mathgroup at

Hello Adrian,

this might get you started:

f[x_] = x^2
d[x_] = D[f[x], x]
Plot[{f[x], d[x]}, {x, -3, 3}]

Best regards,
Matthias Bode
Sal. Oppenheim jr. & Cie. KGaA
Untermainanlage 1
D-60329 Frankfurt am Main
Tel.: +49(0)69 71 34 53 80
Mobile: +49(0)172 6 74 95 77
Fax: +49(0)69 71 34 95 380
E-mail: matthias.bode at

-----Ursprüngliche Nachricht-----
Von: adrian sky [mailto:skaai at] 
Gesendet: Mittwoch, 21. Juli 2004 12:40
An: mathgroup at
Betreff: [mg49478] Plotting a function and its derivative

first of all, thanks for reading this message, i would imagine this is 
a beginner level question, and sorry if this was answered previously, 
im still getting the hang of proper searches in a mathematical forum.

anyways, what i'm trying to do is illustrate the simplest of 
derivatives in the form of a graph but i am getting errors.

the function i'm trying to derive is x^2
its derivative i'm trying to illustrate is 2x

i would like to set up a graph which allows me to determine the 
argument (be it x^2 or x^4+1), calculate its derivative, and graph them 
so as to illustrate their relationship.

i know that the derivative can be graphed at any x value, and as far as 
this is concerned, the value can be anything, probably a small value to 
keep the graph manageable.

anyways, i'm inputting this:
f[x_] := x^2; d[x_] := _x f[x]
which supposedly should assign the f(x) a value of ^2 and d(x) a value 
of the derivative of f(x)

i can even type f(x) and get back the value x^2 and d(x) gives me 2x, 
so it seems the system understands and assigns the requested values

but when I try to plot this with the command:
Plot[{f[x], d[x]}, {x, -5, 5}]
i get numerous errors and only get the graph of x^2
the errors are:
General::ivar: -5. is not a valid variable.
Plot::plnr: d[x] is not a machine-size real number at x = 
Plot::plnr: d[x] is not a machine-size real number at x = 
and a few more similar plot errors

anyways, to simplify my question, how to i plot a function (like x^2) 
and its derivative (like 2x) and apply its derivative to any part of 
the function (like x=3) so as to show the tangent line which should 
touch the function? i thought my way should have worked, but it seems 
the d(x) is the troublesome function, since without it, i get a graph 
of the function (albeit without the derivative).....

many thanks for looking this question over!

adrian sky

For a man to attain to an eminent degree in learning costs him time, 
watching, hunger, nakedness, dizziness in the head, weakness in the 
stomach, and other inconveniences. - Miguel De Cervantes

  • Prev by Date: Re: Plotting a function and its derivative
  • Next by Date: RE: Plotting a contour plot with cylindrical co-ordinates
  • Previous by thread: RE: Quantum Mechanics, Boundary Value Problem
  • Next by thread: Fundamental theorem problem