I am an absolute beginner in maple and have problems to understand the following:
The following does not work:
f:=(x)->x^2;
df_wrong:=(x)->diff(f(x),x);
Since df_wrong(1); always yields the following "Error, (in df_wrong) invalid input: diff received 1, which is not valid for its 2nd argument
". After some time I found that the following solves this:
df_correct := unapply(diff(f(x), x), x);
Since df_correct(1);. Could anyone explain me what is the problem the problem in using df_wrong and maybe why unapply() solves these?
I have checked the Maple explanation of unapply(), but it is somehow still not very clear to me.
Thanks in advance!
In your wrong version, your function uses
xas a functional operator. When you input1,df_wrong(1)is parsed asdiff(f(1),1), which is nonsense: you cannot differentiate wrt. a constant.The nice thing about the
unapplyfunctional is that it returns a functional operator. This means you can manipulate things and then use it as an operator. This is in contrast to the operator assign commandx -> ...that makesxan operator of the entire right hand side.