# Legendre polynomial Symbolic derivative

16 views (last 30 days)
IRFAN on 29 Apr 2011
I need to find derivative with respect to the argument of Associated Legendre functions symbolically . The following does not work:
x=sym('x', 'real');
q=sym('q', 'positive'); % harmonic index
t=sym('t', 'real');
x=cos(t);
P=legendre(q,x )% Associated Legendre function
P_1st_der=diff(P,x)
Can anyone help me?
Thanks
Irfan

Walter Roberson on 29 Apr 2011
That's a bit messy because the MUPAD legendre() function returns an array of all the associated Legendre values of order 0 to q.
When LegendreP(q, u, f(x)) is the associated Legendre function of degree q and order u, u from 0:q, then
diff(LegendreP(q, u, f(x)), x)
is
((q-u+1)*LegendreP(q+1, u, f(x))-(q+1)*f(x)*LegendreP(q, u, f(x)))*(diff(f(x), x))/(f(x)^2-1)
If x is a vector then that would probably have to be
((q-u+1)*LegendreP(q+1, u, f(x))-(q+1)*f(x).*LegendreP(q, u, f(x))).*(diff(f(x), x)) ./ (f(x).^2-1)
To construct an entire matrix of these symbolically over u = 0:q, you would have to throw in some repmat() on the portions having to do with f(x) appearing outside of your corresponding legendre() calls (since legendre() returns a matrix so you would have to copy f(x) q+1 times in order to do the element-wise multiplication and division)
It would be easier if you only needed one particular degree and order -- e.g.,
LegendreP(q+1, u, f(x))
would become
Lq1 = legendre(q+1,f(x));
then use
Lq1(u+1,:)
Walter Roberson on 29 Apr 2011
By the way, for the specific case of cos(t), then arbitrarily letting q=4, the matrix can be simplified to
[
-(35/16)*sin(4*t)-(5/8)*sin(2*t),
(5/4)*sqrt(cos(t)-1)*sqrt(cos(t)+1)*(7*cos(4*t)+cos(2*t))/sin(t),
-(105/4)*sin(4*t)+(15/2)*sin(2*t),
210*(cos(t)+1)^(3/2)*(cos(t)-1)^(3/2)*(cos(2*t)+1/2)/sin(t),
-(105/2)*sin(4*t)+105*sin(2*t)
]
with the entries corresponding to u=0..4
for q=15, the matrix comes out as the uglier
[
-(42902475/33554432)*sin(11*t)-(30421755/33554432)*sin(9*t)-(2760615/33554432)*sin(t)-(21603855/33554432)*sin(7*t)-(14549535/33554432)*sin(5*t)-(145422675/33554432)*sin(15*t)-(65189475/33554432)*sin(13*t)-(8423415/33554432)*sin(3*t),
(15/33554432)*sqrt(cos(t)-1)*sqrt(cos(t)+1)*(18253053*cos(9*t)+31461815*cos(11*t)+4849845*cos(5*t)+10081799*cos(7*t)+56497545*cos(13*t)+145422675*cos(15*t)+184041*cos(t)+1684683*cos(3*t))/sin(t),
-(42902475/16777216)*sin(11*t)+(1186448445/16777216)*sin(9*t)+(1533873705/16777216)*sin(7*t)+(1382205825/16777216)*sin(5*t)-(15269380875/16777216)*sin(15*t)-(3194284275/16777216)*sin(13*t)+(328513185/16777216)*sin(t)+(934999065/16777216)*sin(3*t),
(154729710135/1048576)*(cos(t)-1)^(3/2)*(cos(t)+(605245/987844)*cos(11*t)+(316825/987844)*cos(13*t)+(1208305/1481766)*cos(9*t)+(24073/24492)*cos(5*t)+(125419/134706)*cos(7*t)+(627/628)*cos(3*t))*(cos(t)+1)^(3/2)/sin(t),
(302544353475/4194304)*sin(13*t)-(595505854125/4194304)*sin(15*t)-(24661461825/4194304)*sin(5*t)-(41771714985/4194304)*sin(3*t)+(48414239055/4194304)*sin(7*t)+(173312738235/4194304)*sin(9*t)-(18725251545/4194304)*sin(t)+(306194964075/4194304)*sin(11*t),
(218243025/262144)*(cos(t)-1)^(5/2)*(cos(t)+1)^(5/2)*(88665*cos(9*t)+30015*cos(11*t)+158125*cos(7*t)+220363*cos(5*t)+264550*cos(3*t)+286858*cos(t))/sin(t),
(55792738126125/2097152)*sin(13*t)-(32752821976875/2097152)*sin(15*t)-(4926836289375/2097152)*sin(5*t)+(2369464522425/2097152)*sin(3*t)-(16329597859575/2097152)*sin(7*t)-(18657814450275/2097152)*sin(9*t)+(1966151412225/2097152)*sin(t)+(5797625959125/2097152)*sin(11*t),
(654729075/32768)*(cos(t)-1)^(7/2)*(cos(t)+1)^(7/2)*(1584585*cos(7*t)+450225*cos(9*t)+3134900*cos(5*t)+4565316*cos(3*t)+5403790*cos(t))/sin(t),
(995459906566125/262144)*sin(13*t)-(294775397791875/262144)*sin(15*t)+(260893168160625/262144)*sin(5*t)+(10435726726425/262144)*sin(3*t)+(292938228007425/262144)*sin(7*t)-(304533479925675/262144)*sin(9*t)-(45221482481175/262144)*sin(t)-(829060512154875/262144)*sin(11*t),
(316234143225/1024)*(cos(t)-1)^(9/2)*(cos(t)+1)^(9/2)*(23535*cos(5*t)+6525*cos(7*t)+45125*cos(3*t)+59983*cos(t))/sin(t),
(34224440150525625/131072)*sin(13*t)-(6190283353629375/131072)*sin(15*t)-(21654132957331875/131072)*sin(5*t)-(7044115540336875/131072)*sin(3*t)+(14333312541673125/131072)*sin(7*t)+(46747312222235625/131072)*sin(9*t)+(3391611186088125/131072)*sin(t)-(67919188111149375/131072)*sin(11*t),
(7905853580625/128)*(cos(t)-1)^(11/2)*(cos(t)+1)^(11/2)*(12591*cos(3*t)+3915*cos(5*t)+20102*cos(t))/sin(t),
(252520869218743125/32768)*sin(13*t)-(30951416768146875/32768)*sin(15*t)+(152622503373965625/32768)*sin(5*t)+(396818508772310625/32768)*sin(3*t)-(1223754981598524375/32768)*sin(7*t)+(1473500896210468125/32768)*sin(9*t)-(91573502024379375/32768)*sin(t)-(852337980380761875/32768)*sin(11*t),
(213458046676875/8)*(cos(t)-1)^(13/2)*(cos(t)+1)^(13/2)*(1021*cos(t)+435*cos(3*t))/sin(t),
(1046157886763364375/16384)*sin(13*t)-(92854250304440625/16384)*sin(15*t)-(5243170000524080625/16384)*sin(11*t)+(15209526199867374375/16384)*sin(9*t)-(27602473473833383125/16384)*sin(7*t)+(30982368184915021875/16384)*sin(5*t)-(18589420910949013125/16384)*sin(3*t)+(2655631558707001875/16384)*sin(t),
92854250304440625*(cos(t)-1)^(15/2)*(cos(t)+1)^(15/2)*cos(t)/sin(t)
]