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.

Homework Answers

Answer #1

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:

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
for the given functions f(x), let x0=1, x1=1.25, x2=1.6. Construct interpolation polynomials of degree at most...
for the given functions f(x), let x0=1, x1=1.25, x2=1.6. Construct interpolation polynomials of degree at most one and at most two to approximate f(1.4), and find the absolute error. a. f(x)=sin (pi x)
Fourier Series Approximation Matlab HW1:     You are given a finite function xt={-1 0≤t≤5; 1 5<t≤10...
Fourier Series Approximation Matlab HW1:     You are given a finite function xt={-1 0≤t≤5; 1 5<t≤10 .            Hand calculate the FS coefficients of x(t) by assuming half- range expansion, for each case below. Modify the code below to approximate x(t) by cosine series only (This is even-half range expansion). Modify the below code and plot the approximation showing its steps changing by included number of FS terms in the approximation. Modify the code below to approximate x(t) by sine...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads...
Curve-Fit Function USING MATLAB Using the top-down design approach, develop a MATLAB function A8P2RAlastname.m that reads data from a file and performs regression analysis using polyfit and polyval. The function shall have the following features: The input arguments shall include the file name (string), a vector of integers for the degrees of polynomial fits to be determined, and an optional plot type specifier (‘m’ for multiple plots, ‘s’ for a single plot - default). The data files will be text...
approximate the function f(x)= 1/sqrt(x) by a taylor polynomial with degree 2 and center a=4. how...
approximate the function f(x)= 1/sqrt(x) by a taylor polynomial with degree 2 and center a=4. how accurate is this approximation on the interval 3.5<x<4.5?
Let f(x) be a cubic polynomial of the form x^3 +ax^2 +bx+c with real coefficients. 1....
Let f(x) be a cubic polynomial of the form x^3 +ax^2 +bx+c with real coefficients. 1. Deduce that either f(x) factors in R[x] as the product of three degree-one polynomials, or f(x) factors in R[x] as the product of a degree-one polynomial and an irreducible degree-two polynomial. 2.Deduce that either f(x) has three real roots (counting multiplicities) or f(x) has one real root and two non-real (complex) roots that are complex conjugates of each other.
1. Find the Taylor polynomial, degree 4, T4, about 1/2 for f (x) = tan-inv (x)...
1. Find the Taylor polynomial, degree 4, T4, about 1/2 for f (x) = tan-inv (x) and use it to approximate tan-inv (1/16). 2. Find the taylor polynomial, degree 4, S4, about 0 for f (x) = tan-inv (x) and use it to approximate tan-inv (1/16). 3. who provides the best approximation, S4 or T4? Prove it.
Consider the following function. f(x) = ln(1 + 2x),    a = 1,    n = 3,    0.8 ≤ x ≤...
Consider the following function. f(x) = ln(1 + 2x),    a = 1,    n = 3,    0.8 ≤ x ≤ 1.2 (a) Approximate f by a Taylor polynomial with degree n at the number a. T3(x) = (b) Use Taylor's Inequality to estimate the accuracy of the approximation f(x) ≈ Tn(x) when x lies in the given interval. (Round your answer to six decimal places.) |R3(x)| ≤ (c) Check your result in part (b) by graphing |Rn(x)|.
The second-order Taylor polynomial fort he functions f(x)=√1+x about X0= is P2=1+(x/2)-(x^2/2) using the given Taylor...
The second-order Taylor polynomial fort he functions f(x)=√1+x about X0= is P2=1+(x/2)-(x^2/2) using the given Taylor polynomial approximate f(0.05) with 2 digits rounding and the find the relative error of the obtained value (Note f(0.05=1.0247). write down the answer and all the calculations steps in the text filed.
For each of the following pairs of polynomials f(x) and g(x), write f(x) in the form...
For each of the following pairs of polynomials f(x) and g(x), write f(x) in the form f(x) = k(x)g(x) + r(x) with deg(r(x)) < deg(g(x)). a)   f(x) = x^4 + x^3 + x^2 + x + 1 and g(x) = x^2 − 2x + 1. b)   f(x) = x^3 + x^2 + 1 and g(x) = x^2 − 5x + 6. c)   f(x) = x^22 − 1 and g(x) = x^5 − 1.
a.)Consider the function f (x) = 3x/ x^2 +1 i) Evaluate f (x+1), and f (x)+1....
a.)Consider the function f (x) = 3x/ x^2 +1 i) Evaluate f (x+1), and f (x)+1. Explain the difference. Do the same for f (2x) and 2f (x). ii) Sketch y = f (x) on the interval [−2, 2]. iii) Solve the equations f (x) = 1.2 and f (x) = 2. In each case, if a solution does not exist, explain. iv) What is the domain of f (x)? b.)Let f (x) = √x −1 and g (x) =...