Question

In: Advanced Math

In Matlab (diary on), do the following: 1. Generate N+1=11 equi-spaced nodes Xi in the interval...

In Matlab (diary on), do the following: 

1. Generate N+1=11 equi-spaced nodes Xi in the interval [−5,5]:
         X = [-5:1:5];    (to see values, omit the ;)
   or    X = linspace(-5,5,11);
   and evaluate f(x) at these nodes:
         Y = 1./(1+X.^2);
   The N+1 points (Xi, Yi) are the data points to be interpolated by various methods. 
   Plot them to see where they are:
         plot(X,Y,'o')
         title('N+1 = 11 equi-spaced points of Runge function')
         pause 

   Also generate lots of points xi at which to evaluate f(x) and the interpolants for plotting:
         x = [-5:0.1:5];   (this is a lower case x, not X)
   Evaluate f(x) at these xi's and plot y=f(x) and the data points:
         plot(x,y,'-', X,Y,'o')
         title('Runge f(x) and data pts')
         pause 

Now, we use the data points (Xi, Yi) to construct various interpolants.
A good interpolant should "reproduce" the function f(x) as close as possible. 
Let's try a few.


2. Nth degree interpolating polynomial:
   Use Matlab's polyinterp to construct (the coefficients of) the Nth degree interpolating polynomial (here N=10):
         pN = polyfit( X,Y, N); 
   Now this can be evaluated anywhere in the interval [-5,5] with polyval, e.g. at the xi's:
         v = polyval( pN, x); 
   Find the Inf-norm error ∥y-v∥:
         err = norm(y-v, inf) 
   and plot both f(x) and pN(x) on the same plot:
         plot(x,y,'-b', x,v,'*-r')
         title('f(x) and pN(x) at plotting pts')
         pause 

   Is this a good interpolant ?  Why ?
        

   
3. Interpolation at Chebychev nodes:
   Generate N+1=11 Chebychev points (Xchebi, Ychebi) in [a,b]:
         fprintf('------ chebychev nodes ------\n')
         K = N+1;
         a=−5;  b=5;
         for i=1:K
             Xcheb(i)=(a+b)/2 + (b−a)/2 *cos( (i−0.5)*pi/K );
         end
         Ycheb = 1./(1+Xcheb.^2);

   Follow the steps in 2. to produce the Nth degree interpolating polynomial pNcheb 
   based on the Chebychev nodes, its values vcheb at the xi's, the error ∥y − vcheb∥,
   and plot both f(x) and pNcheb(x) on the same plot.

   Compare the error and plot with those from 2.
   Which one is better ?  why ?
        


4. Piecewise linear interpolation:
   Use Matlab's interp1 to construct the linear interpolant:
         lin = interp1(X,Y, x, 'linear'); 
   Repeat the steps of 2. 

   Compare errors and plots.
        

5. Piecewise cubic interpolation:
   Use Matlab's interp1 to construct the cubic interpolant:
         cub = interp1(X,Y, x, 'cubic'); 
   Repeat the steps of 2. 

   Compare errors and plots.
        


6. Cubic spline interpolation:
   Use Matlab's interp1 to construct the spline interpolant:
         spl = interp1(X,Y, x, 'spline'); 
   Repeat the steps of 2. 

   Compare errors and plots.
        


7. To see that the error gets worse for bigger N for equi-spaced nodes but not for Chebychev nodes 
   (for this f(x) at least), repeat 2. and 3. with N = 20.

Solutions

Expert Solution



Related Solutions

