       Re: Plotting a function and its derivative

• To: mathgroup at smc.vnet.net
• Subject: [mg49487] Re: Plotting a function and its derivative
• From: BobHanlon at aol.com
• Date: Thu, 22 Jul 2004 02:44:51 -0400 (EDT)
• Sender: owner-wri-mathgroup at wolfram.com

```f[x_] := x^2;

d[x_] := Evaluate[D[f[x], x]];

Plot[{f[x],f'[x]},{x,0,2}];

Plot[{f[x],d[x]},{x,0,2}];

d==f'

True

Bob Hanlon

> In a message dated Wed, 21 Jul 2004 11:17:20 +0000 (UTC), <
> skaai at earthlink.net> writes: 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_] := =B6_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 =
> -4.9999995833333335`
> Plot::plnr: d[x] is not a machine-size real number at x =
> -4.594330084270842`
> 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).....
>

```

• Prev by Date: RE: If-statement problems
• Next by Date: RE: rounding
• Previous by thread: Plotting a function and its derivative
• Next by thread: Re: Plotting a function and its derivative