How to get diff from legendreP faster?
9 visualizaciones (últimos 30 días)
Mostrar comentarios más antiguos
I am trying to get differential from LegendreP, but it took me long time, for some data more that 12 hours !!!
syms mn
for n=1:1025
expr(n)=legendreP(n-1,cos(mn));
end
for n=1:1025
mmm(n)=diff(expr(n),mn,1);
end
teta=0:0.01:pi;
L=zeros(1025,315);
for i=1:length(teta)
L(:,i)=subs(mmm,teta(i));
end
LegendreP(n,cos(teta)) and first diff were considered. How can I have this one faster???? Thanks
1 comentario
Walter Roberson
el 30 de Nov. de 2015
I do not know at the moment why it might be slow. For whatever it is worth, mmm(n) should be
-n*(legendreP(n-1, cos(mn))*cos(mn) - legendreP(n, cos(mn)))/sin(mn)
This already takes into account that expr(n) is defined in terms of legendreP(n-1,cos(mn))
Respuestas (1)
Walter Roberson
el 30 de Nov. de 2015
I suggest trying
syms mn N
LPD = diff( legendreP(N, cos(mn)), mn );
teta = 0:0.01:pi;
L = zeros(1025,length(teta));
for n = 1:1025
mmm = matlabFunction( subs(LPD, N, n-1), mn );
L(n, :) = mmm(teta);
end
4 comentarios
Elvis Alexander Agüero Vera
el 16 de En. de 2023
And the main comment throws
Error using symengine
Unable to generate code for partial derivative 'D([2], orthpoly::legendre)(12,
cos(mn))'.
Error in sym/matlabFunction>mup2mat (line 404)
res = mupadmex('symobj::generateMATLAB',r.s,ano,spa,0);
Error in sym/matlabFunction>mup2matcell (line 382)
c = cellfun(@mup2mat,c,anonymousArgs,sparseArgs,'UniformOutput',false);
Error in sym/matlabFunction (line 188)
body = mup2matcell(funs, opts.Sparse);
Walter Roberson
el 16 de En. de 2023
Interesting, I am now seeing the same results that you post.
At the moment I do not recall whether I tested back in 2015; I will check if I have time.
Ver también
Categorías
Más información sobre Linear Algebra en Help Center y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!