Question

# 1 Approximation of functions by polynomials Let the function f(x) be given by the following: f(x)...

1 Approximation of functions by polynomials

Let the function f(x) be given by the following:

f(x) = 1/ 1 + x^2

Use polyfit to approximate f(x) by polynomials of degree k = 2, 4, and 6. Plot the approximating polynomials and f(x) on the same plot over an appropriate domain. Also, plot the approximation error for each case. Note that you also will need polyval to evaluate the approximating polynomial.

Submit your code and both plots. Make sure each of these plots is distinguishable and that a legend is included.

MATLAB Code:

close all
clear
clc

x = 0:0.1:10;
y = 1./(1 + x.^2);

p2 = polyfit(x, y, 2);
p4 = polyfit(x, y, 4);
p6 = polyfit(x, y, 6);

plot(x, y, x, polyval(p2, x), x, polyval(p4, x), x, polyval(p6, x)), xlabel('x')
legend('f(x)', 'Degree 2 Polynomial', 'Degree 4 Polynomial', 'Degree 6 Polynomial')
xlabel('x'), title('Function Plots')

figure, plot(x, abs(y - polyval(p2, x)), x, abs(y - polyval(p4, x)), x, abs(y - polyval(p6, x)))
legend('Degree 2 Polynomial', 'Degree 4 Polynomial', 'Degree 6 Polynomial')
xlabel('x'), title('Error Plots')

Plots:  #### Earn Coins

Coins can be redeemed for fabulous gifts.

##### Need Online Homework Help?

Most questions answered within 1 hours.

##### Active Questions
• Blue Ocean Strategy: An approach where firms seek to create and compete in uncontested market spaces....
• QUESTION 17 The following results are from data where the dependent variable is the selling price...
• Compare the energetics for producing ethanol from these two locations: Iowa (no irrigation) and High Plains...
• Internal Rate of Return Method—Two Projects Munch N’ Crunch Snack Company is considering two possible investments:...
• what three organizational considerations may influence a judge's sentencing decision? Why would these influence the judge...
• A vaccine to prevent a severe virus was given to children within the first year of...