Plotting the zeros of jacobi polynomials

3 次查看(过去 30 天)
I would like to plot the zeros of jacobi polynomials of increasing degree, for which I have made the two functions at the bottom of this question.
Whenever I try to run "jacobiroots(50,1,2,3)", I get the error "Undefined function 'sym2poly' for input arguments of type 'function_handle'. Error in jacobiroots (line 7) coeff=sym2poly(p);". It's been a long time since I've worked with MATLAB so I don't really see how to solve this.
Thank you in advance!
function jacobiroots(n,a,b,c)
syms x
for k=1:n
p=jacobirecursive(a*k,-(a+b)*k,(b+c)*k);
coeff=sym2poly(p);
r=roots(coeff);
scatter(real(r),imag(r),'filled','red');
title(k);
pause(0.3)
end
end
function output = jacobirecursive(n,alfa,beta)
if n==1
output = @(x) (alfa+1)+(alfa+beta+2)*(x-1)/2;
else
first = (2*n+alfa+beta-1)*((2*n+alfa+beta)*(2*n+alfa+beta-2)*x+alfa^2-beta^2);
second = 2*(n+alfa-1)*(n+beta-1)*(2*n+alfa+beta);
denom = 2*n*(n+alfa+beta)*(2*n+alfa+beta-2);
output = @(x) (first*jacobirecursive(n-1,alfa,beta)-second*jacobirecursive(n-2,alfa,beta))/denom;
end
end

回答(1 个)

Torsten
Torsten 2019-9-3
  3 个评论
Torsten
Torsten 2019-9-3
编辑:Torsten 2019-9-3
I don't have MATLAB available, but this might work:
function jacobiroots(n,a,b,c)
for k=1:n
p=jacobirecursive(a*k,-(a+b)*k,(b+c)*k);
coeff=sym2poly(p);
r=roots(coeff);
scatter(real(r),imag(r),'filled','red');
title(k);
pause(0.3)
end
end
function output = jacobirecursive(n,alfa,beta)
syms x
if n==1
output = (alfa+1)+(alfa+beta+2)*(x-1)/2;
else
first = (2*n+alfa+beta-1)*((2*n+alfa+beta)*(2*n+alfa+beta-2)*x+alfa^2-beta^2);
second = 2*(n+alfa-1)*(n+beta-1)*(2*n+alfa+beta);
denom = 2*n*(n+alfa+beta)*(2*n+alfa+beta-2);
output = (first*jacobirecursive(n-1,alfa,beta)-second*jacobirecursive(n-2,alfa,beta))/denom;
end
end
Catinca Mujdei
Catinca Mujdei 2019-9-3
Thank you! It works. I also forgot to add an if statement to the function jacobirecursive in case n=0, which I now solved.

请先登录,再进行评论。

类别

Help CenterFile Exchange 中查找有关 Calculus 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by