Question

4 [3 points] Use the function f(x on the interval [5, 5] and the 11 points below to find a N-10 Lagrange polynomial, using MA

Please use matlab, post the code, and dont just write the code by hand. Thank you!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

For, Lagrange interpolation of nth degree n+1 ,points are required which is given in question.

The formula for calculating the value through Lagrange interpolation is

f(x) =( (x-x1)*(x-x2)*......(x-xn)/(x0-x1)*(x0-x2)....(x0-xn))*f0 + .......+( (x-x1)*(x-x2)*......(x-xn-1)/(xn-x0)*(xn-x2)....(xn-xn-1))*fn

Here, the function value for all the points are given. So, we can use the values or save the value in array and use to calculate the value through matlab code.

(a) % Matlab code to calculate value using Lagrange polynomial

x = linspace(-5,5,11) ;% it will create array and save it in work-space of matlab having the values as shown in table, with % the variable x

y = (x.^2)/(1+ x.^4) ; % it will calculate the function f(x) for every value of x and will save in work-space with variable y

% here both x and y will have 11 points.

% for calculating the Lagrange interpolation ,there is direct command in matlab

xx = linspace(-5,5,10);

yy = lagrange(xx,x,y); % it will determine the lagrange polynomial values

plot(x, y, 'o', xx, yy, '.'); %It will plot both function and interpolating polynomial on same graph

(b) % consider error =e

for i =1:11

e(i) = (y(i)-yy(i))/y(i) % it wil calculate and save the error as a variable e in workspace

end

hold on

plot(x,e) % it will plot the error on same graph

Add a comment
Know the answer?
Add Answer to:
Please use matlab, post the code, and dont just write the code by hand. Thank you!...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • IN MATLAB Write a MATLAB function that can be used by a user to perform polynomial...

    IN MATLAB Write a MATLAB function that can be used by a user to perform polynomial interpolation using Lagrange Interpolation Method on a set of data. You should name your function as YourInitials_Lagrange_interpolation. 1. FUNCTION INPUT: . The input data pairs x and f(x) should be expressed as vectors and are used to construct the interpolation polynomials The interpolating data points/value The order of interpolating polynomials to be used. For this project you code should handle first order, second order...

  • **********************matlab code please******************* 1. Interpolation error of polynomial fit Using 11 equi-dist...

    **********************matlab code please******************* 1. Interpolation error of polynomial fit Using 11 equi-distributed points (10 equal segments) in the interval [-1 1], Using Newton's form find and plot the interpolating polynomial p(x) for the function f(x) -1/(125x2). Comment on the large discrepancies between p(x) and the function f(x) that the data came from Write down an expression for the error in the interpolating polynomial above? Which part of the expression is responsible for the large errors observed? 1. Interpolation error of...

  • 1. Runge's function is written as f(x) = 1 25r2 (a) Develop a plot of this function for the inter...

    1. Runge's function is written as f(x) = 1 25r2 (a) Develop a plot of this function for the interval from x =-1 to 1 using Matlab (no submission required). Develop the fourth-order Lagrange interpolating polynomial using equispaced function values corresponding to xi =-1,-0.5, 0, 0.5, and 1. (Note that you first need to determine the (a. ) pairs.) Use the polynomial to estimate f(0.9). (b) What is et? (c) Generate a cubic spline using the five data points from...

  • Matlab Matlab Matlab Matlab, Please solve this problem Problem 4 : Runge's phenomenon For this proble,...

    Matlab Matlab Matlab Matlab, Please solve this problem Problem 4 : Runge's phenomenon For this proble, you wil interpolate the function h(x) = tanh(10x) in I [a, b, through n datapoints (xi, hx with equidistant nodes for several values of n, and observe the behavior of the interpolating polynomial as n increases. You should use the pair of functions polyfit and polyval In your prob40: (a) Interpolate the function tanh(10x) in [-1,1] using a uniform grid of n nodes, where...

  • 3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 point...

    3. Consider the function f(x) = cos(x) in the interval [0,8]. You are given the following 3 points of this function: 10.5403 2 -0.4161 6 0.9602 (a) (2 points) Calculate the quadratic Lagrange interpolating polynomial as the sum of the Lo(x), L1(x), L2(x) polynomials we defined in class. The final answer should be in the form P)a2 bx c, but with a, b, c known. DELIVERABLES: All your work in constructing the polynomial. This is to be done by hand...

  • Task 2 (30 points +4 for comments): Write computer code that uses Lagrange's nterpolating Polynom...

    matlab code Task 2 (30 points +4 for comments): Write computer code that uses Lagrange's nterpolating Polynomials to fit an interpolating polynomial to the data for Task 2 in the excel file and use the polynomials to interpolate the data set and evaluate the function value at x values of 8.4, 7.6, and 6.7 What are the first through 3rd order estimations for the interpolated function value at> 8.4 and x 7.6? a) b) Extrapolate the data set to determine...

  • Using MATLAB!!! Please and thank you (5 points) Use Matlab to plot the magnitude and phase...

    Using MATLAB!!! Please and thank you (5 points) Use Matlab to plot the magnitude and phase of as a function of ω over the interval 0 If the input is ω 2π (5 points) What is the FS representation of y[n]? (5 points) Plot x[n] and y[n] over the range 0 to 24. If either has an imaginary component you must plot both real and imaginary parts .You must hand in a published .pdf of your script that shows the...

  • matlab The error function is a mathematical function that frequently arises in probability and statistics. It also c...

    matlab The error function is a mathematical function that frequently arises in probability and statistics. It also can show up in the solution to some partial differential equations, particularly those arising in heat and mass transfer applications. The error function is defined as 2 e-t dt picture attached This function is actually built-in to MATLAB as the command erf, and here we'll use that function to compute a "true value" with which we can compare results of two interpolation approaches....

  • Show work by hand and also using MATLAB code. Model 1 Given a polynomial f(x) Write a first-order approximation of f(x), given the value of f(x) at two points Plot the polynomial and the first-or...

    Show work by hand and also using MATLAB code. Model 1 Given a polynomial f(x) Write a first-order approximation of f(x), given the value of f(x) at two points Plot the polynomial and the first-order approximation on a graph Write a second-order approximation of f(x), given the value at three points. Plot the polynomial, the first-order and second-order approximations on a graph Find the integral Exactly Using trapezoidal rule Using composite trapezoidal rule Using Simpson's 1/3 rule . Calculate the...

  • InClassHandout21 P1) A5 m long beam is loaded by a triangular distributed load. (a) It is...

    InClassHandout21 P1) A5 m long beam is loaded by a triangular distributed load. (a) It is known that the vertical deflection of the beam y is exactly given by a 5th degree polynomial in x, what is the minimum number of points at which the deflection should be measured precisely to obtain the 5th degree polynomial? (b) Obtain the interpolating polynomial for the data given below by solving a linear system (you may use MATLAB to invert the resulting matrix)...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT