2

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!

DonkeyKong
  • 465
  • 1
  • 5
  • 16

1 Answers1

2

In your wrong version, your function uses x as a functional operator. When you input 1, df_wrong(1) is parsed as diff(f(1),1), which is nonsense: you cannot differentiate wrt. a constant.

The nice thing about the unapply functional 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 command x -> ... that makes x an operator of the entire right hand side.

Therkel
  • 1,379
  • 1
  • 16
  • 31