Skip to Content
Interpolation

Interpolation (W5)

- Q1 -

In the problem, we have a function called f(x) = (1 - x^2)x^3. We want to find a polynomial, let’s call it p(x), that passes through 7 equally spaced points on the interval from 0 to 1.

The degree of a polynomial tells us the highest power of x in that polynomial. To find the degree of the interpolating polynomial, we need to determine the minimum degree required to accurately represent the function f(x) using those 7 points.

In this case, the interpolating polynomial p(x) is expected to have a minimum degree equal to the number of points minus 1, which in this case is 7 - 1 = 6. However, the polynomial p(x) = x^3 - x^5 has a degree of 5, which is less than 6.

Since the degree of p(x) is lower than the minimum required degree of 6, we cannot use p(x) to accurately interpolate the function f(x) on the given points.

Therefore, the correct answer is E) no, since the interpolating polynomial has a minimum degree equal to 6.

- Q2 -

In MATLAB, the spline function does not directly provide an option to specify the order of the spline. By default, the spline function constructs a piecewise cubic spline, which is a third-order spline.

Correct answer is none of the alternatives, in this case, D.

- Q3 -

To interpolate the function f(x) = sin(x) with a polynomial of higher degree using 5 linearly spaced nodes in the interval [0, π], including the extrema, When we say “linearly spaced nodes including extrema,” it means that we want to choose equidistant points within the interval [0, π], with the endpoints 0 and π included. In this case, with 5 linearly spaced nodes, we will have the following x-values:

x = [0, π/4, π/2, 3π/4, π]

Including the extrema ensures that the interpolation polynomial will pass through those specific points as well. we can use the MATLAB instructions as follows:

  1. Define the x-values of the 5 linearly spaced nodes, including the extrema:

  2. Calculate the y-values of the function f(x) = sin(x) at the given x-values:

  3. Use the polyfit function in MATLAB to fit a polynomial of a higher degree to the data points.

For interpolation with 5 points, a polynomial of degree 4 can perfectly fit the data points, as it can pass through all 5 points. Thus, you would typically use a polynomial of degree 4 for this case.

Therefore, you should input a degree of 4 when using the polyfit function to fit the polynomial to the 5 data points.

  1. Evaluate the polynomial at x = π/8 to find the value of the interpolating polynomial at that point:

The polyval function returns the value of the polynomial p at the point x1.

By following these steps, you can interpolate the function sin(x) with a polynomial of higher degree using 5 linearly spaced nodes in the interval [0, π]. The value of the interpolating polynomial at x = π/8 will be stored in the variable y1.

clear all x=linspace(0,pi,5); y = sin(x); p = polyfit(x,y,4); x1= pi/8; y1= polyval(p,x1)

Correct answer is 0.3812, in this case, D.

- Q4 -

Basically, if there are n points, it should be n-1 degree. In this question, it is given n+1 points.

Correct answer n, in this case, D.

- Q5 -

In interpolation, we use n-1 degree from given n points. In cubic spline, ax^3+bx^2+cx+d, there are 4 coefficients so for n-1 degree, we will have 4*(n-1) conditions.

Correct answer is B.

- Q6 -

Lagrange fundamental polynomial is [1, 0, 0] specifically asked to use.

In the matlab, there is no lagr function so we can eliminate these options.

In the question, it is asked to built to the first three nodes so we need use n-1 degree which is 2.

Correct answer is D.

- Q7 -

It is asked to find coefficient of the second order term. Polyfit function gives us coefficients of the polynomial.

clear all x = [1, 2, 3, 4]; y = [1, -1, 1, -1]; c=polyfit(x,y,3); c(2)

We define first x and y values, then we use polyfit and use 3 because we have 4 points so we need to use n-1 degree. Polyfit function gives us coefficients so c(2) will give us the coeefficient of second order-term.

Correct answer is 10, in this case, D.

- Q8 -

In this question, it is asked to interpolate the given data in with spline function. Basically we need to define x, y and z values then use the spline function.

clear all x = [-1, 1, 7, 9, 19]; y = [4, 3, 10, 10, 9]; z = log(0.9); spline(x,y,z)

