Hamzaan

5 Reputation

One Badge

11 years, 223 days

MaplePrimes Activity


These are questions asked by Hamzaan

Hi

Long story short I had a detailed question and then the session timed out and killed it!

Quickly then, if we calculate something recursively Maple acts differently to other languages.

For example, in Python:

__________________________________________

>>>t=1;

>>>t+=1;

>>>print t;

___________________________________________

Is interpreted as:

__________________________________________

>>>t=1;

>>>t=t+1=2

>>>print t

2

___________________________________________

In Maple:

___________________________________________

>t:=1

>t:=t+1

>print(t)

___________________________________________

Is Interpreted as:

___________________________________________

>t=1

>t=t+1=1+1=2

>print(t); t=t+1=1+1=2

2

____________________________________________
And there in lies my problem. Logically, I wish to use a iterative algorithm to work out an expression of the nth derivative of a function from the (n-1) derivative. However, doing this is in maple brings up "error (in Test) too many levels of recursion".

 

For context, Minimum Working Example:

____________________________________________

>TestFunction:=(x)->cos(exp(-1/x^2))*F(x):

>limit(TestFunction(x),x=0)

F(0)

>TestDerivative:=(x)->eval(diff(TestFunction(y),y),y=x):

>limit(TestDerivative(x),x=0)

D(F)(0)

>for i from 1 to 50 do
print(D^(i)(TestFunction)(0)=limit(TestDerivative(x),x=0));

TestDerivative:=(x)->eval(diff(TestDerivative(y),y),y=x):

od:

D(TestFunction)(0)=D(F)(0)

Error, (in TestDerivative) too many levels of recursion

_______________________________________________

Ideally, this code would output the limit of the second derivative at zero by differentiating the first derivative and then the limit of the third derivative at zero by differentiating the second derivative etc. But what Maple is trying to do is to find the limit of the second derivative by differentiating the function then differentiating the result of that, then to find the limit of the third derivative it will first derivative by differentiate the function, then the second by differentiating the result, then third derivative by differentiating the result of that. If I have the analytic expression for the 5th derivative and I wanted the expression for the 6th derivative, I do not want to work out the 1st, 2nd, 3rd, 4th and then 5th derivative when I've already an of the expression of the 5th derivative!

I will note, it is possible to avoid the problem by using different names at each step but that does not solve the iterative problem.  Is there anyway to force maple to overwrite a function name? Is there a seperate solution? Or is maple just that daft in this case?

 

Thanks for the help,

Hamzaan

Page 1 of 1