Question

Create a MATLAB function to perform Lagrange Interpolation. Your function will be used as illustrated below:...

Create a MATLAB function to perform Lagrange Interpolation. Your function will be used as illustrated below:

>> ya = Lagrange(x, y, a)

where "x" is a vector of ? independent data values, "y" is a vector of ? dependent function values corresponding to "x", "a" is an arbitrary value of "x" for which you want to know the Westimate of "y", and "ya" is the estimate of the function at x=a. Print an error message and exit the function if the size of the "x" and "y" vectors are not compatible. Hints: MATLAB built-in function "length()" can be used to return the number of elements in a vector, and built-in function "error()" will print an error message and exit the function. The following table lists values of the Bessel function of the first kind, of order zero.

? 1.0 , 1.3 , 1.6 , 1.9 , 2.2

?(?) 0.7651977 , 0.6200860 , 0.4554022 , 0.2818186 , 0.1103623

In the Command Window, use the commands needed to create the "x" and "y" vectors, and then use your MATLAB function to obtain the answer to the following question: What is the estimated value of the function at ? = 1.5? When complete, your MATLAB Workspace should include the input and output variables.

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

`Hey,

Note: Brother in case of any queries, just comment in box I would be very happy to assist all your queries

clear all
clc
x=[1.0 , 1.3 , 1.6 , 1.9 , 2.2];
y=[0.7651977 , 0.6200860 , 0.4554022 , 0.2818186 , 0.1103623];
disp('Value at x=1.5 is')
[yhat]=Lagrange(x,y,1.5)
function [yhat]=Lagrange(x,y,interpx)
if(length(x)~=length(y))
error('x and y are not compatible');
end
X=x;
f=y;
x=interpx;

l=0;
for i=1:length(X)
li=1;
for j=1:length(X)
if i~=j
li=(li).*((x-X(j))/(X(i)-X(j)));
end
end
l=(l)+((li)*f(i));
end
yhat=l;
  
end

Kindly revert for any queries

Thanks.

Add a comment
Know the answer?
Add Answer to:
Create a MATLAB function to perform Lagrange Interpolation. Your function will be used as illustrated below:...
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
  • Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials....

    Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials. Download the template for function lagrange interp.m. The tem Plate is in homework 4 folder utl TritonED·TIue function lakes in the data al nodex.xi and yi, as well as the target x value. The function returns the interpolated value y. Here, xi and yi are vectors while x and y are scalars. You are not required to follow the template; you can create the...

  • 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...

  • Write a MATLAB function that can be used by a user to perform polynomial interpolation using...

    Write a MATLAB function that can be used by a user to perform polynomial interpolation using Lagrange Interpolation Method on a set of data.

  • 1) Create a matlab function that calculates: for Name your function TwoVarFunc : The inputs should...

    1) Create a matlab function that calculates: for Name your function TwoVarFunc : The inputs should be in the same order: xmin xmax ymin ymax N: n is the number of elements in the vector x and y The ouputs should be in the same order: f_xy: is the calculated array f(x,y) f_xyMAX: should be the the maximum value of the function f(x,y). Hint: to create vectors x and y look up the matlab built-in function linspace() Hint 2: To...

  • 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....

  • 3. For any function f and n1 distinct nodes ro,....Tn, Lagrange interpolation factors f P R where...

    3. For any function f and n1 distinct nodes ro,....Tn, Lagrange interpolation factors f P R where and R is the approximation error. The following Matlab function, function a linterp_poly (X, a-zeros (1,numel(X)) for i1:numel(X) aa - poly (X([1:i-1 i+1:end])); a-a + Y(i) * aa / polyval (aa, X(i)); end end represents P(z)-Ση:0akrk as its coefficients a-lan, an-1, , al, ao (this solves Worksheet 7 Q2.) a) Write a Matlab function that uses P to approximate fd() for any positive...

  • Interpolation Polynomial Coding MATlab

    I have to write a Matlab function called "interpoly(x,y) which calculates the corresponding interpolation polynomial for given support points (xj,fj) with x=[x1,x2,...,xn] and f=[f1,f2,...,fn] and in interval x[min xj, max xj] plotted. Any method can be used to calculate the interpolation polynomial but I think Lagrange would be the best. One rule is that I can not use "polyfit" command.I have to test the programm with values of fj of the functions f(x)=cos(x) and f(x)=1/(1+x^2) each in the interval [-6,6]....

  • matlab matlab For this problem you will test a few interpolation approaches for the application of generating interpolated data. We'll do this by interpolating data that is sampled from a k...

    matlab matlab For this problem you will test a few interpolation approaches for the application of generating interpolated data. We'll do this by interpolating data that is sampled from a known mathematical function. The same function can then be used to compute true values at the interpolated points to use in error Consider the following mathematical function (Runge's function): 1+25r2 Write a function mfile that uses this formula to generate a set of data use those points along approaches outlined...

  • Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts...

    Please write the code using matlab 1) i. Create an anonymous function named optimist, that accepts a single variable as input i Create a row vector Tthat represents the number of seconds in two minutes, starting ii. Call the function optimist on the vector T, store the result in variable R1 and returns the double of that variable from one and ending at a hundred and twenty v. Create an anonymous function named pessimist, that accepts a single variable as...

  • PLEASE USE MATLAB COMMANDS THANK YOU Use Matlab to graph the functions f(x) = 3xsin(3x) and...

    PLEASE USE MATLAB COMMANDS THANK YOU Use Matlab to graph the functions f(x) = 3xsin(3x) and g(x)= 12 - 2x² so that you can read off the point(s) of intersection (if any), accurate up to two decimal places. 1) Write down the Matlab command(s) you used to create the x-vector. 2) Write down the Matlab command(s) you used to produce the vectors containing the f- and g-function values. 3) Write down the Matlab command(s) you used to plot the graphs....

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