3
$\begingroup$

I have 2 rules of recursive relation of the derivative, I want to use it several times get the higher derivative on [\Theta] of P[\[Theta],n,m] only expressed by P[\[Theta], n, m] and P[\[Theta], n-1, m]. (Yes, P is Associated Legendre polynomials here)

This is my rule (Sorry, I don't know how to wrap this long line of code):

rule1 = D[P[\[Theta], n, m], {\[Theta], i}] :> D[D[P[\[Theta], n, m], {\[Theta], i - 1}], {\[Theta], 1}];(*i>=2*)
rule2 = D[P[\[Theta], n, m], {\[Theta], 1}] :> 1/Sin[\[Theta]] (n Cos[\[Theta]]*P[\[Theta], n, m] - (n + m) P[\[Theta], n - 1, m]);
rule = {rule1, rule2};

Then I use this first code and it return the needed result.

D[P[\[Theta], n, m], {\[Theta], 1}] //. rule

However, the higher derivative on [\Theta] canot work. How to the let it works?

D[P[\[Theta], n, m], {\[Theta], 2}] //. rule (* return with calcuation *)

We can make rule 1 execute first, consider rule 2 during the compute, and repeat the process to get what I want. But how to implement it in code?

Another try (Try these two rules in each calculation step) :

r1 = D[P[\[Theta], n_, m], {\[Theta], 1}] :> (1/Sin[\[Theta]] (n Cos[\[Theta]]*P[\[Theta], n, m] - (n + m) P[\[Theta], n - 1, m]));
r2 = D[P[\[Theta], n_, m], {\[Theta], i_}] :> (D[D[P[\[Theta], n, m], {\[Theta], i - 1}] /. r1, \[Theta] ] /. r1);(*i>=2*)
D[P[\[Theta], n, m], {\[Theta], 2}] /. r2 (* Out contains P[\[Theta], -2 + n, m], This is not what you want to see *)
D[P[\[Theta], n, m], {\[Theta], 3}] /. r2 (* Nothing changed *)
$\endgroup$

1 Answer 1

4
$\begingroup$

Your problem is that MMA simplifies the exprerssion D[D[P[\[Theta], n, m], {\[Theta], i - 1}], {\[Theta], 1}]at once to D[P[\[Theta], n, m], {\[Theta], i}]. And you are where you started. To prevent this, we may formulate it in a recursive way. E.g.:

Clear["Global`*"]
p[1] = 1/
   Sin[\[Theta]] (n Cos[\[Theta]]*
     P[\[Theta], n, m] - (n + m) P[\[Theta], n - 1, m])
p[i_] := D[p[i - 1], \[Theta]];

Now with this we get e.g.:

p[2]

enter image description here

Or

p[3]

enter image description here

A new editon base on the previous method

ClearAll[f];
f[1,n_,m_,\[Theta]_]:=1/Sin[\[Theta]] (n Cos[\[Theta]]*f[0,n,m,\ 
 [Theta]]-(n+m)f[0,n-1,m,\[Theta]]);(*Eq.(8) at 
 https://mathworld.wolfram.com/AssociatedLegendrePolynomial.html*)
 f[j_,n_,m_,\[Theta]_]:=FullSimplify@((D[f[j-1,n,m,\[Theta]],\ 
 [Theta]])//.{
    (*(f^(0,0,0,1))[j-2,n,m,\[Theta]]:>f[j-1,n,m,\[Theta]],
    (f^(0,0,0,1))[j-2,-1+n,m,\[Theta]]:>f[j-1,-1+n,m,\[Theta]],*)
    (f^(0,0,0,1))[0,n,m,\[Theta]]:>f[1,n,m,\[Theta]],
    (f^(0,0,0,1))[0,-1+n,m,\[Theta]]:>f[1,-1+n,m,\[Theta]],
    f[0,-2+n,m,\[Theta]]:>((-1+2 n) Cos[\[Theta]] f[0,-1+n,m,\[Theta]]+ 
    (m-n)f[0,n,m,\[Theta]])/(-1+m+n)
    })/;j>=2;

Try

    Table[f[j, n, m, \[Theta]], {j, 0, 4}] // TableForm

The out put is: enter image description here The above code works, but how to simplify them (Are there redundant items in the replacement rule??)?

$\endgroup$
1
  • $\begingroup$ Thank you @Daniel Huber. I modeyied your good answer to further simplify the results. $\endgroup$
    – He Tang
    Feb 22, 2023 at 5:23

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.