Answered step by step
Verified Expert Solution
Question
1 Approved Answer
%% composite simpsons rule code for part 1 function XI = simpson(f,a,b,n) h=(b-a); XI0=f(a)+f(b); XI1=0; XI2=0; for i=1:n-1 X=a+i*h; if mod(i,2)==0 XI2=XI2+f(X); else XI1=XI1+f(X); end
%% composite simpsons rule code for part 1
function XI = simpson(f,a,b,n) h=(b-a); XI0=f(a)+f(b); XI1=0; XI2=0; for i=1:n-1 X=a+i*h; if mod(i,2)==0 XI2=XI2+f(X); else XI1=XI1+f(X); end end XI=h*(XI0+2*XI2+4*XI1)/3;
The aim of this lab is to implement and test the accuracy of Chebyshev polynomial approximations 1 Given f(x, write a function to calculate the Nth Chebyshev polynomial P(x). Hint: You will need to approximate an integral. Use your code of the composite Simpson's rule. Also substitute x-cos . (What happens if you don't substitute x?) Your function should use the same order of input below. function y-chebyshev (f,N,x) % f function handle to be approximated % N degree of the Chebyshev polynomial, P(x) % x - x-coordinate to cacuate P(x) % your implementation below end 2) Create a script 'main.m' that does the following. First, compute the Chebyshev polynomial of f(x)-e* over the interval [-1,1], for N = 2,3,4,5. Plot the error as a function of N. what's the smallest N so that the error is less than 106? Note that the error here is o(x)lP(x) - f(x)l2 dx. Ca You can also use composite Simpson's rule to calculate this error. 3) Consider the sign function sign (x).Compute its Chebyshev polynomial approximation over the interval [-1,1], for N 2,3,4,5. Then, plot these polynomials together with sign (x). Describe the result. Can one make the error as small as one likes by increasing N? The aim of this lab is to implement and test the accuracy of Chebyshev polynomial approximations 1 Given f(x, write a function to calculate the Nth Chebyshev polynomial P(x). Hint: You will need to approximate an integral. Use your code of the composite Simpson's rule. Also substitute x-cos . (What happens if you don't substitute x?) Your function should use the same order of input below. function y-chebyshev (f,N,x) % f function handle to be approximated % N degree of the Chebyshev polynomial, P(x) % x - x-coordinate to cacuate P(x) % your implementation below end 2) Create a script 'main.m' that does the following. First, compute the Chebyshev polynomial of f(x)-e* over the interval [-1,1], for N = 2,3,4,5. Plot the error as a function of N. what's the smallest N so that the error is less than 106? Note that the error here is o(x)lP(x) - f(x)l2 dx. Ca You can also use composite Simpson's rule to calculate this error. 3) Consider the sign function sign (x).Compute its Chebyshev polynomial approximation over the interval [-1,1], for N 2,3,4,5. Then, plot these polynomials together with sign (x). Describe the result. Can one make the error as small as one likes by increasing NStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started