Maple: assign derivative to function This is probably a basic Maple question.  I'm trying to introduce $g$ as the derivative of $f$:

Somewhat puzzling, Maple now says $g$ is two times the function $x()$.
I've tried g := x -> diff(f(x),x) and g := diff(f,x), but no luck. Google tells me I can use subs(x=3,g) to evaluate the derivative at $x=3$, but that's not very practical.
Is there a way to define a Maple function as the derivative of another Maple function?
 A: Use D (capital D): g:= D(f); This is the functional derivative operator.
In your case:
f:=x->x^2;
g:=D(f);
g(3);

A: The answer worked for the OP, but I have had trouble getting "D" to behave the way I want it to.  I found a solution using "unapply".  If the function is named f, then
fp:= unapply(diff(f(x),x),x) 

creates a function fp that's the derivative of f.  diff(f(x), x) is an expression, and unapply converts it to a function of x.
This can also be done for functions of several variables (see Maplesoft's documentation for unapply here: https://www.maplesoft.com/support/help/maple/view.aspx?path=unapply)
UPDATE: Hey there, in case anyone else feels compelled to suggest this be deleted, yes I know what "D" does.  It might do what you want most of the time.  But I've written code where "D" didn't behave the way I wanted to.  unapply is a decent workaround.  I see several other Maple users suggesting it in this Maple forum.  One of them wrote "I find that in some situations D seems a little stupid, so often I prefer diff with unapply."
If you think there's something wrong with my answer, then a comment might be nice.  This workaround has worked for me and others when "D" didn't.
A: To answer the original poster above, what you have defined g:=diff(f(x),x) is actually an expression, not a function. Therefore g(3) is equivalent to 2x(3) because Maple thinks you want to multiply g and 3 or 2x(3). Maple does not not what else to do with it.  
But why doesn't Maple allow you to evaluate g(3) when g and f are defined previously as
g:=x->diff(f(x),x)and f:=x->x^2. This is more interesting; you have defined here a valid function. Maple takes the 3 and evaluates diff(f(3),3) which is equivalent to diff(9,3). This is not a valid derivative, the second argument must be a variable.
At some point you have to use the subs command if you go on to make more complicated derivative expressions or functions.
