Plotting the zeros of jacobi polynomials

3 views (last 30 days)
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

Answers (1)

Torsten
Torsten on 3 Sep 2019
  3 Comments
Torsten
Torsten on 3 Sep 2019
Edited: Torsten on 3 Sep 2019
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 on 3 Sep 2019
Thank you! It works. I also forgot to add an if statement to the function jacobirecursive in case n=0, which I now solved.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!