Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Please solve in python code! When working with functions on finite domains, it is often convenient to approximate the function as a polynomial. The reason

Please solve in python code!

image text in transcribed

image text in transcribedimage text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

When working with functions on finite domains, it is often convenient to approximate the function as a polynomial. The reason is that the rules of calculus are much easier when working with polynomials than with general functions. Now, an nth-order polynomial p(x)=a0+a1x+a2x2+anxn is uniquely defined by n+1 point, which specify the n+1 coefficients of the polynomial. Therefore, we can find an approximating polynomial of order n by fitting it to n+1 points of the original function. Now, it turns out that approve polynomial representation is not numerically stable, especially when working with higher-order polynomials. better solution is to use Chebyshev polynomials. which have the form p(x)=c0T0+c1T1(x)+c2T2(x)++cnTn(x) where Ti(x) is a Chebychev polynomial of order i. These polynomials (of the first kind) are defined as: T0(x)=1T1(x)=xT2(x)=2x21Tn(x)=2xTn1(x)Tn1(x) In addition to using a different form of the polynomial, it also matters how we choose the n+1 points, known as collocation points, for fitting the polynomial to the function: (e.g. f(xi)=p(xi) for i=0,,n). If we assume that the domain is [1,1] (good for numerical stability), the optimal choice of n+1 points is xi=cos(i for i=0,,n. We can then fit a Chebychev polynomial to a function as illustrated in the code below. as illustrated in the code below: This code with generate the figure below (note that the two curves overlap). In general, more points yields a better fit to the function though at some point you will run into numerical issues. Given a polynomial representation of the function, we can determine the functions derivative and integral using the functions (chebder) and chebint, respectively. Similar to Homework 2 , these functions return the coefficients for the derivative and integral of the polynomial. Now, you task is to plot the derivative of the function f(x)=sin2(6x) on the domain [1,1] by fitting the function f(x) is a Chebyshev polynomial of order n. Then use chebdev to determine the derivative of f(x). First, compare the exact derivative (df(x)=12sin(6x)cos(6x)) to the one generated using a 10 th order Chebyshev polynomial. You should generate the following plot. Next, compare the accuracy of the derivative for various values of n. The error is given by the maxidf(xi)pd(xi) for 1000 equally spaced points between 1 and 1 . Here, df(x) refers to the exact derivative and pd(x) the approximate one determined using chebder. You should generate the following plot. Notice how fast the error decreases with increasing n. This is known as spectral accuracy. Last, use chebint to determine the integral: 11sin2(6x)dx The exact integral is given by 2x241sin(12x). Compare the results for the definite integral using chebint versus the exact answer (do not use quad) as a function of n. You should generate the following plot (where the error is the absolute value of the exact and approximate answer). Notice again how fast the error decreases with increasing n. When working with functions on finite domains, it is often convenient to approximate the function as a polynomial. The reason is that the rules of calculus are much easier when working with polynomials than with general functions. Now, an nth-order polynomial p(x)=a0+a1x+a2x2+anxn is uniquely defined by n+1 point, which specify the n+1 coefficients of the polynomial. Therefore, we can find an approximating polynomial of order n by fitting it to n+1 points of the original function. Now, it turns out that approve polynomial representation is not numerically stable, especially when working with higher-order polynomials. better solution is to use Chebyshev polynomials. which have the form p(x)=c0T0+c1T1(x)+c2T2(x)++cnTn(x) where Ti(x) is a Chebychev polynomial of order i. These polynomials (of the first kind) are defined as: T0(x)=1T1(x)=xT2(x)=2x21Tn(x)=2xTn1(x)Tn1(x) In addition to using a different form of the polynomial, it also matters how we choose the n+1 points, known as collocation points, for fitting the polynomial to the function: (e.g. f(xi)=p(xi) for i=0,,n). If we assume that the domain is [1,1] (good for numerical stability), the optimal choice of n+1 points is xi=cos(i for i=0,,n. We can then fit a Chebychev polynomial to a function as illustrated in the code below. as illustrated in the code below: This code with generate the figure below (note that the two curves overlap). In general, more points yields a better fit to the function though at some point you will run into numerical issues. Given a polynomial representation of the function, we can determine the functions derivative and integral using the functions (chebder) and chebint, respectively. Similar to Homework 2 , these functions return the coefficients for the derivative and integral of the polynomial. Now, you task is to plot the derivative of the function f(x)=sin2(6x) on the domain [1,1] by fitting the function f(x) is a Chebyshev polynomial of order n. Then use chebdev to determine the derivative of f(x). First, compare the exact derivative (df(x)=12sin(6x)cos(6x)) to the one generated using a 10 th order Chebyshev polynomial. You should generate the following plot. Next, compare the accuracy of the derivative for various values of n. The error is given by the maxidf(xi)pd(xi) for 1000 equally spaced points between 1 and 1 . Here, df(x) refers to the exact derivative and pd(x) the approximate one determined using chebder. You should generate the following plot. Notice how fast the error decreases with increasing n. This is known as spectral accuracy. Last, use chebint to determine the integral: 11sin2(6x)dx The exact integral is given by 2x241sin(12x). Compare the results for the definite integral using chebint versus the exact answer (do not use quad) as a function of n. You should generate the following plot (where the error is the absolute value of the exact and approximate answer). Notice again how fast the error decreases with increasing n

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction To Chemical Engineering Fluid Mechanics

Authors: William M. Deen

1st Edition

1107123771, 9781107123779

More Books

Students also viewed these Chemical Engineering questions

Question

Determine miller indices of plane A Z a/2 X a/2 a/2 Y

Answered: 1 week ago