Correct answer is 3.0762e+00, in this case, A.

- Q9 -

In this question, it is asked to interpolate the given data in with spline function. Basically we need to define x, y and z values then use the spline function.

clear all x = [-5, 4, 5, 11]; y = [6, 2, 4, 10] z = sqrt(1.8); y0 = 10; yn = 4; spline(x, [y0, y, yn], z)

Correct answer is 6.7247e+00, in this case, D.

- Q10 -

We are asked to find the coefficient of the first-degree term in a polynomial that interpolates the function f(x) = √(1 + x^2) in the interval [0, 5]. The polynomial is constructed using 5 Chebyshev nodes, which are specific points determined by a formula. By calculating the Chebyshev nodes, mapping them to the interval [0, 5], evaluating the function at those points, and performing polynomial interpolation, we can determine the coefficient of the first-degree term in the polynomial approximation.

clear all f=@(x) sqrt(1+x.^2); a=0; b=5; n=4; for i=1:(n+1) % we have 5 nodes so we set n=4 t(i)=-cos((((2.*i)-1)*pi)./(2*(n+1))); x(i)=(((b-a)/2).*t(i))+((b+a)/2); % general formula end y=f(x); c=polyfit(x,y,n); % normally we use n-1 but we already set n = 4 c(4) % prints the coefficient of first degree

The code defines a function f(x) that calculates the square root of (1 + x^2). It sets the interval [a, b] to be [0, 5] and the number of Chebyshev nodes n to be 4. It then generates the Chebyshev nodes within the interval and maps them to [a, b]. The function f(x) is evaluated at these nodes, and the polyfit function performs polynomial interpolation. Finally, the code prints the coefficient of the first-degree term of the interpolated polynomial.

Correct answer is 0.1166, in this case, B.

- Q11 -

In this question, it is asked to interpolate the given data in with spline function. Basically we need to define x and z values, y function then use the spline function.

clear all x = [0, 0.5, 1, 1.5, 2]; y = (sin(x)-(x+1).^2)./((x.^2)+3); z = 1.97; spline(x,y,z)

Correct answer is -1.148, in this case D.

- Q12 -

In this question, it is asked to interpolate the given data. Basically we need to define x and y values then use first polyfit then polyval in the given point.

clear all x = [3, 6, 7, 14, 21]; y = [8, 4, 5, 5, 7]; z = exp(0.7); c = polyfit(x,y,4); % 5 points, should be 4 degre polyval(c,z)

Correct answer is 1.383776857236245e+01, in this case, B.

- Q13 -

The question asks us to compute the polynomial of higher degree that interpolates the function f(x) = arctan(x (x+1)) using 8 linearly spaced points on the interval [0, 1], including the extrema. We need to perform polynomial interpolation using these points and calculate the interpolation error at specific values like 0.5 and 0.7. By subtracting the interpolated polynomial’s values at these points from the true function values, we can determine the interpolation error at those particular points.

clear all n=8; f=@(x) atan(x.*(x+1)); x=linspace(0,1,n); y=f(x); c=polyfit(x,y,(n-1)); p1=polyval(c,0.5); err1=abs(f(0.5)-p1) p2=polyval(c,0.7); err2=abs(f(0.7)-p2)

The code computes the polynomial of higher degree that interpolates the function using 8 points on the interval. It evaluates the function at the interpolation points and performs polynomial interpolation using the polyfit function. The code then calculates the interpolation error at specific values, such as 0.5 and 0.7, by comparing the true function values with the values obtained from the interpolated polynomial. The absolute difference between the true function values and the interpolated polynomial values represents the interpolation error at those specific points.

Correct answer is approximately 1.28e-05 and 4.88e-06, respectively, in this case, D.

- Q14 -

In this question, it is asked to interpolate the given data. Basically we need to define x and y values then use first polyfit then polyval in the given point.

clear all x = linspace(0, 2*pi, 4); f = @(x) cos(x); y = f(x); c = polyfit(x,y,3); % 4 points, should be 3 degree p = polyval(c,pi/8)

Correct answer is 6.0449e-01, in this case, A.