Question
matlab code
Task 2 (30 points +4 for comments): Write computer code that uses Lagranges nterpolating Polynomials to fit an interpolating


4.275 8 5.280799 3.242674 10 3.087088 11 4.314521
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 a value of the function at x 6.7 using your first c) through 3rd order polynomials. Plot the original data points as circles of a given color, and plot the first through 3rd order interpolated estimations atx- 8.4 andx 7.6 and the extrapolated values at x- 6.7 as squares of a different color from the original data points. Add the lines for the polynomials too if you want. Based on your plot, how accurate do you think each of your interpolations were? What about the extrapolation? Explain? d)
4.275 8 5.280799 3.242674 10 3.087088 11 4.314521
0 0
Add a comment Improve this question Transcribed image text
Answer #1

x- [7 89 10 11]: Y-[4.275 5.280799 3.242674 3.087088 4.314521]: % See Function at the bottom for interpolation y1 84LangrangePlotting Arrangements x_query - 8.4,7.6,6.7]: p-plot (X,Y,-ok,x_query,yl_q,-.bs,x_query, y2_q, -.r3, x query,y3_g,-ms p (1

Command Window At x = 8.4 Using 1st order Lagrange polynomial, y-5.6831 Using 2nd order Lagrange polynomial, y = 4.8308 Using

Lagrange Interpolatiom 6 Original Data -一日一1st order interpolation 日-2nd order interpolation B-3rd order interpolation 5.5 5

Text :-

X = [7 8 9 10 11];
Y = [4.275 5.280799 3.242674 3.087088 4.314521];
% See Function at the bottom for interpolation
y1_84 = Langrange(X,Y,1,8.4);       % Using Function defined to calculate y
y2_84 = Langrange(X,Y,2,8.4);
y3_84 = Langrange(X,Y,3,8.4);
fprintf("\nAt x = 8.4");
fprintf("\n Using 1st order Lagrange polynomial, y = %.4f",y1_84);
fprintf("\n Using 2nd order Lagrange polynomial, y = %.4f",y2_84);
fprintf("\n Using 3rd order Lagrange polynomial, y = %.4f\n",y3_84);

y1_76 = Langrange(X,Y,1,7.6);
y2_76 = Langrange(X,Y,2,7.6);
y3_76 = Langrange(X,Y,3,7.6);
fprintf("\nAt x = 7.6");
fprintf("\n Using 1st order Lagrange polynomial, y = %.4f",y1_76);
fprintf("\n Using 2nd order Lagrange polynomial, y = %.4f",y2_76);
fprintf("\n Using 3rd order Lagrange polynomial, y = %.4f\n",y3_76);

y1_67 = Langrange(X,Y,1,6.7);
y2_67 = Langrange(X,Y,2,6.7);
y3_67 = Langrange(X,Y,3,6.7);
fprintf("\nAt x = 6.7");
fprintf("\n Using 1st order Lagrange polynomial, y = %.4f",y1_67);
fprintf("\n Using 2nd order Lagrange polynomial, y = %.4f",y2_67);
fprintf("\n Using 3rd order Lagrange polynomial, y = %.4f\n",y3_67);

% Plotting Arrangements
x_query = [8.4,7.6,6.7];
y1_q = [y1_84,y1_76,y1_67];
y2_q = [y2_84,y2_76,y2_67];
y3_q = [y3_84,y3_76,y3_67];

p = plot(X,Y,'-ok',x_query,y1_q,'-.bs',x_query,y2_q,'-.rs',x_query,y3_q,'-.ms');
p(1).MarkerSize = 8;
p(2).MarkerSize = 8;
p(3).MarkerSize = 8;
p(4).MarkerSize = 8;
legend(["Original Data","1st order interpolation","2nd order interpolation",...
        "3rd order interpolation"],'Location','Best')
grid on
xlabel("x");    ylabel("y");    title("Lagrange Interpolatiom");

function [y] = Langrange(X,Y,n,x)
% Function for lagrange interpolation of order n
% Finds y at given x

L = ones(n+1,1);    % Initialization
for j = 1 : n+1
    for i = 1:n+1
        if i ~= j
            L(j) = L(j)*(x - X(i))/(X(j)-X(i)); % lagrange Polynomials ( L1 to Ln+1)
        end
    end
end
y = dot(L,Y(1:n+1));    % interpolation formula (L1*Y1 + L2*Y2 + .... Ln+1*Yn+1))
end
Add a comment
Know the answer?
Add Answer to:
Task 2 (30 points +4 for comments): Write computer code that uses Lagrange's nterpolating Polynom...
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...

  • Lagrange Polynomials You just watched some poor kid let go of her balloon in a 8-m...

    Lagrange Polynomials You just watched some poor kid let go of her balloon in a 8-m high mall food court. The four data points at right represent the height of a balloon (H, in meters) as a function of time (t, in seconds). (a) Create the 3rd-order Lagrange polynomial that exactly passes through all H(t)2 data, and use it to estimate (extrapolate) the balloon height at time 4 seconds. Show your work!! (b) Create the 3rd-order Lagrange polynomial to interpolate...

  • Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point...

    Task 2 (25 points + 4 points for commenting): Write computer code to perform the Fixed.Point method and use your code to find the root of the following equation using an initial guess of 3 and a stopping criterion of 0.001%; f(x) e -4x For Fixed-Point, you do not have to code Matlab to take the derivatives of the function and check the g'(x). You can do that step by hand, and then show me your hand cal ulations to...

  • Task 3 (36 points +4 points for commenting): Write computer code that performs the Simplex Method...

    matlab code Task 3 (36 points +4 points for commenting): Write computer code that performs the Simplex Method of Linear Programming to determine the optimal solution of the following problem statement. A manufacturer makes three types of plastic fixtures. The time in hours required for molding, trimming, and packaging of each fixture is given in the table below. Type Z 1.5 Type X Type Y Total Time Available Process Molding Trimming Packaging Profit per Fixture $11 12000 4600 2400 2/3...

  • Matlab code: Task 5 As an engineer you are asked to calculate the approximate surface area of a lake in your local community. In order to do that, you decide to use a GPS to measure the x and y coord...

    Matlab code: Task 5 As an engineer you are asked to calculate the approximate surface area of a lake in your local community. In order to do that, you decide to use a GPS to measure the x and y coordinates at various points around the lake. You pick a starting point and calibrate your GPS position at that point to be (0,0). You begin to walk around the lake collecting the following data below and eventually return to your...

  • Need help with this question on matlab. Show code please! Salmon_dat.csv 272395 286156 391573 461443 401998...

    Need help with this question on matlab. Show code please! Salmon_dat.csv 272395 286156 391573 461443 401998 313120 240763 297488 446152 480276 420555 277697 357375 331788 420879 332479 320947 359853 300917 403286 416419 345028 256049 281980 286625 278560 344422 317956 219688 259337 208197 189419 272884 360673 248860 306981 401711 867728 870035 921314 846026 570413 493708 275954 518942 480284 809799 677171 589937 1129664 1152642 Exercise 1: Salmon Runs Download the file salmon-dat.csv included with the homework. This file con- tains the annual...

  • One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we...

    One example of computer-aided design (CAD) is building geometric structures inter- actively. In Chapter 4, we will look at ways in which we can model geometric objects comprised of polygons. Here, we want to examine the interactive part. Let’s start by writing an application that will let the user specify a series of axis- aligned rectangles interactively. Each rectangle can be defined by two mouse positions at diagonally opposite corners. Consider the event listener canvas.addEventListener("mousedown", function() { gl.bindBuffer(gl.ARRAY_BUFFER, vBuffer); if...

  • please Identify the key points and main thesis of the article 2. Describe the skills you...

    please Identify the key points and main thesis of the article 2. Describe the skills you will need to develop to manage the hospital of the future. use critical analysis doing these questions Suggestion for writing assignmemnt make believe the reader has never read the article -what are the key points you would want the reader to know in order to understand the hospital of the future. In addition, managers, executives do not have time to read--so again what key...

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