Chebyshev Rational Approximation coding based on algorithm 8.2, Exercises of Computer Science

>Numerical Analysis_9th edition >page 537-536

Typology: Exercises

2019/2020

Uploaded on 06/29/2020

muhammad-ridhuan
muhammad-ridhuan 🇲🇾

1 document

1 / 3

Toggle sidebar

This page cannot be seen from the preview

Don't miss anything!

bg1
Chebyshev’s coding based on Algorithm
function [R] = ChebyshevRatApprox(f,m,n)
syms theta x
N = m+n;
a = zeros(1,N+m+1);
a(1) = (2/pi)*(int(f(cos(theta)),theta,[0 pi]));
for i = 2:N+m+1
a(i) = (2/pi)*(int(f(cos(theta))*cos((i-1)*theta),theta,[0 pi]));
end
p = zeros(1,n+1); q = zeros(1,m+1);
A = zeros(N+1); b = zeros(1,N+1);
q(1) = 1;
for i = 1:N+1
for j = 1:i
if j<=n+1
A(i,j) = 0;
end
if i<=n+1
A(i,i) = 1;
end
for j = i+1:n+1
A(i,j) = 0;
end
for j = n+2:N+1
if i~=1
if abs(i-j+n+1)==0
A(i,j) = -(a(i+j-n-1)+a(2))/2;
pf3

Partial preview of the text

Download Chebyshev Rational Approximation coding based on algorithm 8.2 and more Exercises Computer Science in PDF only on Docsity!

Chebyshev’s coding based on Algorithm function [R] = ChebyshevRatApprox(f,m,n) syms theta x N = m+n; a = zeros(1,N+m+1); a(1) = (2/pi)(int(f(cos(theta)),theta,[0 pi])); for i = 2:N+m+ a(i) = (2/pi)(int(f(cos(theta))cos((i-1)theta),theta,[0 pi])); end p = zeros(1,n+1); q = zeros(1,m+1); A = zeros(N+1); b = zeros(1,N+1); q(1) = 1; for i = 1:N+ for j = 1:i if j<=n+ A(i,j) = 0; end if i<=n+ A(i,i) = 1; end for j = i+1:n+ A(i,j) = 0; end for j = n+2:N+ if i~= if abs(i-j+n+1)== A(i,j) = -(a(i+j-n-1)+a(2))/2;

else A(i,j) = -(a(i+j-n-1)+a(abs(i-j+n+1)))/2; end else A(i,j) = -a(j-n)/2; end end if i~= b(i) = a(i); else b(i) = a(i)/2; end end end cc = A\b.'; CC = cc.'; p(1:n+1) = CC(1:n+1); q(2:m+1) = CC(n+2:N+1); for i=1:N+ T(i) = chebyshevT(i-1,x); end for i = 1:n+ P(i) = p(i)T(i); end for i = 1:m+ Q(i) = q(i)T(i); end