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
0 个评论
回答(1 个)
Torsten
2019-9-3
3 个评论
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
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Calculus 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!