Question

Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials
function y= lagrange interp(X1, y1, X) % LAGRANGE INTERP : use Lagrange polynomials to interpolate value of y at % input x us
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

clc%clears the screen
clear all %clears the history
format long;
x=input('Enter x vector(depth) from table as mentioned in question: ');
y=input('Enter x vector(temp) from table as mentioned in question: ');
p5a=lagrange_interp(x(3:5),y(3:5),-150)
p5b=lagrange_interp(x(3:6),y(3:6),-150)
p5c=lagrange_interp(x,y,-150)
depth=-330:10:-10;
temp=lagrange_interp(x(3:5),y(3:5),depth)
figure(5);
plot(temp,depth,x,y,'o');
p5d='See figure 5';

function [yhat]=lagrange_interp(x,y,interpx)

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:
Problem 5 (programming): Create a MATLAB function named lagrange interp.m to perform interpolation using Lagrange polynomials....
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
  • 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...

  • Problem 01 (about INTERPOLATION Given the following data Xi Yi 4 -5 (a) Using 2-nd order...

    Problem 01 (about INTERPOLATION Given the following data Xi Yi 4 -5 (a) Using 2-nd order (or QUADRATIC) "LAGRANGE" interpolation function, compute the value of Y ( @X 4.7) ?? (b) Using 2-nd order (or QUADRATIC) "Newton Divided Difference" interpolation function, compute the coefficients bo, b1 and b2 ??

  • Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...

    Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any arbitrary function f given an initial guess xo, an absolute error tolerance e and a maximum number of iterations max iter. Follow mynewton.m template posted in homework 2 folder on TritonED for guidance. You are not required to use the template. The function should return the approximated root ^n and the number of steps n taken to reach the solution. Use function mynewton.m to perform...

  • Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any a...

    Problem 4 (programming): Create a MATLAB function named mynewton.m to estimate the root for any arbitrary function f given an initial guess xo, an absolute error tolerance e and a maximum number of iterations max.iter. Follow mynewton.m template posted in homework 2 folder on TritonED for guidance. You are not required to use the template. The function should return the approximated root n and the number of steps n taken to reach the solution. Use function mynewton.m to perform the...

  • I need to create a MATLAB function, bvp_solve.m, to approximate the solution y(x). The function takes...

    I need to create a MATLAB function, bvp_solve.m, to approximate the solution y(x). The function takes the number of grid points n as an input. The outputs are grid vector x and the solution vector y %% This is the function i have so far: function [xi, yi] = bvp_solve(n) % BVP_SOLVE computes the solution y(x) of a two-point boundary value problem % using finite difference method (FDM). % The governing equation is % y''' = -y + (x -...

  • please provide matlab solution too 3. Butterball recommends the following cooking times for turkeys at 325...

    please provide matlab solution too 3. Butterball recommends the following cooking times for turkeys at 325 °C. size, (lbs) un-stuffed t, (h) stuffed t, (h) 2.00 2.25 6. 2.50 2.75 10 3.00 3.50 18 3.50 4.50 22 4.00 5.00 24 4.50 5.50 30 5.00 6.25 (a) Plot the recommended cooking time as a function of turkey size for un-stuffed and stuffed turkeys on the same plot. (b) For each of the two menu options, find the third-order interpolating polynomial (by...

  • Hide email Problem 5 (10 points): For the data below, perform Newton Divided Difference interpola...

    Please solve problem 7 not 5. however you need data from problem 5 to slove problem 7 Hide email Problem 5 (10 points): For the data below, perform Newton Divided Difference interpolation of fC7.5 C) using first through third order interpolating polynomial:s for f viscosity of water 1000 in metric (MKS) units. Choose thexi interpolation points to provide the most accurate interpolation (points should most closely surround x = 7.5 C). 040 y i 1.781 | İ .568 | 1...

  • 2. Create a main program that calls the subroutine created on problem 1 and compare results using the following data sets: b. 1 5), (0, 8), (3,-10) С. (-10,-2), (45), (73), (12, 20) t: (c...

    2. Create a main program that calls the subroutine created on problem 1 and compare results using the following data sets: b. 1 5), (0, 8), (3,-10) С. (-10,-2), (45), (73), (12, 20) t: (copy and paste the output in the following box) Use MATLAB or Scilab to solve the following problems 1. Create a MATLAB subroutine called Lagrange.m that receives two set data points, x and y and plots the curve by interpolating the missing points (hEX-Xi-1) using Lagrange...

  • Problem 4 : Finite difference formula and interpolation For this problem, you will approximate th...

    Please answer this problem using MATLAB. Problem 4 : Finite difference formula and interpolation For this problem, you will approximate the derivative of the function g(x)5x6x 23823x 15 on a set of points using the centered difference formula (x +h) -g(x- h) 2h g'(x) Then, you will find the interpolating polynomial through these points, Q, and verify that it is indeed close to the polynomial that is the true derivative of g, ie. Q(x) g'(x) 25x 24x36x+16x+3 In your prob40...

  • must be done in MATLAB 2. Create a main program that calls the subroutine created on problem 1 and compare resu...

    must be done in MATLAB 2. Create a main program that calls the subroutine created on problem 1 and compare results using the following data sets: b. (1 5), (0, 8), (3, -10) С. (-10,-2). ( 4,5), (7, 3), (12, 20) Output: (copy and paste the output in the following box) Use MATLAB or Scilab to solve the following problems 1. Create a MATLAB subroutine called Lagrange.m that receives two set data points, x and y and plots the curve...

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