Plotting the zeros of jacobi polynomials

3 ビュー (過去 30 日間)
Catinca Mujdei
Catinca Mujdei 2019 年 9 月 3 日
コメント済み: Catinca Mujdei 2019 年 9 月 3 日
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 Center および File ExchangeCalculus についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by