Using the Composite Trapezoidal Rule, with evenly spaced nodes, and n=3, find an approximate value for...
Using the Composite Trapezoidal Rule, with evenly spaced nodes, and n=3, find an approximate value for interval where b=1 and a=0, e^(-x^2)dx. Estimate the error.
Use and provide Matlab for the following: Generate the discrete-time signal x[n] = 4 cos (2pi....
Use and provide Matlab for the following: Generate the discrete-time signal x[n] = 4 cos (2pi. 10. nT5) + 2cos(2pi. 100. nT5) + 3cos(2pi 200. nT's), with Ts0.001 sec. Display the signal in both time and frequency-domain. Assume that the 100 Hz component of x [n] is your desired signal while the other two components are noise. Design a suitable filter to extract the desired (i.e. 100 Hz) signal. Display the filter's response. Display the output signal in the frequency-domain....
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2...
Write and upload a MATLAB script to do the following. Compute the sequence S(n+1) = (2 – K) S(n) – S(n-1) ;   Assume S(1) = 0, S(2) = 1; (a)    Case 1, Assume K = 1 (b)    Case 2, Assume K = 2 (c)     Case 3, Assume K = 4 Plot all of these on the same plot, for N = 1 to 20
Let D = {xi} n i=1, where xi ∈ R, be a data set drawn independently...
Let D = {xi} n i=1, where xi ∈ R, be a data set drawn independently from a Gumbel distribution α ∈ R is the location parameter and β > 0 is the scale parameter. a) Derive an algorithm for estimating α and β. b) Implement the algorithm derived above and evaluate it on data sets of different sizes. First, find or develop a random number generator that creates a data set with n ∈ {100, 1000, 10000} values using...
Write a Java program to generate random numbers in the following range a. 1 <=n <=...
Write a Java program to generate random numbers in the following range a. 1 <=n <= 3 b. 1 <= n <= 200 c. 0 <= n <= 9 d. 1000 <= n <= 2112 e. -1 <= n <= 5 JAVA PROGRAMMING
Assume n independent observations, denoted Xi, (i=1,....n), are taken from a distribution with a mean of...
Assume n independent observations, denoted Xi, (i=1,....n), are taken from a distribution with a mean of E(X)=μ and variance V(X) =σ2. Prove that the mean of the n observations has an expected value of E(X)=μ and a variance of V(X) =σ2/n. Use the appropriate E and V rules in your answer. What happens as n becomes large? What does this tell you about the quality of the sample mean as an estimate of μ as the sample size increases?
Use one MATLAB statement to generate each of the following scalars and vectors. (These parts are...
Use one MATLAB statement to generate each of the following scalars and vectors. (These parts are sequential) a.) Generate the vector x=(sin5,sin10,sin15,...,sin200) but dont print b.)Find the Max value in X and which index has this value. Print both the index and the value using Disp (so you can use 2 statements) c.)Find the minimum value x and which index has this value. Print both the index and the value using Disp (so you can use 2 statements) d.)Find the...
generate the following matrices with given rank and verify with the rank command. Include the Matlab...
generate the following matrices with given rank and verify with the rank command. Include the Matlab sessions in your report as indicated. A) is 8x8 with rank 3. B) is 6x9 with rank 4. C) is 10x7 with rank 5 .
CALCULATE THE MEAN value : Mean(x) = x0 = 1/N * ∑in xi and the Stardandar...
CALCULATE THE MEAN value : Mean(x) = x0 = 1/N * ∑in xi and the Stardandar deviacion :     σ = √ (∑in (xi-x0)2 / (N-1) BOTH USING MATLAB EMERGENCY PLEASE . THE DATA IS BELOW ....SHOW THE STEPS AND THE GRAPHS ...THERE ARE R1 AND R5 for the data R1 1.3004560111742451e+01 1.2989489582476999e+01 1.2992918145494006e+01 1.3015926219975810e+01 1.3003113745531683e+01 1.3009060588116746e+01 1.3006255988139626e+01 1.3006525855308004e+01 1.3015986719424999e+01 1.3015607658994400e+01 R5 1.2896465697037076e+01 1.3078048708539365e+01 1.2947635768569747e+01 1.3036655293457565e+01 1.2970848809276067e+01 1.3044710696683399e+01 1.3036858101292060e+01 1.3033168310496990e+01 1.2872334019855321e+01 1.2853995527962450e+01
CALCULATE THE MEAN value : Mean(x) = x0 = 1/N * ∑in xi and the Stardandar...
CALCULATE THE MEAN value : Mean(x) = x0 = 1/N * ∑in xi and the Stardandar deviacion :     σ = √ (∑in (xi-x0)2 / (N-1) BOTH USING MATLAB EMERGENCY PLEASE . THE DATA IS BELOW ....SHOW THE STEPS AND THE GRAPHS ...THERE ARE R1 AND R5 for the data R1 1.3004560111742451e+01 1.2989489582476999e+01 1.2992918145494006e+01 1.3015926219975810e+01 1.3003113745531683e+01 1.3009060588116746e+01 1.3006255988139626e+01 1.3006525855308004e+01 1.3015986719424999e+01 1.3015607658994400e+01 R5 1.2896465697037076e+01 1.3078048708539365e+01 1.2947635768569747e+01 1.3036655293457565e+01 1.2970848809276067e+01 1.3044710696683399e+01 1.3036858101292060e+01 1.3033168310496990e+01 1.2872334019855321e+01 1.2853995527962450e+01
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT