1
$\begingroup$

I need help to check my code if my way to generate the gradient of a function that contains Legendre polynomials is correct or not.

if f is a function in θ and κ ,I need the gradient of f with respect to θ, where its derivative with respect to κ is zero because κ is a constant.The last equation to obtain gradient f is correct or there is another way?

Thanks in advance.

k = 0.70945`;
tl0 = -0.021720662277045163` - 0.007146744456323989` I;
tl1 = 0.00019355365528147435` + 6.204118924315627`*^-6 I;
tl2 = 0.0031603066656386166` + 0.0003213571906147552` I;
tl3 = 0.00019355365528147435` + 6.204118924315627`*^-6 I;
t = {tl0, tl1, tl2, tl3}
t // MatrixForm

kappa = 0.0814776349681311`;
 lmax = 3
θmax = 10;
 θarray = 
  Table[(π i)/θmax, {i, 0, θmax}] // N;


f = Sqrt[2/(k*\[Kappa])]*Sum[(2*l + 1)*t[[l + 1]]*LegendreP[l, Cos[\[Theta]array]], {l, 0, lmax}]

gradf = (1/\[Kappa])*Sqrt[2/(k*\[Kappa])]*Sum[(2*l + 1)*t[[l + 1]]*LegendreP[l, 1, Cos[\[Theta]array]], 
{l, 0, lmax}]
$\endgroup$
4
  • $\begingroup$ OK, but where the parameter θ is used? $\endgroup$ Dec 5, 2018 at 22:29
  • $\begingroup$ does your answer mean that my way is correct??I used θ as an array in Cosθ. I used LegendreP[n,m,z], where n=L,m=1,z=Cosθ to express dP[L,z]/dθ $\endgroup$
    – Ghady
    Dec 6, 2018 at 1:29
  • $\begingroup$ Please post code in InputForm; you may find this meta Q&A helpful. $\endgroup$
    – Michael E2
    Dec 6, 2018 at 1:58
  • $\begingroup$ Thanks Michael! Now, I posted in InputForm. $\endgroup$
    – Ghady
    Dec 6, 2018 at 2:26

1 Answer 1

4
$\begingroup$

One can directly verify that the derivative $dP_l(\cos(\theta))/d\theta $ and $P_l^1(\cos(\theta))$ coincide in the interval $(0,\pi ) $ using the well-known formula

fig1

Consequently

f = Sqrt[2/(k*\[Kappa])]*Sum[(2*l + 1)*t[[l + 1]]*LegendreP[l, Cos[\[Theta]array]], {l, 0, lmax}]
gradf = Sqrt[2/(k*\[Kappa])]*Sum[(2*l + 1)*t[[l + 1]]*LegendreP[l,1, Cos[\[Theta]array]], {l, 0, lmax}]
$\endgroup$
2
  • $\begingroup$ Thanks a lot Alex! $\endgroup$
    – Ghady
    Dec 6, 2018 at 14:24
  • $\begingroup$ @Ghady, you're welcome! $\endgroup$ Dec 6, 2018 at 15:29

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.